求助!求助!急,大家帮忙,分不够再给

DieGhost 2004-10-29 06:25:26
如何得到另外一个窗体上按钮按下的消息??
...全文
204 24 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
24 条回复
切换为时间正序
请发表友善的回复…
发表回复
DieGhost 2004-11-03
  • 打赏
  • 举报
回复
问题自己解决了,绕了个弯路,才发现自己是个猪头
ksaiy 2004-11-01
  • 打赏
  • 举报
回复
没有具体看。你去下载来看看。
DieGhost 2004-10-31
  • 打赏
  • 举报
回复
是用WH_GETMESSAGE钩子吗?
ksaiy 2004-10-31
  • 打赏
  • 举报
回复
没有时间写了。你去这里下类似的代码看看吧:

http://www.2ccc.com/article.asp?articleid=1279

http://www.2ccc.com/article.asp?articleid=923

http://www.2ccc.com/article.asp?articleid=546

http://www.2ccc.com/article.asp?articleid=278
lyguo 2004-10-31
  • 打赏
  • 举报
回复
up
liuqifeiyu 2004-10-31
  • 打赏
  • 举报
回复
up
DieGhost 2004-10-31
  • 打赏
  • 举报
回复
up一下,高手快来啊
DieGhost 2004-10-30
  • 打赏
  • 举报
回复
晕死啊
DieGhost 2004-10-30
  • 打赏
  • 举报
回复
to hsmserver(撒哈拉之雨的悲伤) ,这个是截获其他程序的窗体消息还是自己窗体的消息?
hsmserver 2004-10-30
  • 打赏
  • 举报
回复
发错了,不好意思
hsmserver 2004-10-30
  • 打赏
  • 举报
回复
unit Main;

interface

uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, ShellAPI,ExtCtrls,Buttons;

