Examples Delphi

SIMPLE WAY OF TRAPPING WINDOWS MESSAGE(S)
WITHOUT RESORTING TO THE HORRENDOUS SYNTAX
OF A 'CALLBACK FUNCTION'
type
{form class declaration}
TMainForm = class(TForm)
DrawArea: TImage;
ExitButton: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure HandleMessages (var Msg: tMsg; var Handled: Boolean);
procedure ExitButtonClick(Sender: TObject);
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
Application.OnMessage := HandleMessages;
end;
procedure TMainForm.HandleMessages(var Msg: tMsg; var Handled: Boolean);
begin
if (Msg.message = WM_KeyDown) and
(Msg.wParam in [VK_DOWN, VK_LEFT, VK_RIGHT]) then
begin
case Msg.wParam of
VK_LEFT: RotateAboutXAxisButtonClick(Self);
VK_DOWN: RotateAboutYAxisButtonClick(Self);
VK_RIGHT: RotateAboutZAxisButtonClick(Self);
end;
Handled := True;
end;
end;