1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| procedure TFPrincipal.GetFocusedControl(var FocusWin: HWND; var ClassName, ControlText, ParentText: string);
var
hOtherWin: HWND;
OtherThreadID: Cardinal;
aDwordvar: DWORD;
hFocusWin: HWND;
S,
ss,
sss: string;
I: Integer;
begin
S := '';
ss := '';
sss:='';
hFocusWin := 0;
hOtherWin := GetForegroundWindow;
OtherThreadID := GetWindowThreadProcessID(hOtherWin, @aDwordvar);
if AttachThreadInput(GetCurrentThreadID, OtherThreadID, True) then
begin
hFocusWin := GetFocus;
if hFocusWin<>0 then
try
I := SendMessage(hFocusWin, WM_GETTEXTLENGTH, 0, 0);
SetLength(S, I+1);
SendMessage(hFocusWin, WM_GETTEXT, I+1, Integer(PChar(S)));
SetLength(ss, 260);
GetClassName(hFocusWin, PChar(ss), 260);
I := SendMessage(GetParent(hFocusWin), WM_GETTEXTLENGTH, 0, 0);
SetLength(sss, I+1);
SendMessage(GetParent(hFocusWin), WM_GETTEXT, I+1, Integer(PChar(sss))); finally
AttachThreadInput(GetCurrentThreadID, OtherThreadID, False);
end;
end;
FocusWin := hFocusWin;
ClassName := Trim(ss);
ControlText := Trim(S);
ParentText := Trim(sss);end; |