首页
社区
课程
招聘
[求助]低级鼠标钩子取窗体句柄小疑惑。。
发表于: 2011-1-25 18:55 3834

[求助]低级鼠标钩子取窗体句柄小疑惑。。

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  就是鼠标处的句柄了。。

可是用低级鼠标钩子要怎么搞啊?

[招生]系统0day安全班,企业级设备固件漏洞挖掘,Linux平台漏洞挖掘!

收藏
免费 0
支持
分享
最新回复 (0)
游客
登录 | 注册 方可回帖
返回
// // 统计代码