安装钩子:
function InstallHook(nkey: DWord): Boolean; stdcall;
begin
Result := False;
if nKey <> 0 then exit;
if ghNextHookMouse = 0 then
ghNextHookMouse := SetWindowsHookEx(WH_MOUSE, @MouseHook, HInstance, 0);
Result := true;
end;
钩子处理函数:
function MouseHook(nCode: integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
begin
Result := 0;
if nCode < 0 then
begin
Result := CallNextHookEx(ghNextHookMouse, nCode, wParam, lParam);
exit;
end;
if wParam = 520 then //520就是鼠标中键消息
begin
if (GetModuleHandle(pcClientProcessName) > 0) then
begin
if not bHook then
begin
//UpdateAddr();
InsetCode() ;
frmHook := TfrmHook.Create(Application);
frmHook.Show ;
bHook := True ;
end
else
frmHook.Visible := true ;
end;
end ;
end ;