F
foenix
Unregistered / Unconfirmed
GUEST, unregistred user!
[]<br>程序如下:<br> 为什么鼠标移出了程序窗口就不能显示鼠标位置,如果将鼠标位置在label中显示,<br>则移出窗口就弹出“非法操作窗口”?<br><br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> procedure Button1Click(Sender: TObject);<br> procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br><br>var<br> Form1: TForm1;<br> hmyhook:hhook=0;<br><br> implementation<br><br>{$R *.DFM}<br>function MyMouseProc(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;<br>var<br> mousehookMouseHookStruct;<br>begin<br>//if ncode<0 then<br>//if (wParam=WM_MOUSEMOVE) then<br>//begin<br> mousehook:=Pmousehookstruct(lparam);<br> form1.Caption :=format('mouse position %d ,%d',[mousehook.pt.x,mousehook.pt.y]);<br>// form1.Label1.Caption := 'I Get the Hook!';<br>// 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>