function GetFocusHandle: HWND;
var
h: HWND;
c: array[0102432] of Char;
idAttach: Cardinal;
begin
H := GetForegroundWindow;
idAttach := GetWindowThreadProcessId(h, nil);
if not AttachThreadInput(idAttach , GetCurrentThreadId(), True) then Exit;
Result := GetFocus;
AttachThreadInput(idAttach, GetCurrentThreadId(), false );
end;
你的问题说的不清楚。不知道你是不想用个热键的方式。
帮你写个例子吧。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
//定义一个热键消息事件
procedure HotKeyDown(var Msg:Tmessage);message WM_HOTKEY;
public
{ Public declarations }
end;
var
Form1: TForm1;
HotKeyid:Integer;
implementation
{$R dfm}
procedure TForm1FormCreate(Sender: TObject);
var
RegKey:longbool;
begin
//GlobalAddAtom函数得到唯一标识
HotKeyid:=GlobalAddAtom('MyHotKey')-$C00;
//HotKeyId的合法取之范围是0x0000到0xBFFF之间, GlobalAddAtom函数得到的值
//在0xC000到0xFFFF之间,所以减掉0xC000来满足调用要求。
RegKey:= RegisterHotKey(Handle,HotKeyid,0,VK_F5);
if RegKey=false then showmessage('热键注册失败');
//热键的辅助按键包括Mod_Ctrl 、Mod_Alt、Mod_Shift,对于Windows兼容键盘还支持Windows
//键,即其键面上有Windows标志的那个键,其值为Mod_win。
//上面 的代码注册了一个热键:F5。
end;
procedure TForm1FormClose(Sender: TObject; var Action: TCloseAction);
begin
UnRegisterHotKey(handle,HotKeyid); //注销热键
end;
procedure TForm1HotKeyDown(var Msg: Tmessage);
begin
//如果按下F5键, 响应你想要的 *** 作
if MsgLParamHi=VK_F5 then
begin
form1Visible := not form1Visible;
end
end;
end
以上就是关于Delphi中如何获取外部程序焦点所在控件的句柄全部的内容,包括:Delphi中如何获取外部程序焦点所在控件的句柄、delphi 控件焦点问题、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)