Thema: Delphi FindwindowEx

Einzelnen Beitrag anzeigen

Benutzerbild von toms
toms
(CodeLib-Manager)

Registriert seit: 10. Jun 2002
4.648 Beiträge
 
Delphi XE Professional
 
#4

Re: FindwindowEx

  Alt 1. Feb 2004, 19:47
Zitat:
ich will mit FindWindowEx einen string, in ein anderes fenster einfügen, doch in dem anderem fenster gibt es 4x TEdit....
Sollte so funktionieren:

Delphi-Quellcode:
function FindControlByNumber(hApp: HWND; ClassName: string; ControlNr: Word = 1): HWND;
var
  i: Word;
  hControl: HWND;
begin
  Result := 0;
  if IsWindow(hApp) then
  begin
    Dec(ControlNr);
    hControl := 0;
    for i := 0 to ControlNr do
    begin
      hControl := FindWindowEx(hApp, hControl, PChar(ClassName), nil);
      if hControl = 0 then
        Exit;
    end;
  end;
  Result := hControl;
end;

procedure SetEditText(hApp: HWND; ClassName, AText: string; EditNr: Integer);
var
  hEdit: HWND;
begin
  hEdit := FindControlByNumber(hApp, ClassName, EditNr);
  if hEdit <> 0 then
    SendMessage(hEdit, WM_SETTEXT, 0, Integer(PChar(AText)));
end;

// dem "4." Edit vom Fenster TForm1 Text senden.
procedure TForm1.Button1Click(Sender: TObject);
begin
  SetEditText(FindWindow('TForm1', nil),'TEdit','alalalala',4);
end;
Thomas
  Mit Zitat antworten Zitat