Delphi中如何获取外部程序焦点所在控件的句柄

2024-12-16 11:41:22
推荐回答(1个)
回答1:

function GetFocusHandle: HWND;
var
h: HWND;
c: array[0..1024*32] 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;