Etwa so sollte es aussehen (alles ungetestet).
Delphi-Quellcode:
library SuperMsgHook;
uses
Windows,
Messages,
SysUtils,
Classes;
type
TMessageHookCallback = procedure(const Msg: Windows.TMsg) of object;
var
HookHandle: Cardinal;
CallbackProc: TMessageHookCallback;
function GetMsgProc(code: integer; wParam: WPARAM; lParam: LPARAM): LResult;
stdcall;
begin
if (code = HC_ACTION) and Assigned(CallbackProc) then
if Windows.PMsg(lParam)^.message = WM_WINDOWPOSCHANGING then
CallbackProc(Windows.PMsg(lParam)^);
Result := CallNextHookEx(HookHandle, Code, wParam, lParam);
end;
procedure DisableMessageHook;
stdcall;
begin
CallbackProc := nil;
if HookHandle <> 0 then
begin
UnhookWindowsHookEx(HookHandle);
HookHandle := 0;
end;
end;
procedure EnableMessageHook(ACallbackProc: TMessageHookCallback);
stdcall;
begin
DisableMessageHook;
CallbackProc := ACallbackProc;
HookHandle := SetWindowsHookEx(WH_GETMESSAGE, GetMsgProc, hInstance, 0);
if HookHandle = 0 then
RaiseLastOsError;
end;
exports
GetMsgProc,
EnableMessageHook,
DisableMessageHook;
end.
... und dann in deinem Hauptprogramm:
Delphi-Quellcode:
type
TMessageHookCallback = procedure(const Msg: Windows.TMsg) of object;
procedure DisableMessageHook; stdcall; external 'SuperMsgHook.dll';
procedure EnableMessageHook(ACallbackProc: TMessageHookCallback); stdcall; external 'SuperMsgHook.dll';
Du brauchst dann eine selbstgeschriebene Methode, die die Informationen entgegennimmt. Die übergibst du an "EnableMessageHook".