Z
zhou13
Unregistered / Unconfirmed
GUEST, unregistred user!
有没有人能说一下<br>HOOK函数<br>SetWindowsHookEx<br>各个参数的意思?看了MSDN,英文太差,没看懂..<br>HC_ACTION是什么意思??<br>GetCurrentThreadID又是什么意思,用来干吗?<br><br>还有,为什么大部分Hook都需要DLL呢?<br>没有DLL不行么<br><br>也是《Delphi.下深入Windows核心编程》的代码的问题 <br>nit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> StdCtrls;<br>const<br> WM_TestMessage = WM_USER + 2000;<br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> procedure FormCreate(Sender: TObject);<br> procedure Button1Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br>var<br> HookHandle: HHOOK;<br><br>function TestHookProc(Code: Integer; WParam: Longint;Msg:Longint): Longint;stdcall;<br>begin<br> if (Code = HC_ACTION) then<br> if PMsg(Msg)^.Message = WM_TestMessage then<br> begin<br> showMessage('已经截获该消息');<br> end;<br> Result := CallNextHookEx(HookHandle, Code, WParam, Longint(@Msg));<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> HookHandle:=SetWindowsHookEx(WH_GETMESSAGE,TestHookProc,0,GetCurrentThreadID);<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> PostMessage(self.Handle,WM_TestMessage,0,0);<br>end;<br><br>end.<br><br>谢谢大家回答拉