以下代码我试图实现以下意图:(100分)

  • 主题发起人 主题发起人 wp231957
  • 开始时间 开始时间
W

wp231957

Unregistered / Unconfirmed
GUEST, unregistred user!
每打开一个窗口,就在LISTBOX1中显示<br>可是实际上没有任何显示,不晓得为什么:<br>主程序代码:<br>unit main;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, StdCtrls;<br><br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;Button1: TButton;<br> &nbsp; &nbsp;Button2: TButton;<br> &nbsp; &nbsp;Button3: TButton;<br> &nbsp; &nbsp;ListBox1: TListBox;<br> &nbsp; &nbsp;procedure Button1Click(Sender: TObject);<br> &nbsp; &nbsp;procedure Button2Click(Sender: TObject);<br> &nbsp; &nbsp;procedure WMcopyData(var msg:TWMcopyData);message wm_copyData;<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>var<br> &nbsp;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> &nbsp;EnableWheelHook;<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br> &nbsp;DisableWheelHook;<br>end;<br><br>procedure TForm1.WMcopyData(var msg:TWMCopyData);<br>var<br> &nbsp;cd:TCOPYDATASTRUCT;<br> &nbsp;c:pchar;<br>begin<br> &nbsp;cd.lpData := PCOPYDATASTRUCT(msg.CopyDataStruct).lpData;<br> &nbsp;c := cd.lpData;<br> &nbsp;listbox1.Items.Add(c);<br>end;<br><br>end.<br><br>DLL代码:<br>library hookapi;<br><br>uses<br> &nbsp;SysUtils,<br> &nbsp;Classes,<br> &nbsp;QQTitleHook in 'QQTitleHook.pas';<br><br>exports<br> &nbsp;EnableWheelHook, DisableWheelHook;<br><br>begin<br> &nbsp;hkQQChat:= 0;<br>end.<br>'QQTitleHook.pas'代码:<br>unit QQTitleHook;<br><br>interface<br><br>uses<br> &nbsp;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> &nbsp;Result:= 0;<br> &nbsp;if Code&lt;0 then begin<br> &nbsp; &nbsp;Result:= CallNextHookEx(hkQQChat, Code, wParam, lParam);<br> &nbsp; &nbsp;Exit;<br> &nbsp;end else if Code = HCBT_ACTIVATE then begin<br> &nbsp; &nbsp;hwQQChat:= HWND(wParam);<br> &nbsp; &nbsp;getwindowtext(hwQQChat,buf,1024);<br> &nbsp; &nbsp;clsName:= string(buf);<br> &nbsp; &nbsp;///////////////////////////////////////////////////<br> &nbsp; &nbsp;H := windows.FindWindow(nil,pchar('FormMain'));<br> &nbsp; &nbsp;cd.dwData := 0;<br> &nbsp; &nbsp;cd.cbData := 30;<br> &nbsp; &nbsp;cd.lpData := @buf;<br> &nbsp; &nbsp;windows.SendMessage(h,wm_copyData,0,integer(@cd));<br> &nbsp; &nbsp;//SetWindowText(hwQQChat, pchar('i am a hooker'));<br> &nbsp;end;<br>end;<br><br>function EnableWheelHook : Boolean; stdcall; <br>begin<br> &nbsp;if hkQQChat=0 then<br> &nbsp;begin<br> &nbsp; &nbsp;hkQQChat := SetWindowsHookEx(WH_CBT, @TitleHookProc, Hinstance, 0);<br> &nbsp; &nbsp;Result := True;<br> &nbsp;end else begin<br> &nbsp; &nbsp;Result := False;<br> &nbsp;end;<br>end;<br>function DisableWheelHook: Boolean; stdcall;<br>begin<br> &nbsp;if hkQQChat&lt;&gt;0 then<br> &nbsp;begin<br> &nbsp; &nbsp;UnHookWindowsHookEx(hkQQChat);<br> &nbsp; &nbsp;hkQQChat := 0;<br> &nbsp; &nbsp;Result := True;<br> &nbsp;end else begin<br> &nbsp; &nbsp;Result := False;<br> &nbsp;end;<br>end;<br><br>end.
 
晕,知道怎么回事了
 
晕,我们还不知道怎么回事啊
 
多人接受答案了。
 
后退
顶部