1,183
社区成员
发帖
与我相关
我的任务
分享
unit u_dllHook;
interface
uses
Windows,SysUtils,Messages;
const
WM_MYACTIVATENEW = WM_USER + 3326;
type
CBTACTIVATESTRUCT = record
FMouse:Boolean;
FHWND :HWND;
end;
PCBTACTIVATESTRUCT = ^CBTACTIVATESTRUCT ;
function installDLL(aWnd:HWND):Boolean;stdcall;
function uninstallDLL:Boolean;stdcall;
var
aHook:HHOOK;
aHWND:HWND;
implementation
function CBTProc(icode:Integer;awParam:WPARAM;alParam:LPARAM):LongInt;stdcall;
begin
Result:=0;
if icode<0 then
Result:=CallNextHookEx(aHook,icode,awParam,alParam);
case icode of
HCBT_ACTIVATE:
begin
PostMessage(aHWND,WM_MYACTIVATENEW,awParam,alParam);
end;
end;
end;
function installDLL(aWND:HWND):Boolean;stdcall;
begin
if aHOOK<>0 then // we have already hooked
begin
Result:=True;
Exit
end;
aHook:=SetWindowsHookEx(WH_CALLWNDPROC,CBTProc,HInstance,0);
Result:=aHook<>0;
aHWND:=aWnd;
end;
function uninstallDLL:Boolean;stdcall;
begin
if aHook<>0 then
begin
UnhookWindowsHookEx(aHook);
Result:=aHook=0;
end;
end;