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> first unit in your library's USES clause AND your project's (select<br> Project-View Source) USES clause if your DLL exports any procedures or<br> functions that pass strings as parameters or function results. This<br> applies to all strings passed to and from your DLL--even those that<br> are nested in records and classes. ShareMem is the interface unit to<br> the BORLNDMM.DLL shared memory manager, which must be deployed along<br> with your DLL. To avoid using BORLNDMM.DLL, pass string information<br> using PChar or ShortString parameters. }<br><br>uses<br> SysUtils,Windows, Messages;<br><br>var<br> FHook: HHOOK;<br> MsgWndH, edtH: Hwnd;<br>// n: Integer;<br><br>{$R *.res}<br><br>function HookProc(nCode: Integer; wP: WParam; lP: LParam): LRESULT; stdcall;<br>var<br> mhs: PMouseHookStruct;<br> a: array[0..100] of char;<br> h: Hwnd;<br> aData: TCOPYDATASTRUCT;<br>begin<br>// if nCode = HC_ACTION then<br> begin<br> if wP = WM_LBUTTONDOWN then<br> begin<br> mhs := PMouseHookStruct(lP);<br> h := mhs^.hwnd;<br> GetClassName(h,a,sizeof(a));<br> if a = 'TBitBtn' then<br> begin<br> GetWindowText(h,a,sizeof(a));<br> if (a = '确定') and (edtH <> 0) then<br> begin<br> h := GetParent(h); //TPanel;<br> h := GetParent(h); //Txxlr1<br> if h <> 0 then<br> begin<br> GetClassName(h,a,sizeof(a));<br> if a = 'Txxlr1' then<br> begin<br> GetWindowText(edtH,a,sizeof(a));<br> aData.dwData := 0;<br> aData.cbData := StrLen(a);<br> aData.lpData := @a[0];<br> SendMessage(MsgWndH,WM_COPYData,0,Integer(@aData));<br> end;<br> end;<br> end;<br> end;<br> end;<br> end;<br> Result := CallNextHookEx(FHook,nCode,wP,lP);<br>end;<br><br>function windProc(h: Hwnd; p: Pointer): Boolean; stdcall;<br>var<br> a: array [0..100] of char;<br>begin<br> GetClassName(h,a,sizeof(a));<br> if a = 'TEdit' then<br> begin<br> edtH := h;<br> Result := False;<br> Exit;<br> end;<br> Result := True;<br>end;<br><br>procedure HookOn(aMsgWndH, aChildWndH: Hwnd); stdcall;<br>begin<br> MsgWndH := aMsgWndH;<br> MessageBox(MsgWndH,'hook on','sdf',64);<br> EnumChildWindows(aChildWndH,@windProc,0);<br> if FHook = 0 then<br> FHook := SetWindowsHookEx(WH_MOUSE,@HookProc,hInstance,0);<br>end;<br><br>procedure HookOff; stdcall;<br>begin<br> if FHook <> 0 then<br> begin<br> UnhookWindowsHookEx(FHook);<br> FHook := 0;<br> end;<br> MsgWndH := 0;<br> edtH := 0;<br>end;<br><br>exports<br>HookOn,HookOff;<br><br>begin<br>end.