Riješio sam ovako:
Code:
function FindWindowByTitle(WindowTitle: string): Hwnd;
var
NextHandle: Hwnd;
NextTitle: array[0..260] of char;
begin
NextHandle := GetWindow(Application.Handle, GW_HWNDFIRST);
while NextHandle > 0 do
begin
GetWindowText(NextHandle, NextTitle, 255);
if Pos(WindowTitle, StrPas(NextTitle)) <> 0 then
begin
Result := NextHandle;
Exit;
end
else
NextHandle := GetWindow(NextHandle, GW_HWNDNEXT);
end;
Result := 0;
end;
Code:
procedure TForm1.Button1Click(Sender: TObject);
function EnumChildProc(AHandle: THandle; AItems: TStrings): BOOL; stdcall;
var
buffer: array[0..255] of Char;
caption: array[0..255] of Char;
begin
Result := True;
GetClassName(AHandle, buffer, SizeOf(buffer) - 1);
SendMessage(AHandle, WM_GETTEXT, 256, Integer(@caption));
AItems.Add(Format('Handle: %d, Class: %s, Text: %s', [AHandle, buffer, caption]));
end;
var
wHnd: THandle;
begin
wHnd := FindWindowByTitle('Program');
ListBox1.Clear;
EnumChildWindows(wHnd, @EnumChildProc, Integer(ListBox1.Items));
end;
Znači tu dobijem handle i onda
Code:
SendMessage(handle, WM_SETTEXT, 0, Integer(PChar('tekst')));
I to radi, ali događa mi se jedna čudna stvar. U jednom od textboxova u koji upisujem, string se izbriše kada kliknem mišem na textbox, a vanjska aplikacija ga u obradi vidi kao praznog tj. kao da nema unosa. Ali to se ne događa na svim textboxovima već samo na određenima. Any advice?
@lan-mi
Pogledaj ovdje