本人初次接触 钩子和消息 还望大虾耐心指教:
以下代码简单 本人照书搬下 可是编译通不过 请大虾耐心指教了, 多谢!
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;Const
WM_TestMessage = WM_User + 2000;type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}var
HookHandle : HHook;//HOOK处理函数
Function TestHookProc(Code:Integer;WParam:LongInt):LongInt;StdCall;
begin
if Code = HC_Action then
if TMsg(Msg)^.message= WM_TestMessage then
begin
showmessage('已经截获该消息');
end;
//挂钩下一个函数
Result := CallNextHookEx(HookHandle,Code,WParam,LongInt(@Msg));
end;procedure TForm1.FormCreate(Sender: TObject);
begin //安装HOOK
HookHandle := SetWindowsHookEx(WH_GetMessage,TestHookProc,0,GetCurrentThreadID);
end;procedure TForm1.Button1Click(Sender: TObject);
begin //发特定消息
PostMessage(self.Handle,WM_TestMessage,0,0);
end;end.
以下代码简单 本人照书搬下 可是编译通不过 请大虾耐心指教了, 多谢!
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;Const
WM_TestMessage = WM_User + 2000;type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}var
HookHandle : HHook;//HOOK处理函数
Function TestHookProc(Code:Integer;WParam:LongInt):LongInt;StdCall;
begin
if Code = HC_Action then
if TMsg(Msg)^.message= WM_TestMessage then
begin
showmessage('已经截获该消息');
end;
//挂钩下一个函数
Result := CallNextHookEx(HookHandle,Code,WParam,LongInt(@Msg));
end;procedure TForm1.FormCreate(Sender: TObject);
begin //安装HOOK
HookHandle := SetWindowsHookEx(WH_GetMessage,TestHookProc,0,GetCurrentThreadID);
end;procedure TForm1.Button1Click(Sender: TObject);
begin //发特定消息
PostMessage(self.Handle,WM_TestMessage,0,0);
end;end.
解决方案 »
- 如何将3DMAX文件中的分散的贴图,集成到单独的一张图里面?
- 我将ws2_32.dll的WSARecv函数Hook成功后,为什么截获不到http 1.0的数据 (delphi版)
- DELPHI中如何使用QuickReport控件将查询结果生成的报表
- 今天玩了会游戏,突然心血来潮,问个外挂问题
- 如何屏蔽win按键?
- 小弟才学delphi,提个问题。关于复制、粘帖
- Delphi7三层关于IntraWeb的问题,一定给分!
- 如何关闭正在使用的abc.mdb文件?
- 100分寻求软件或实现代码,不知道是不是很菜的问题
- 请问如何让自己的程序在win2000的登录对话框出现前运行?
- 请问怎样两个窗体用一个adoquery?
- 奇怪问题。。。
Function TestHookProcfunction(Code: Integer; WParam: Longint; var Msg: TMsg): Longint; stdcall;begin
if Code = HC_Action then
if Msg.message = WM_TestMessage then
begin
showmessage('已经截获该消息');
end;
//挂钩下一个函数
Result := CallNextHookEx(HookHandle,Code,WParam,Longint(@Msg));
end;procedure TForm1.FormCreate(Sender: TObject);
begin //安装HOOK
HookHandle := SetWindowsHookEx(WH_GetMessage,@TestHookProcfunction,0,GetCurrentThreadID);end;procedure TForm1.Button1Click(Sender: TObject);
begin //发特定消息
PostMessage(self.Handle,WM_TestMessage,0,0);
end;
不过我还没有达到我的目的啊
如果我点击Button1时应该发送消息啊
然后调用 函数TestHookProc(Code:Integer;WParam:LongInt;Var Msg:TMsg):LongInt;StdCall;
弹出消息对话框 showmessage('已经截获该消息'); 怎么不能啊
你也可以用delphi包装的钩子函数Application.HookMainWindow(WindowHook);
弹出来了