您的位置:首页 > 其它

捕获外部程序中TListView控件的鼠标右键点击事件

2011-01-17 16:13 337 查看
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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: