Znajdywanie kontrolek to wiadomo EnumWindows
ewentualnie EnumChildWindows
opisane na MSDNie plus mnóstwo stron do wygooglowania z przykładami, również w Delphi. Co do pobierania i ustawiania tekstu kontrolki typu Okno / Label / Edit / GroupBox to patrz poniżej.
Wersja ANSI (pochodzi ze źródel VCL Delphi 7):
function GetTextLen(AHandle : HWND) : Integer;
begin
Result := SendMessage(AHandle, WM_GETTEXTLENGTH, 0, 0);
end;
function GetTextBuf(AHandle : HWND; Buffer : PChar; BufSize : Integer) : Integer;
begin
Result := SendMessage(AHandle, WM_GETTEXT, BufSize, longint(Buffer));
end;
function GetText(AHandle : HWND) : string;
var
Len : Integer;
begin
Len := GetTextLen(AHandle);
SetString(Result, PChar(nil), Len);
if Len <> 0 then
begin
GetTextBuf(AHandle, Pointer(Result), Len + 1);
end;
end;
procedure SetSelStart(Handle : HWND; Value : Integer);
begin
SendMessage(Handle, EM_SETSEL, Value, Value);
end;
Wersja UNICODE (znalezione w Google lub ze źródeł TNT - nie pamiętam :)):
procedure SetWideText(ControlHandle : HWND; Text : Widestring);
begin
SendMessageW(ControlHandle, WM_SETTEXT, 0, Integer(PWideChar(Text)));
end;
function GetWideText(ControlHandle : HWND) : WideString;
begin
SetLength(Result, GetWindowTextLengthW(ControlHandle));
GetWindowTextW(ControlHandle, PWideChar(Result), Succ(Length(Result)));
end;
Natomiast SetWindowText
jest pewnie mniej uniwersalne bo raczej do okienek. Przynajmniej wiem, że zdarzało się mi iż GetWindowText
nie pobrał tekstu z jakiejś kontrolki. Także pewni również raczej przewidziane tylko dla okien.