我的鼠标钩子为什么不是全局的?
我已经做在DLL里了,但是只有鼠标自己的程序内移动的时候才会收到消息,移出自己的窗口就收不到了,何解?
请看源码
版本1:
function MouseProc(iCode: Integer;wParam: WPARAM;lParam: LPARAM): LRESULT; stdcall;
var
MyMsg : ^Msg;
pPnt:TPoint;
begin
if iCode=0 then
begin
MyMsg:=Pointer(lParam);
if MyMsg.message=WM_MOUSEMOVE then
begin
GetCursorPos(pPnt);
PostMessage(iHandle,WM_APP+$100,pPnt.x,pPnt.y);
end;
end;
result:=CallNextHookEx(iHook,iCode,wParam,lParam);
end;
function SetMouseHook(h:THandle): BOOL; export;
begin
if iHook=0 then
begin
iHandle:=h;
iHook:=SetWindowsHookEx(WH_GETMESSAGE,MouseProc,HInstance,0);
Result:=true;
end
else
begin
Result:=false;
end;
end;
版本2
function MouseProc(iCode: Integer;wParam: WPARAM;lParam: LPARAM): LRESULT; stdcall;
var
MouseStruct:^MOUSEHOOKSTRUCT;
x,y:integer;
begin
result:=0;
if iCode>-1 then
begin
if wParam=WM_MOUSEMOVE then
begin
MouseStruct:=pointer(lParam);
x:=MouseStruct^.pt.X;
y:=MouseStruct^.pt.Y;
PostMessage(iHandle,WM_APP+$100,pPnt.x,pPnt.y);
end;
end
else
result:=CallNextHookEx(iHook,iCode,wParam,lParam);
end;
function SetMouseHook(h:THandle): BOOL; export;
begin
if iHook=0 then
begin
iHandle:=h;
iHook:=SetWindowsHookEx(WH_MOUSE,MouseProc,HInstance,0);
Result:=true;
end
else
begin
Result:=false;
end;
end;
帮忙看看,谢谢