function WinProc(hWnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
var
msgstr:string;
begin
msgstr:='If you want close applicatin,please close dog simulator first!';
case msg of
WM_CLOSE: begin
showmessage(msgstr);
result:=1;
end;
else result := CallWindowProc(SavedProc,hwnd,msg,wparam,lparam);
end;
end;
procedure GetAndSet(h:integer);stdcall;
begin
if pointer(getwindowlong(h,GWL_WNDPROC))<>@winProc then
begin
SavedProc:=pointer(SetWindowLong(h,GWL_WNDPROC,cardinal(@Winproc)));
end;
end;
function CallWndProc(
nCode:integer ; // hook code
wParam: WPARAM ; // current-process flag
lParam: LPARAM // address of structure with message data
):LRESULT;stdcall;
var
h:longint;
begin
h:=FindWindow(pchar('DKMagic_CLASS'),nil);
if tmsg(pointer(lparam)^).hwnd=h then
begin
GetAndSet(h);
end;
result:=CallNextHookex(syshook,ncode,wparam,lparam);
end;
procedure RunStopHook(b:boolean);export;stdcall;
begin
if b
then SyShook:=Setwindowshookex(WH_GETMESSAGE,@callWndProc,Hinstance,0)
else unhookwindowshookex(syshook);
if (syshook=cardinal(-1)) or(syshook=cardinal(0)) then
messagebox(0,'hook失败','',mb_ok);
end;