【鼠标钩子】为什么鼠标移出窗口,就钩不到了。(100分)

  • 主题发起人 主题发起人 foenix
  • 开始时间 开始时间
F

foenix

Unregistered / Unconfirmed
GUEST, unregistred user!
[:(]<br>程序如下:<br>&nbsp; &nbsp; 为什么鼠标移出了程序窗口就不能显示鼠标位置,如果将鼠标位置在label中显示,<br>则移出窗口就弹出“非法操作窗口”?<br><br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br><br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; hmyhook:hhook=0;<br><br>&nbsp; implementation<br><br>{$R *.DFM}<br>function MyMouseProc(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;<br>var<br>&nbsp; mousehook:PMouseHookStruct;<br>begin<br>//if ncode&lt;0 then<br>//if (wParam=WM_MOUSEMOVE) then<br>//begin<br>&nbsp; mousehook:=Pmousehookstruct(lparam);<br>&nbsp; form1.Caption :=format('mouse position %d ,%d',[mousehook.pt.x,mousehook.pt.y]);<br>// &nbsp; form1.Label1.Caption := 'I Get the Hook!';<br>// &nbsp;result:=0;<br>//end<br>//else<br>result:=CallNextHookEx(hmyHook,nCode,wParam,lParam);<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>hmyhook:=SetWindowsHookEx(WH_MOUSE,MyMouseProc,hInstance,0);<br>button1.Enabled := false;<br>end;<br><br>procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);<br>begin<br>UnhookWindowshookEx(hmyhook);<br>end;<br><br>end.<br>
 
用WH_MOUSE_LL
 
LeeChange<br>能不能详细点?<br>
 
你勾的是应用程序吧,勾WINDOWS看看啊
 
用上全局钩子吧,勾子程序要在另一个DLL中
 
内存映像文件
 
我这里有范例程序<br>也用到了Dll和内存映像文件<br>但我就是不懂为什么要用Dll和内存映像<br>是不是一定要用?<br>我看了一个回放鼠标键盘事件的例子,就没有用Dll。<br>有没有朋友能帮忙介绍一下做这类钩子程序的关键步骤和注意事项,谢谢。<br>
 
非Dll调用的钩子,只在自己的应用程序范围内起作用<br>DLL中无法使用全局变量,只能通过内存映像来实现全局变量的功能
 
在win98/Me下可以不用DLL的,我很久以前做过示例程序。nt下就不行了,必须DLL,要的加我QQ 53681116
 

Similar threads

后退
顶部