Witam. Mam taki oto kod:
function GetText(WindowHandle: hwnd):string;
var
txtLength : integer;
buffer: string;
begin
TxtLength := SendMessage(WindowHandle, WM_GETTEXTLENGTH, 0, 0);
txtlength := txtlength + 1;
setlength (buffer, txtlength);
sendmessage (WindowHandle,wm_gettext, txtlength, longint(@buffer[1]));
result := buffer;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
hWindow, hEdit, hButton: HWND;
ID: Integer;
R: string;
begin
R := edit2.text;
hWindow := FindWindow('#12345', nil);
hEdit := FindWindowEx(hWindow, 0, 'Edit', nil);
hButton := FindWindowEx(hWindow, 0, 'Button', nil);
begin
if (hEdit <> 0) and
(hButton <> 0) then
begin
SendMessage(hEdit, WM_SETTEXT, 0, Longint(PChar(R)));
ID := GetWindowLong(hButton, GWL_ID);
PostMessage(hWindow, WM_COMMAND,
MakeLong(ID, BN_CLICKED), hButton);
end;
end;
Uzupełnia to pewne pole, klika w button, oraz kopiuje text z podanego pola w jakimś programie. I mam w związku z tym problem. Otóż aby znaleźć odpowiedni komponent na "tamtej" formie, uzywam funkcji:
hEdit := FindWindowEx(hWindow, 0, 'Edit', nil);
hButton := FindWindowEx(hWindow, 0, 'Button', nil);
Co zrobić, gdy mam 2 komponenty o tej samej klasie, np. 2x Edit. I do jednego chciałbym coś wpisać, a z drugiego coś skopiować (za pomocą funkcji GetText).
Jak je odróżnić?
Pozdrawiam