UNIT Unit1;
{$MODE OBJFPC}{$H+}{$J-}
Interface
USES
Windows, Classes, Forms, Dialogs;
TYPE
TForm1 = Class(TForm)
Procedure FormCreate (Sender: TObject);
PRIVATE
PrevWndProc: Windows.WNDPROC;
End;
VAR
Form1: TForm1;
Implementation
{$R *.LFM}
Function WndCallback (MyHWND: HWND; uMSG: UINT; wParam: WParam; lParam: LParam): LRESULT; StdCall;
var
WindowInfo: PWin32WindowInfo;
Begin
WindowInfo := GetWin32WindowInfo(Window); //<---- step one
If (uMSG = WM_DISPLAYCHANGE)
Then ShowMessage('Display Changed') // only for testing purposes...
Else Form1.Color:= RGB(0, 170, 0); // don't use this in real world apps, take
// a look at the following post from GetMem
if WindowInfo^.WinControl is TForm1 then //Eliminate form1 global variable for safer handling.
Result:= CallWindowProc(TForm1(WindowInfo^.WinControl).PrevWndProc, MyHWND, uMSG, WParam, LParam);
End;
Procedure TForm1.FormCreate(Sender: TObject);
Begin
PrevWndProc:= Windows.WNDPROC
(SetWindowLongPtr(Handle, GWL_WNDPROC, PtrInt(@WndCallback)));
End;
END.