function HookProc(code:Integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;
var
MouseHookStruct: ^TMOUSEHOOKSTRUCT;
WC: TWinControl;
classname: array [0..99] of char;
i:Integer;
begin
Result := 0;
if code < 0 then
Result := CallNextHookEx(NextHook,code,wParam,lParam);
case wParam of
WM_LBUTTONDOWN:
begin
end;
WM_LBUTTONUP:
begin
end;
WM_LBUTTONDBLCLK:
begin
end;
WM_RBUTTONDOWN:
begin
MouseHookStruct := Pointer(LParam);
//MouseHookStruct.hwnd为所点击组件的句柄,通过它得到它的类名
GetClassName(MouseHookStruct.hwnd,classname,100);
//如果是TLitView
if StrPas(classname) = 'TListView' then
begin
//获取该组件
WC := TListView(PInteger(Integer(GetWindowLong(MouseHookStruct.hwnd, GWL_WNDPROC)) + 9)^);
//循环显示item的Caption
for i := 0 to TListView(WC).Items.Count - 1 do
begin
ShowMessage(TListView(WC).Items[i].Caption);
end;
end;
end;
WM_RBUTTONUP:
begin
end;
WM_NCMOUSEMOVE,WM_MOUSEMOVE:
begin
//给调用者发消息
SendMessage(CallHandle,MessageID,pMouseHookStruct(lParam)^.hwnd,Integer(@pMouseHookStruct(lParam)^));
end;
end;
end;
捕获外部程序中TListView控件的鼠标右键点击事件
最新推荐文章于 2018-08-05 10:17:00 发布