Autor Beitrag
Flamefire
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Di 18.03.08 21:35 
Ich brauche eine Funktion, die wie in Autoit ein Fenster anhand von Titel und Text ermittelt

Kennt jemand so was?
Mein versuch war der hier:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
function GetWindowText2(wnd: Hwnd): String;
var
  S:String;
  I:Integer;
begin
  I := GetWindowTextLength(wnd);
  SetLength(S, I + 1);
  GetWindowText(wnd, PChar(S), I + 1);
   Result:=S;
end;

function enumProc(wnd: Hwnd; Text:PChar): Boolean; stdcall;
var
  dwStyle: Integer;
  bAdd: Boolean;
  s:String;
begin
  Result := true;
  if IsWindowVisible(wnd) then
  begin
    If(GetWindowText2(wnd)='OK'then Text:=PChar(IntToHex(wnd, 8));
  end;
end;

...

      SetLength(S,100);
      EnumChildWindows(fHandle,@enumProc,Integer(@S));

Es kommt immer nur Kauderwelsch zurück.
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Mi 19.03.08 00:49 
Ähm, das hast du in deiner anderen Frage schon gemacht... zumindest nach Titel: FindWindow bzw. FindWindowEx.

Und um nach Text zu suchen, bist du schon fast richtig. Nur wenn du den als solchen Zeiger übergibst, müsstest du den PChar auch ordentlich erstellen (GetMem) und den String ordentlich reinkopieren (StrPCopy).

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
Flamefire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Mi 19.03.08 12:30 
öhm???

reicht das setlength nicht?
und wie was reinkopieren?
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Mi 19.03.08 21:03 
GetMem und StrPCopy sind nicht notwendig, du musst den String nur richtig übergeben. Ein String ist bereits ein Zeiger (sizeof(string) = 4), du übergibts also quasi einen Zeiger auf einen Zeiger. Was du aber brauchst ist ein Zeiger auf das erste Zeichen des Strings:
ausblenden Delphi-Quelltext
1:
EnumChildWindows(fHandle,@enumProc,Integer(@S[1]));					

Alternativ geht auch:
ausblenden Delphi-Quelltext
1:
EnumChildWindows(fHandle,@enumProc,Integer(Pointer(S)));					

da muss man dann aber auf Seiteneffekte aufpassen. Für Details dazu empfehl ich dir mein Strings-Tutorial auf www.manuel-poeter.de

Gruß, Motzi

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
Flamefire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Mi 19.03.08 21:58 
hmm
und wie muss die enumProc aussehen?
mit der hier:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
function enumProc(wnd: Hwnd; Text:PChar): Boolean; stdcall;
var s:String;
begin
  Result := true;
  if IsWindowVisible(wnd) then
  begin
    s:=GetWindowText2(wnd);
    If(Pos('OK',s)>0then begin
      Text:=PChar(IntToHex(wnd, 8));
    end else begin
      Text:='LOL';
    end;
  end;
end;

wird der string nicht überschrieben
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Do 20.03.08 11:27 
Sorry, mein Fehler.. das ist genau einer der Seiteneffekte wenn man Strings nach PChar castet! ;) Bei diesem cast @s[1] wird intern UniqueString aufgerufen wodurch eine neue Kopie des Strings erstellt wird, deren Referenzzähler 1 ist. Der Seiteneffekt davon ist allerdings, dass sich Änderungen an dieser Kopie nicht mehr auf das Original auswirken - meist wünschenswert, in deinem Fall jedoch das Gegenteil.
Du musst also entweder per PChar(s) oder Pointer(s) casten - in beiden Fällen bekommst du einen Zeiger auf das erste Zeichen des Strings (im Fall von PChar(s) wird noch ein bisschen was anderes im Hintergrund erledigt, aber das ist nicht weiter wichtig), welcher dann noch explizit nach Integer/LParam gecastet werden muss damit EnumWindow ihn als Parameter akzeptiert.

Gruß, Motzi

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
Flamefire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Do 20.03.08 12:18 
klappt immer noch nicht
in der enumproc wird die zuweisung auf Text einfach übersprungen
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Do 20.03.08 12:59 
Hm, erklär doch bitte nochmal ganz genau was du eigentlich machen möchtest..

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
Flamefire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Do 20.03.08 15:08 
ich möchte ein fenster suchen, was einen bestimmten text hat (messagedlg mit ner meldung)
dazu ist das die unterprozedurm die den text überprüfen soll

passieren soll damit:
alle unterfenster durchgehen, wenn text=vorgabe dann gib handle zurück sonst nix

wenn jmd ne bessere idee hat wäre ich dafür dankbar
vl ne globale var?
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Do 20.03.08 15:11 
Gibt es nur ein solches Fenster oder kann es auch mehrere geben? Sofern nur ein Fenster gefunden werden soll geht das mit FindWindow wesentlich einfacher, bei mehreren Fenstern musst du EnumWindows verwenden, allerdings ein bisschen anders als bisher.. ;)

Sag bescheid ob es um ein oder mehrere Fenster geht, dann kann ich dir den entsprechenden Code geben...

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
Flamefire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Do 20.03.08 15:48 
also: ein programm mit name "xxx" hat ein fenster titel "yyy"
das kann messagedlg-fenster öffnen, die auch als titel "yyy" haben
jetzt will ich den text aus dem messagedlg haben, bzw wissen ob ein solches messagedlg fenster mit einem bestimmten text existiert

mit autoit geht das recht einfach, da kann man titel und text angeben und der findet das entprechende fenster oder gibt ne 0 zurück

ich will praktisch das programm fernsteuern und wissen, was der sonst noch ausgibt. fehlermeldungen, status etc.