hook 问题,高手帮忙!(100分)

  • 主题发起人 主题发起人 cjianwen
  • 开始时间 开始时间
C

cjianwen

Unregistered / Unconfirmed
GUEST, unregistred user!
代码如下,为啥这个 hook,只对调用者有效呢? 为啥不是全局的?<br><br>library HookInsurance;<br><br>{ Important note about DLL memory management: ShareMem must be the<br> &nbsp;first unit in your library's USES clause AND your project's (select<br> &nbsp;Project-View Source) USES clause if your DLL exports any procedures or<br> &nbsp;functions that pass strings as parameters or function results. This<br> &nbsp;applies to all strings passed to and from your DLL--even those that<br> &nbsp;are nested in records and classes. ShareMem is the interface unit to<br> &nbsp;the BORLNDMM.DLL shared memory manager, which must be deployed along<br> &nbsp;with your DLL. To avoid using BORLNDMM.DLL, pass string information<br> &nbsp;using PChar or ShortString parameters. }<br><br>uses<br> &nbsp; SysUtils,Windows, Messages;<br><br>var<br> &nbsp;FHook: HHOOK;<br> &nbsp;MsgWndH, edtH: Hwnd;<br>// &nbsp;n: Integer;<br><br>{$R *.res}<br><br>function HookProc(nCode: Integer; wP: WParam; lP: LParam): LRESULT; stdcall;<br>var<br> &nbsp; &nbsp;mhs: PMouseHookStruct;<br> &nbsp; &nbsp;a: array[0..100] of char;<br> &nbsp; &nbsp;h: Hwnd;<br> &nbsp; &nbsp;aData: TCOPYDATASTRUCT;<br>begin<br>// &nbsp; &nbsp;if nCode = HC_ACTION then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;if wP = WM_LBUTTONDOWN then<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mhs := PMouseHookStruct(lP);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;h := mhs^.hwnd;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GetClassName(h,a,sizeof(a));<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if a = 'TBitBtn' then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GetWindowText(h,a,sizeof(a));<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (a = '确定') and (edtH &lt;&gt; 0) then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;h := GetParent(h); &nbsp; //TPanel;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;h := GetParent(h); &nbsp; //Txxlr1<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if h &lt;&gt; 0 then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GetClassName(h,a,sizeof(a));<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if a = 'Txxlr1' then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GetWindowText(edtH,a,sizeof(a));<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aData.dwData := 0;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aData.cbData := StrLen(a);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aData.lpData := @a[0];<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SendMessage(MsgWndH,WM_COPYData,0,Integer(@aData));<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;end;<br> &nbsp; &nbsp;Result := CallNextHookEx(FHook,nCode,wP,lP);<br>end;<br><br>function windProc(h: Hwnd; p: Pointer): Boolean; stdcall;<br>var<br> &nbsp; &nbsp;a: array [0..100] of char;<br>begin<br> &nbsp; &nbsp;GetClassName(h,a,sizeof(a));<br> &nbsp; &nbsp;if a = 'TEdit' then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;edtH := h;<br> &nbsp; &nbsp; &nbsp; &nbsp;Result := False;<br> &nbsp; &nbsp; &nbsp; &nbsp;Exit;<br> &nbsp; &nbsp;end;<br> &nbsp; &nbsp;Result := True;<br>end;<br><br>procedure HookOn(aMsgWndH, aChildWndH: Hwnd); stdcall;<br>begin<br> &nbsp; &nbsp;MsgWndH := aMsgWndH;<br> &nbsp; &nbsp;MessageBox(MsgWndH,'hook on','sdf',64);<br> &nbsp; &nbsp;EnumChildWindows(aChildWndH,@windProc,0);<br> &nbsp; &nbsp;if FHook = 0 then<br> &nbsp; &nbsp; &nbsp; &nbsp;FHook := SetWindowsHookEx(WH_MOUSE,@HookProc,hInstance,0);<br>end;<br><br>procedure HookOff; stdcall;<br>begin<br> &nbsp; &nbsp;if FHook &lt;&gt; 0 then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;UnhookWindowsHookEx(FHook);<br> &nbsp; &nbsp; &nbsp; &nbsp;FHook := 0;<br> &nbsp; &nbsp;end;<br> &nbsp; &nbsp;MsgWndH := 0;<br> &nbsp; &nbsp;edtH := 0;<br>end;<br><br>exports<br>HookOn,HookOff;<br><br>begin<br>end.
 
怎么没人?顶一下![:(]
 

Similar threads

I
回复
0
查看
742
import
I
I
回复
0
查看
520
import
I
I
回复
0
查看
762
import
I
后退
顶部