SAS;
uses
System
.
SysUtils,
System
.
Classes,
Winapi
.
Windows,
Winapi
.
Messages;
{$R *.res}
type
TMessageHookCallback =
procedure
(
const
Msg: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
PMsg(lParam)^.message = WM_WINDOWPOSCHANGING
then
CallbackProc(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
.