type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
Hook: TMemo;
GroupBox3: TGroupBox;
OnDown: TLabel;
OnUp: TLabel;
GroupBox4: TGroupBox;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
procedure FormCreate(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
public
WindowHandle: HWnd;
StartSpy:Boolean;
OldKey: Byte;
LShiftUp, RShiftUp: Boolean;

procedure WndProc(var Msg: TMessage);
procedure KeyDownSpy;
procedure UpdateTimer;
procedure KeySpyDown(Sender: TObject; Key: Byte; KeyStr: String);
procedure KeySpyUp(Sender: TObject; Key: Byte; KeyStr: String);
end;

const
OldRet: Boolean = False;
var
Form1: TForm1;

implementation

{$R *.DFM}
const
LowButtonName: Array[1..88] of PChar =
('--Esc','1','2','3','4','5','6','7','8','9',
'0','-','=','--BkSp','--Tab','q','w','e','r','t',
'y','u','i','o','p','[',']','--Enter','--Ctrl','a',
's','d','f','g','h','j','k','l',';','''','`',
'--LShift Down','\','z','x','c','v','b','n','m',',',
'.','/',
'--RShift Down','--Gray*','--Alt','--Space',
'--CapsLock','--F1','--F2','--F3','--F4','--F5',
'--F6','--F7','--F8','--F9','--F10',
'--NumLock','--ScrollLock','--Home','--Up',
'--PgUp','--Gray-','--Left','--*5*','--Right',
'--Gray+','--End','--Down','--PgDown','--Ins',
'--Del','--LShift Up','--RShift Up',
'--Unknown','--F11','--F12');

HiButtonName: Array[1..88] of PChar =
('--Esc','!','@','#','$','%','^','&','*','(',
')','_','+','--BkSp','--Tab','Q','W','E','R','T',
'Y','U','I','O','P','{','}','--Enter','--Ctrl','A',
'S','D','F','G','H','J','K','L',':','"','~',
'--LShift Down','|','Z','X','C','V','B','N','M','<',
'>','?',
'--RShift Down','--Gray*','--Alt','--Space',
'--CapsLock','--F1','--F2','--F3','--F4','--F5',
'--F6','--F7','--F8','--F9','--F10',
'--NumLock','--ScrollLock','--Home','--Up',
'--PgUp','--Gray-','--Left','--*5*','--Right',
'--Gray+','--End','--Down','--PgDown','--Ins',
'--Del','--LShift Up','--RShift Up',
'--Unknown','--F11','--F12');

procedure TForm1.WndProc(var Msg: TMessage);
begin
with Msg do
if Msg = WM_TIMER then
try
KeyDownSpy;
except
Application.HandleException(Self);
end
else
Result := DefWindowProc(WindowHandle, Msg, wParam, lParam);
end;

procedure TForm1.UpdateTimer;
var
b: Byte;
begin
KillTimer(WindowHandle, 1);
if StartSpy then
begin
asm
mov al, 60h
mov b, al
end;
OldKey := b;
if SetTimer(WindowHandle, 1, 1, nil) = 0 then
raise EOutOfResources.Create('建立定时器出错');
end;
end;

procedure TForm1.KeyDownSpy;
var
Key: Byte;
St: String;
begin
asm
in al, 60h
mov Key, al
end;
if Key = 170 then
begin
Key := 84;
LShiftUp := True;
end;
if Key = 182 then
begin
Key := 85;
RShiftUp := True;
end;
if Key = 42 then LShiftUp := False;
if Key = 54 then RShiftUp := False;
if Key <> OldKey then
begin
OldKey := Key;
if Key <= 88 then
begin
if LShiftUp and RShiftUp then
St := StrPas(LowButtonName[Key])
else
St := StrPas(HiButtonName[Key]);
KeySpyDown(self,key,st);
end
else
if (Key - 128 <= 88) then
begin
if LShiftUp and RShiftUp then
St := StrPas(LowButtonName[Key - 128])
else
St := StrPas(HiButtonName[Key - 128]);
KeySpyUp(self,key,st);
end;
end;
end;

procedure TForm1.KeySpyDown(Sender: TObject; Key: Byte;
KeyStr: String);
begin
OnDown.Caption := 'KeySpyDown: Key = ' + IntToStr(Key) + ', KeyStr = ' + KeyStr;
if (KeyStr[1] = '-') and (KeyStr[2] = '-') then
begin
Hook.Lines.Add('');
OldRet := True;
end
else
if OldRet then
begin
Hook.Lines.Add('');
OldRet := False;
end;
Hook.Text := Hook.Text + KeyStr;

end;

procedure TForm1.KeySpyUp(Sender: TObject; Key: Byte;
KeyStr: String);
begin
OnUp.Caption := 'KeySpyUp: Key = ' + IntToStr(Key) + ', KeyStr = ' + KeyStr;
end;



procedure TForm1.FormCreate(Sender: TObject);
begin
LShiftUp := True;
RShiftUp := True;
StartSpy := True;
WindowHandle := AllocateHWnd(WndProc);
if StartSpy then UpdateTimer;
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
StartSpy:=true;
end;

procedure TForm1.BitBtn2Click(Sender: TObject);
begin
StartSpy:=false;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
StartSpy := False;
UpdateTimer;
DeallocateHWnd(WindowHandle);
end;

end.
dwf3110 2004-10-30
  • 打赏
  • 举报
回复
同一個程序比較簡單 設置個全局變量即可
不同的程序 需要利用API函數 通過得到Button的HWND 來完成
dwf3110 2004-10-30
  • 打赏
  • 举报
回复
是同一個應用程序嗎 還是2個不同的程序?
lyguo 2004-10-30
  • 打赏
  • 举报
回复
关注
DieGhost 2004-10-30
  • 打赏
  • 举报
回复
我也知道用hook,我用了日志钩子截获不到。
请大家给出具体例子好吗?谢谢
whythinkwhy 2004-10-30
  • 打赏
  • 举报
回复
可以设一boolean变量来捕捉button按钮是否按下,如果按下则调....
longtusoft 2004-10-30
  • 打赏
  • 举报
回复
HOOK技术比较可行.
DieGhost 2004-10-30
  • 打赏
  • 举报
回复
另外一个程序!捕捉另外一个程序窗体上的按钮
hottey 2004-10-29
  • 打赏
  • 举报
回复
Hook
DieGhost 2004-10-29
  • 打赏
  • 举报
回复
up一下!!!!!!!急啊
加载更多回复(4)

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