可以使用mouse钩子,勾wm_lbuttondown消息,然后判断是否是TButton,我试了一下,98下
可以使用。下面的代码是动态链接库里的代码,host代码就不用贴了吧。只是调用了dll中
的starthook和stophook。
library Hook;
uses
SysUtils, messages, windows,
Classes;
{$R *.res}
var
HookHandle: integer;
FileBuf: pointer;
Hmap: THandle;
function MouseProc(
code: integer; // hook code
wParam: WPARAM; // message identifier
LPARAM: lParam // mouse coordinates
): LResult; stdcall;
var
MouseInfo: pMouseHookStruct;
function IsButton: boolean;
var
p: TPoint;
H: THandle;
ClsName: array[0..255] of char;
begin
Result := false;
MouseInfo := pMouseHookStruct(Lparam);
H := MouseInfo^.hwnd;
GetClassName(h,ClsName,SizeOf(ClsName));
if ClsName = 'TButton' then
Result := true;
end;
begin
result:=0;
if Code<0 then
begin
CallNextHookEx(HookHandle,Code,wParam,lParam);
exit;
end;
if Code = HC_ACTION then
begin
if wparam = WM_LBUTTONDOWN then
begin
if IsButton then
Result := 1
else Result := 0;
end;
end;
end;
function StartHook: integer;export;
begin
Result := 0;
HookHandle := SetWindowsHookEx(WH_MOUSE ,MouseProc,hinstance,0);
Result := HookHandle;
end;
function StopHook: boolean;export;
begin
Result := UnhookWindowsHookEx(HookHandle);
end;
exports
StartHook,
StopHook;
begin
end.