W
wp231957
Unregistered / Unconfirmed
GUEST, unregistred user!
每打开一个窗口,就在LISTBOX1中显示<br>可是实际上没有任何显示,不晓得为什么:<br>主程序代码:<br>unit main;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> Button2: TButton;<br> Button3: TButton;<br> ListBox1: TListBox;<br> procedure Button1Click(Sender: TObject);<br> procedure Button2Click(Sender: TObject);<br> procedure WMcopyData(var msg:TWMcopyData);message wm_copyData;<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br>function EnableWheelHook:boolean;stdcall;external 'hookapi.dll';<br>function DisableWheelHook:boolean;stdcall;external 'hookapi.dll';<br>{$R *.dfm}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> EnableWheelHook;<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br> DisableWheelHook;<br>end;<br><br>procedure TForm1.WMcopyData(var msg:TWMCopyData);<br>var<br> cd:TCOPYDATASTRUCT;<br> cchar;<br>begin<br> cd.lpData := PCOPYDATASTRUCT(msg.CopyDataStruct).lpData;<br> c := cd.lpData;<br> listbox1.Items.Add(c);<br>end;<br><br>end.<br><br>DLL代码:<br>library hookapi;<br><br>uses<br> SysUtils,<br> Classes,<br> QQTitleHook in 'QQTitleHook.pas';<br><br>exports<br> EnableWheelHook, DisableWheelHook;<br><br>begin<br> hkQQChat:= 0;<br>end.<br>'QQTitleHook.pas'代码:<br>unit QQTitleHook;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Dialogs, CommCtrl, StrUtils;<br>var<br>hkQQChat: HHOOK;<br>hwQQChat: HWnd ;<br>tlQQChat: string;<br>clsName: string;<br>H:THandle;<br>cd:TCOPYDATASTRUCT;<br>buf: array [0..1024] of char;<br>function TitleHookProc(Code: Integer; wParam: WPARAM; lParam:LPARAM): LRESULT; stdcall;<br>function EnableWheelHook : Boolean; stdcall; export;<br>function DisableWheelHook: Boolean; stdcall; export;<br>implementation<br>//钩子的处理函数<br>function TitleHookProc(Code: Integer; wParam: WPARAM; lParam:LPARAM): LRESULT; stdcall;<br>begin<br> Result:= 0;<br> if Code<0 then begin<br> Result:= CallNextHookEx(hkQQChat, Code, wParam, lParam);<br> Exit;<br> end else if Code = HCBT_ACTIVATE then begin<br> hwQQChat:= HWND(wParam);<br> getwindowtext(hwQQChat,buf,1024);<br> clsName:= string(buf);<br> ///////////////////////////////////////////////////<br> H := windows.FindWindow(nil,pchar('FormMain'));<br> cd.dwData := 0;<br> cd.cbData := 30;<br> cd.lpData := @buf;<br> windows.SendMessage(h,wm_copyData,0,integer(@cd));<br> //SetWindowText(hwQQChat, pchar('i am a hooker'));<br> end;<br>end;<br><br>function EnableWheelHook : Boolean; stdcall; <br>begin<br> if hkQQChat=0 then<br> begin<br> hkQQChat := SetWindowsHookEx(WH_CBT, @TitleHookProc, Hinstance, 0);<br> Result := True;<br> end else begin<br> Result := False;<br> end;<br>end;<br>function DisableWheelHook: Boolean; stdcall;<br>begin<br> if hkQQChat<>0 then<br> begin<br> UnHookWindowsHookEx(hkQQChat);<br> hkQQChat := 0;<br> Result := True;<br> end else begin<br> Result := False;<br> end;<br>end;<br><br>end.