●●●●怎么解决这个问题(捕捉Windows的所有消息)●●●●● ( 积分: 100 )

  • 主题发起人 主题发起人 longjiang
  • 开始时间 开始时间
L

longjiang

Unregistered / Unconfirmed
GUEST, unregistred user!
问题如下:
我怎么捕获系统所有的消息啊!!代码如下:
function HookProc(iCode: integer; wParam: wParam; lParam: lParam): LResult; stdcall;
var
s:string;
begin

if (PEventMsg(lparam)^.message = BM_CLICK) then
begin
Form1.ListBox1.Items.Add('1');
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
hooktimes := 0;
hHook := 0;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
inc(hooktimes);
if hooktimes = 1 then
begin
hookkey := TimeToStr(now) + ' ';
hHook := SetWindowsHookEx(WH_CALLWNDPROC, HookProc, HInstance, 0);
MessageBox(0, '启动', '信息', MB_ICONINFORMATION + MB_OK);
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
UnHookWindowsHookEx(hHook);
hHook := 0;
if hooktimes <> 0 then
begin
MessageBox(0, '监视关闭', '信息', MB_ICONINFORMATION + MB_OK);
end;
hooktimes := 0;
end;

procedure TForm1.ListBox1DblClick(Sender: TObject);
begin
listbox1.clear;
end;

procedure TForm1.btn1Click(Sender: TObject);
begin
SendMessage(btn2.Handle ,BM_CLICK ,0,0 );
end;
问题使用WH_CALLWNDPROC的时候好像机器会死掉
 
问题如下:
我怎么捕获系统所有的消息啊!!代码如下:
function HookProc(iCode: integer; wParam: wParam; lParam: lParam): LResult; stdcall;
var
s:string;
begin

if (PEventMsg(lparam)^.message = BM_CLICK) then
begin
Form1.ListBox1.Items.Add('1');
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
hooktimes := 0;
hHook := 0;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
inc(hooktimes);
if hooktimes = 1 then
begin
hookkey := TimeToStr(now) + ' ';
hHook := SetWindowsHookEx(WH_CALLWNDPROC, HookProc, HInstance, 0);
MessageBox(0, '启动', '信息', MB_ICONINFORMATION + MB_OK);
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
UnHookWindowsHookEx(hHook);
hHook := 0;
if hooktimes <> 0 then
begin
MessageBox(0, '监视关闭', '信息', MB_ICONINFORMATION + MB_OK);
end;
hooktimes := 0;
end;

procedure TForm1.ListBox1DblClick(Sender: TObject);
begin
listbox1.clear;
end;

procedure TForm1.btn1Click(Sender: TObject);
begin
SendMessage(btn2.Handle ,BM_CLICK ,0,0 );
end;
问题使用WH_CALLWNDPROC的时候好像机器会死掉
 
用WH_MSGFILTER 和WH_SYSMSGFILTER 钩子
 
to daqun:这两个好像不行吧!!!
 
拦截系统的,消息分配机制啊!
 
谁有累死的例子啊,给我一个看看!!谢谢了
 
在程序中加入TApplicationEvents控件,代码如下
procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
begin
listbox1.items.add(IntToStr(Msg.message));
end;
msg.message就是系统消息,msg中还包括了获取这个消息的窗口或控件句柄及参数等
 
whitewolfxp: 我要得到的不是自身程序的所有消息,要的是Windows的所有消息
就像spy++的软件一样
 
代码如何下:
function HookProc(iCode: integer; wParam: wParam; lParam: lParam): LResult; stdcall;
var
s:string;
begin

if (PEventMsg(lparam)^.message = BM_CLICK) then
begin
Form1.ListBox1.Items.Add('1');
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
hooktimes := 0;
hHook := 0;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
inc(hooktimes);
if hooktimes = 1 then
begin
hookkey := TimeToStr(now) + ' ';
hHook := SetWindowsHookEx(WH_CALLWNDPROC, HookProc, HInstance, 0);
MessageBox(0, '启动', '信息', MB_ICONINFORMATION + MB_OK);
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
UnHookWindowsHookEx(hHook);
hHook := 0;
if hooktimes <> 0 then
begin
MessageBox(0, '监视关闭', '信息', MB_ICONINFORMATION + MB_OK);
end;
hooktimes := 0;
end;

procedure TForm1.ListBox1DblClick(Sender: TObject);
begin
listbox1.clear;
end;

procedure TForm1.btn1Click(Sender: TObject);
begin
SendMessage(btn2.Handle ,BM_CLICK ,0,0 );
end;
 
HookProc 要写在dll中
 
放在dll中也不行。。。。
 

Similar threads

I
回复
0
查看
641
import
I
I
回复
0
查看
623
import
I
后退
顶部