编写了一个鼠标钩子,右键点击的消息能够截获,但是双击消息不能截获,请高手指点。dll程序如下:
library Mouse_HookDLL;uses
SysUtils,
Windows,
Messages,
Classes; const WH_MOUSE_LL=14;{$R *.res}var
NextHook : HHook;
CallHandle : HWND;
MessageID : Word;function HookProc(code:Integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;
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
SendMessage(CallHandle,MessageID,wParam,Integer(@pMouseHookStruct(lParam)^));
end;
WM_RBUTTONDOWN:
begin
end;
WM_RBUTTONUP:
begin
SendMessage(CallHandle,MessageID,wParam,Integer(@pMouseHookStruct(lParam)^));
end;
WM_NCMOUSEMOVE,WM_MOUSEMOVE:
begin
end;
end;
end;//启动钩子
function StartHook(MsgID:Word):Bool;stdcall;
begin
Result := False;
if NextHook <> 0 then
Exit;
MessageID := MsgID;
NextHook := SetWindowsHookEx(WH_MOUSE_LL,@HookProc,HInstance,0);
Result := NextHook <> 0;
end;//脱钩
function StopHook:Bool;stdcall;
begin
if NextHook <> 0 then
begin
UnHookWindowsHookEx(NextHook);
NextHook := 0;
end;
Result := NextHook = 0;
end;//传递调用者句柄
procedure SetCallHandle(sender:HWND);stdcall;
begin
CallHandle := sender;
NextHook := 0;
end;exports
StartHook name 'StartHook',
StopHook name 'StopHook',
SetCallHandle name 'SetCallHandle';begin
end.
library Mouse_HookDLL;uses
SysUtils,
Windows,
Messages,
Classes; const WH_MOUSE_LL=14;{$R *.res}var
NextHook : HHook;
CallHandle : HWND;
MessageID : Word;function HookProc(code:Integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;
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
SendMessage(CallHandle,MessageID,wParam,Integer(@pMouseHookStruct(lParam)^));
end;
WM_RBUTTONDOWN:
begin
end;
WM_RBUTTONUP:
begin
SendMessage(CallHandle,MessageID,wParam,Integer(@pMouseHookStruct(lParam)^));
end;
WM_NCMOUSEMOVE,WM_MOUSEMOVE:
begin
end;
end;
end;//启动钩子
function StartHook(MsgID:Word):Bool;stdcall;
begin
Result := False;
if NextHook <> 0 then
Exit;
MessageID := MsgID;
NextHook := SetWindowsHookEx(WH_MOUSE_LL,@HookProc,HInstance,0);
Result := NextHook <> 0;
end;//脱钩
function StopHook:Bool;stdcall;
begin
if NextHook <> 0 then
begin
UnHookWindowsHookEx(NextHook);
NextHook := 0;
end;
Result := NextHook = 0;
end;//传递调用者句柄
procedure SetCallHandle(sender:HWND);stdcall;
begin
CallHandle := sender;
NextHook := 0;
end;exports
StartHook name 'StartHook',
StopHook name 'StopHook',
SetCallHandle name 'SetCallHandle';begin
end.
private
{ Private declarations }
//重载消息处理
procedure WndProc(var Message: TMessage);override;const
WM_TestMsg = WM_User + 100;
implementation{$R *.dfm}
function StartHook(MsgID:Word):Bool;stdcall;external 'Mouse_HookDLL.dll';
function StopHook:Bool;stdcall;external 'Mouse_HookDLL.dll';
procedure SetCallHandle(sender:HWND);stdcall;external 'Mouse_HookDLL.dll';procedure TForm1.FormShow(Sender: TObject);
begin
SetCallHandle(Self.Handle);
if not StartHook(WM_TestMsg) then //WM_TestMsg为自定义消息
begin
ShowMessage('挂钩失败!');
end;
end;
procedure TForm1.WndProc(var Message: TMessage);
begin
//得到符合条件的钩子
if Message.Msg = WM_TestMsg then
begin
memo1.Lines.Add('Get it!');
end;
inherited;
end;
呵呵,是啊,没办法啊,任务没有完成呢。
我试过WH_MOUSE,连右键都捕获不到了。
根据两次单击时间判断该怎么做呢?
你的任务还是获得在资源管理器中打开的文件?
兄弟,恕我愚钝,具体怎么做?如果用dll的方法,如何判断?
这里=14是怎么来的,是不是应该改成7,delphi 里面定义 WH_MOUSE=7;