function GetWindowText: WideString;
var
TextLength: Integer;
Text: PWideChar;
Wnd: HWND;
begin
Wnd:= GetActiveWindow;
TextLength:= SendMessageW(Wnd, WM_GETTEXTLENGTH, 0, 0);
if TextLength <> 0 then
begin
GetMem(Text, TextLength * 2 + 2);
SendMessageW(Wnd, WM_GETTEXT, WPARAM(TextLength*2 + 2), LPARAM(Text));
Result := Text;
FreeMem(Text);
end;
end;