Z
z_cactic
Unregistered / Unconfirmed
GUEST, unregistred user!
我的hook写在dll里,当SetWindowsHookEx后,在另外一个程序里不管怎么动,都不会触发<br>MyWindowHook(code: Integer; wp: WPARAM; lp: LPARAM)这个函数,设断点也跟不进去,这是什么原因,<br>如果把SetWindowsHookEx里参数GetWindowThreadProcessId(Han ,nil)改为0断点是可以跟踪进去<br>但是if (pmsg.hwnd = handle) and (pmsg.message = WM_LBUTTONDOWN) then都是FALSE的。<br>我的程序如下。<br>procedure hookon(handle:thandle;chihan: thandle);stdcall;<br>procedure unhook;stdcall;<br>function MyWindowHook(code: Integer; wp: WPARAM; lp: LPARAM): LRESULT stdcall;<br>implementation<br>var<br> hk:HHOOK;<br> chihandle: thandle;<br> IsExit: boolean=false;<br> s: string;<br>procedure hookon(handle:thandle;chihan: thandle);<br>var<br> han: thandle;<br>begin<br> han := FindWindow('tform1', 'xxx');<br> if han = 0 then<br> exit;<br> hk := SetWindowsHookEx(WH_CALLWNDPROC,MyWindowHook,HInstance,<br> GetWindowThreadProcessId(Han ,nil));<br><br>end;<br>procedure unhook;<br>begin<br> UnhookWindowsHookEx(hk);<br>end;<br>function MyWindowHook(code: Integer; wp: WPARAM; lp: LPARAM): LRESULT stdcall;<br>var<br> pmsg:^CWPSTRUCT;<br> I:Integer;<br> lv: TLVITEM;<br> han: thandle;<br> handle,hedit: thandle;<br> ss: PChar;<br>begin<br> Result := 0;<br> if Code < 0 then<br> begin<br> Result := CallNextHookEx(hk, Code, wP, lP);<br> Exit;<br> end;<br> pmsg:= Pointer(lp);<br> if code = HC_ACTION then<br> begin<br> handle := FindWindow('tform1', 'xxx');<br> if handle = 0 then exit;<br> hedit := FindWindowEx(handle,0,'TEdit',nil);<br> if han = 0 then exit;<br> if (pmsg.hwnd = handle) and (pmsg.message = WM_LBUTTONDOWN) then<br> begin<br> getmem(ss,30);<br> SendMessage(hedit,WM_SETTEXT,0,LPARAM(LPCTSTR('df')));<br> freemem(ss);<br> end;<br> end;<br> Result:= 1;<br>end;