Author: Tomas Rutkauskas
How to trap and process Windows messages before the applications' window procedure
is executed
Answer:
The following project source demonstrates how to get Window messages before the
application's window procedure is called. It is rare, if ever, that this needs to
be done. In most cases assigning a procedure to the Application.OnMessage will
accomplish the same thing.
1 program Project1;
2
3 uses
4 Forms, messages, wintypes, winprocs, Unit1 in 'UNIT1.PAS' {Form1};
5
6 {$R *.RES}
7
8 var
9 OldWndProc: TFarProc;
10
11 function NewWndProc(hWndAppl: HWnd; Msg, wParam: Word; lParam: Longint): Longint;
12 export;
13 begin
14 result := 0; { Default WndProc return value }
15 {Handle messages here; The message number is in Msg}
16 result := CallWindowProc(OldWndProc, hWndAppl, Msg, wParam, lParam);
17 end;
18
19 begin
20 Application.CreateForm(TForm1, Form1);
21 OldWndProc := TFarProc(GetWindowLong(Application.Handle, GWL_WNDPROC));
22 SetWindowLong(Application.Handle, GWL_WNDPROC, longint(@NewWndProc));
23 Application.Run;
24 end.
|