-
-
[求助]低级鼠标钩子取窗体句柄小疑惑。。
-
发表于: 2011-1-25 18:55 3834
-
unit LLMouseHook;
interface
uses
Windows, Messages, SysUtils;
function StartHookMouse: boolean;
function StopHookMouse: boolean;
implementation
const
WH_MOUSE_LL = 14;
var
hhkLowLevelMouse: HHook = 0;
function LowLevelMouseProc(nCode: Integer; WParam: WPARAM; LParam: LPARAM): LRESULT; stdcall;
begin
if (nCode = HC_ACTION) then
begin
case wParam of
WM_LBUTTONDOWN:
begin
//此处如何添加获取左键按下处的控件句柄功能呢????
//例如按了XX程序的确定,如何通过低级鼠标钩子获取点的确定的句柄?
end;
end;
Result := 0;
Result := CallNextHookEx(0, nCode, WParam, LParam);
end;
end;
function StartHookMouse: boolean;
begin
if hhkLowLevelMouse = 0 then hhkLowLevelMouse := SetWindowsHookEx(WH_MOUSE_LL, LowlevelMouseProc, HInstance, 0);
result := hhkLowLevelMouse <> 0;
end;
function StopHookMouse: boolean;
begin
if hhkLowLevelMouse <> 0 then
begin
UnHookWindowsHookEx(hhkLowLevelMouse);
hhkLowLevelMouse := 0;
end;
result := true;
end;
initialization
hhkLowLevelMouse := 0;
finalization
if hhkLowLevelMouse <> 0 then UnhookWindowsHookEx(hhkLowLevelMouse);
end.
------------------------------------------------
{ Structure used by WH_MOUSE }
PMouseHookStruct = ^TMouseHookStruct;
{$EXTERNALSYM tagMOUSEHOOKSTRUCT}
tagMOUSEHOOKSTRUCT = packed record
pt: TPoint;
hwnd: HWND;
wHitTestCode: UINT;
dwExtraInfo: DWORD;
end;
TMouseHookStruct = tagMOUSEHOOKSTRUCT;
{$EXTERNALSYM MOUSEHOOKSTRUCT}
MOUSEHOOKSTRUCT = tagMOUSEHOOKSTRUCT;
WH_MOUSE 的结构体是这样的。。。 其中 hwnd 就是句柄。。
PMouseHookStruct(lParam).hwnd 就是鼠标处的句柄了。。
可是用低级鼠标钩子要怎么搞啊?
interface
uses
Windows, Messages, SysUtils;
function StartHookMouse: boolean;
function StopHookMouse: boolean;
implementation
const
WH_MOUSE_LL = 14;
var
hhkLowLevelMouse: HHook = 0;
function LowLevelMouseProc(nCode: Integer; WParam: WPARAM; LParam: LPARAM): LRESULT; stdcall;
begin
if (nCode = HC_ACTION) then
begin
case wParam of
WM_LBUTTONDOWN:
begin
//此处如何添加获取左键按下处的控件句柄功能呢????
//例如按了XX程序的确定,如何通过低级鼠标钩子获取点的确定的句柄?
end;
end;
Result := 0;
Result := CallNextHookEx(0, nCode, WParam, LParam);
end;
end;
function StartHookMouse: boolean;
begin
if hhkLowLevelMouse = 0 then hhkLowLevelMouse := SetWindowsHookEx(WH_MOUSE_LL, LowlevelMouseProc, HInstance, 0);
result := hhkLowLevelMouse <> 0;
end;
function StopHookMouse: boolean;
begin
if hhkLowLevelMouse <> 0 then
begin
UnHookWindowsHookEx(hhkLowLevelMouse);
hhkLowLevelMouse := 0;
end;
result := true;
end;
initialization
hhkLowLevelMouse := 0;
finalization
if hhkLowLevelMouse <> 0 then UnhookWindowsHookEx(hhkLowLevelMouse);
end.
------------------------------------------------
{ Structure used by WH_MOUSE }
PMouseHookStruct = ^TMouseHookStruct;
{$EXTERNALSYM tagMOUSEHOOKSTRUCT}
tagMOUSEHOOKSTRUCT = packed record
pt: TPoint;
hwnd: HWND;
wHitTestCode: UINT;
dwExtraInfo: DWORD;
end;
TMouseHookStruct = tagMOUSEHOOKSTRUCT;
{$EXTERNALSYM MOUSEHOOKSTRUCT}
MOUSEHOOKSTRUCT = tagMOUSEHOOKSTRUCT;
WH_MOUSE 的结构体是这样的。。。 其中 hwnd 就是句柄。。
PMouseHookStruct(lParam).hwnd 就是鼠标处的句柄了。。
可是用低级鼠标钩子要怎么搞啊?
[招生]系统0day安全班,企业级设备固件漏洞挖掘,Linux平台漏洞挖掘!
赞赏
他的文章
- [求助]OD 如此修改DLL 为什么会出错啊? 3511
- [求助]WIN7 下星号密码查看如何实现? 6099
- [求助]低级鼠标钩子取窗体句柄小疑惑。。 3835
- [求助]OD 简单添加调用 WINEXEC 疑惑 5551
- [求助]delphi 如何响应网页按钮按下事件? 3633
看原图
赞赏
雪币:
留言: