求助!求助!急,大家帮忙,分不够再给 如何得到另外一个窗体上按钮按下的消息?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以设一boolean变量来捕捉button按钮是否按下,如果按下则调.... 同一個程序比較簡單 設置個全局變量即可 不同的程序 需要利用API函數 通過得到Button的HWND 來完成 我也知道用hook,我用了日志钩子截获不到。请大家给出具体例子好吗?谢谢 unit Main;interfaceuses 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. to hsmserver(撒哈拉之雨的悲伤) ,这个是截获其他程序的窗体消息还是自己窗体的消息? 没有时间写了。你去这里下类似的代码看看吧:http://www.2ccc.com/article.asp?articleid=1279http://www.2ccc.com/article.asp?articleid=923http://www.2ccc.com/article.asp?articleid=546http://www.2ccc.com/article.asp?articleid=278 ICS中的ftpclint控件如何实现断点续传,请给个源码例子,小弟有礼了。 紧急求助,ADO数据库取表名的问题 高分求救----800RMB/Month 行吗 各位,谁有Data object handlers示例? 文件读写遇到的问题Reset(f,1) BlockRead() 嘻嘻,找些歌来听听吧 QuickReport如何连接多个打印机? 我的小问题,看看...... 学习DELPHI 给推荐基本好书吧? 各位大侠 请问在form 上可以既画前景又画背景吗(在同一区域) 100分请教,解决后另开新帖给分 我是否应该升级我的delphi
不同的程序 需要利用API函數 通過得到Button的HWND 來完成
请大家给出具体例子好吗?谢谢
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.