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;