G
googledcjt
Unregistered / Unconfirmed
GUEST, unregistred user!
我设置了一个简单的捕获鼠标左键单击事件的全局钩子,在一个应用程序主窗体创建的时候InstallHook,在窗体释放的时候UnInstallHook。
为什么在应用程序运行时候不是每次鼠标单击就showmessage?而是偶尔出现一次showmessage?
代码如下:
library HookDll;
uses
Windows, Messages, Imm, Dialogs,
SysUtils,
Classes;
var
aHk :HHOOK;
{$R *.res}
function MouseProc(Code: Integer; WParam: WParam; LParam: LParam): LRESULT;
var
theMsg: TMessage;
begin
Result := 0;
if Code < 0 then begin
Result := CallNextHookEx(aHk, Code, WParam, LParam);
Exit;
end;
if PMsg(LParam).message = WM_LBUTTONDOWN then
ShowMessage('WM_LBUTTONDOWN');
Result := CallNextHookEx(aHk, Code, WParam, LParam);
end;
procedure InstallHook; stdcall;
begin
aHk := SetWindowsHookEx(WH_Mouse, @MouseProc, HInstance, 0);
end;
procedure UnInstallHook; stdcall;
begin
UnHookWindowsHookEx(aHk);
end;
exports
InstallHook, UnInstallHook;
begin
end.
为什么在应用程序运行时候不是每次鼠标单击就showmessage?而是偶尔出现一次showmessage?
代码如下:
library HookDll;
uses
Windows, Messages, Imm, Dialogs,
SysUtils,
Classes;
var
aHk :HHOOK;
{$R *.res}
function MouseProc(Code: Integer; WParam: WParam; LParam: LParam): LRESULT;
var
theMsg: TMessage;
begin
Result := 0;
if Code < 0 then begin
Result := CallNextHookEx(aHk, Code, WParam, LParam);
Exit;
end;
if PMsg(LParam).message = WM_LBUTTONDOWN then
ShowMessage('WM_LBUTTONDOWN');
Result := CallNextHookEx(aHk, Code, WParam, LParam);
end;
procedure InstallHook; stdcall;
begin
aHk := SetWindowsHookEx(WH_Mouse, @MouseProc, HInstance, 0);
end;
procedure UnInstallHook; stdcall;
begin
UnHookWindowsHookEx(aHk);
end;
exports
InstallHook, UnInstallHook;
begin
end.