为什么钩不到鼠标移动的消息(100分)

  • 主题发起人 主题发起人 liudonghui
  • 开始时间 开始时间
L

liudonghui

Unregistered / Unconfirmed
GUEST, unregistred user!
附源程序如下:<br>library mousedll;<br><br>uses<br>&nbsp; SysUtils,<br>&nbsp; Classes,<br>&nbsp; Unitrep in 'Unitrep.pas' {Form1};<br>exports<br>HookUpMouse,<br>UnHookMouse,<br>MouseProc;<br><br>{$R *.RES}<br><br>begin<br>end.<br><br>unit Unitrep;<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; Label1: TLabel;<br>&nbsp; &nbsp; Label2: TLabel;<br>&nbsp; &nbsp; Label3: TLabel;<br>&nbsp; &nbsp; Label4: TLabel;<br>&nbsp; &nbsp; Label5: TLabel;<br>&nbsp; &nbsp; Label6: TLabel;<br>&nbsp; &nbsp; Edit1: TEdit;<br>&nbsp; &nbsp; Edit2: TEdit;<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br>&nbsp; function HookUpMouse:THandle;export;<br>&nbsp; function UnHookMouse:Uint;export;<br>&nbsp; function MouseProc(Code: Integer; wParam: WPARAM; lParam: LPARAM):LRESULT;export; &nbsp;<br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; hMNextHook:hHook;<br>&nbsp; MouseHasHookUp:Boolean;<br>implementation<br><br><br>{$R *.DFM}<br><br><br><br>function HookUpMouse:THandle;<br>var<br>&nbsp; hinst:Thandle;<br>&nbsp; proc:tfarproc;<br>begin<br>&nbsp; {动态连接库的application指:调用动态连接库的主程序}<br>&nbsp; form1:=tform1.create(application);<br>&nbsp; form1.show;<br>&nbsp; Result:=0;<br>&nbsp; if MouseHasHookUp then Exit;<br>&nbsp; hinst:=LoadLibrary(LPCTSTR('mousedll'));<br>&nbsp; form1.edit2.text:=inttostr(hinst);<br>&nbsp; proc:=getProcAddress(hinst,'MouseProc');<br>&nbsp; hMNextHook:=SetWindowsHookExW(WH_MOUSE,proc,hinst,0);<br>&nbsp; if hMNextHook&lt;&gt;0 then MouseHasHookUp:=True<br>end;<br><br>function UnHookMouse:Uint;<br>begin<br>&nbsp; Result:=0;<br>&nbsp; if not MouseHasHookUp then Exit;<br>&nbsp; if hMNextHook&lt;&gt;0 then<br>&nbsp; &nbsp; if UnHookWindowsHookEx(hMNextHook) then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; hMnextHook:=0;<br>&nbsp; &nbsp; &nbsp; MouseHasHookUp:=False;<br>&nbsp; &nbsp; &nbsp; end;<br>end;<br><br>function MouseProc(Code:Integer;wParam:WPARAM;lParam:LPARAM):LRESULT;export;<br>var<br>&nbsp; p:^TMouseHookStruct;<br>begin<br>&nbsp; form1.edit1.text:=inttostr(wparam);<br>&nbsp; if Code&lt;0 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; Result:=CallNextHookEx(hMNextHook,Code,wParam,lParam);<br>&nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; end;<br>&nbsp; if wParam=WM_MOUSEMOVE then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Form1.Caption := Form1.Caption + '1';<br>&nbsp; &nbsp; &nbsp; form1.label1.caption:='wParam='+intTostr(wparam);<br>&nbsp; &nbsp; &nbsp; form1.label2.caption:='lParam='+intTostr(lparam);<br>&nbsp; &nbsp; &nbsp; p:=ptr(lparam);<br>&nbsp; &nbsp; &nbsp; form1.label3.caption:='pt.x='+intTostr(p^.pt.x)+' &nbsp;pt.y='+intTostr(p^.pt.y);<br>&nbsp; &nbsp; end;<br>&nbsp; Result := 0;<br>end;<br><br>end.
 
你的dll中的函数怎么放到了exe中去实现,那还要dll做什么?<br><br>这是一个Mouse Hook的例子:http://service.lonetear.com/delphi/dispdoc.asp?id=1300
 
接受答案了.
 
后退
顶部