如何捕获窗体所有控件发生的事件

 我来答
匿名用户
推荐于2016-05-09
展开全部
用HOOK应该可以实现,下面是代码供参考

unit Unit1;

interface

uses
Windows, Messages, SysUtils, 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;

function TestHookProc(Code: Integer; WParam: Longint;Msg:Longint): Longint;stdcall;
begin
if (Code = HC_ACTION) then
if PMsg(Msg)^.Message = WM_TestMessage then
begin
showMessage('已经截获该消息');
end;
Result := CallNextHookEx(HookHandle, Code, WParam, Longint(@Msg));
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
HookHandle:=SetWindowsHookEx(WH_GETMESSAGE,TestHookProc,0,GetCurrentThreadID);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
PostMessage(self.Handle,WM_TestMessage,0,0);
end;

end.
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式