function mouseproc
icode:integer;wParam:wParam;lParam:lParam):lresult;stdcall;var
Form1: TForm1;
idhook:Hhook;
formok:boolean;
implementation{$R *.dfm} function mouseproc(icode:integer;wParam:wParam;lParam:lParam):lresult;stdcall;
var mp : TPoint ; begin if icode<0 then begin
showmessage('icode <0');
Result:=CallNextHookEx(idHook,iCode,wParam,lParam);
exit;
end;
if wparam=wm_mousemove then //当鼠标移动时就在label2中显示座标
begin
GetCursorPos(mp);
form1.Label2.Caption:='x:'+inttostr(mp.x)+' y:'+inttostr(mp.Y);
end;
end;我的钩子函数是放在dll中的,但每次一离开自己的窗口就出问题了,怎么处理,我会给够100分的,谢谢
icode:integer;wParam:wParam;lParam:lParam):lresult;stdcall;var
Form1: TForm1;
idhook:Hhook;
formok:boolean;
implementation{$R *.dfm} function mouseproc(icode:integer;wParam:wParam;lParam:lParam):lresult;stdcall;
var mp : TPoint ; begin if icode<0 then begin
showmessage('icode <0');
Result:=CallNextHookEx(idHook,iCode,wParam,lParam);
exit;
end;
if wparam=wm_mousemove then //当鼠标移动时就在label2中显示座标
begin
GetCursorPos(mp);
form1.Label2.Caption:='x:'+inttostr(mp.x)+' y:'+inttostr(mp.Y);
end;
end;我的钩子函数是放在dll中的,但每次一离开自己的窗口就出问题了,怎么处理,我会给够100分的,谢谢
在mainprt程序的窗口可以hook到座标,并显示出来了,但鼠标一离开mainprt窗口hook就没有用了,再移回来也没有用了,只能是再点击hook一次 如果说全局hook要把钩子程序放到dll的话,我已经做了,怎么回事?
http://www.csdn.net/expert/topic/786/786032.xml?temp=.3390924
主要是窗体没有更新的问题。我给你改一下程序你就可以结贴了
把这个 form1.Label2.Caption:='x:'+inttostr(mp.x)+' y:'+inttostr、改为这个 sendmessage(findwindow'notepad',nil),WM_SETTEXT,0,integer(pchar(inttostr(mp.x)+','+inttostr(mp.y ))));在运行程序之前打开一个记事本,你鼠标移动的时候看看记事本的标题。
如果有什么疑问,给我发短信