TSysControl.GetText will truncate text to 1K characters. This is less worse than the VCL which - up to 10.1 Berlin - did this:
function GetSysWindowText(Window: HWND): string;
var
Text: array[0..256] of Char;
begin
SetString(Result, Text, Winapi.Windows.GetWindowText(Window, Text, Length(Text)));
end;
A solution like below is more flexible:
function GetSysWindowText_WMGetText(Window: HWND): string;
var
RequiredTextLength: Integer;
ObtainedTextLength: Integer;
begin
RequiredTextLength := SendMessage(Window, WM_GETTEXTLENGTH, 0, 0);
SetString(Result, PChar(nil), RequiredTextLength);
if RequiredTextLength <> 0 then
begin
ObtainedTextLength := SendMessage(Window, WM_GETTEXT, WParam(RequiredTextLength + 1), LParam(PChar(Result)));
if ObtainedTextLength < RequiredTextLength then
SetLength(Result, ObtainedTextLength);
end;
end;
Two notes:
Getting the text can be done by using GetWindowText or by sending a WM_GETTEXT message; The secret life of GetWindowText – The Old New Thing. TL;DR: explains the difference and favours WM_GETTEXT, and in-process GetWindowText will use WM_GETTEXT.
In the use-case I needed the fix for, the VCL DrawToolTipText in the Vcl.SysStyles unit cannot word-wrap long TTS_ALWAYSTIP based hint texts, but now at least they are longer
TSysControl.GetText
will truncate text to 1K characters. This is less worse than the VCL which - up to 10.1 Berlin - did this:A solution like below is more flexible:
Two notes:
GetWindowText
or by sending aWM_GETTEXT
message; The secret life of GetWindowText – The Old New Thing. TL;DR: explains the difference and favoursWM_GETTEXT
, and in-processGetWindowText
will useWM_GETTEXT
.DrawToolTipText
in theVcl.SysStyles
unit cannot word-wrap longTTS_ALWAYSTIP
based hint texts, but now at least they are longer