Autor Beitrag
Bronstein
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 578
Erhaltene Danke: 1

WIN XP
Delphi 6 / Delphi 2006 / Delphi XE
BeitragVerfasst: Fr 15.07.11 08:11 
Hallo,
ich habe eine Funktion im Internet gefunden mit der man das Handel einer anderen Anwendung bekommt. Diese habe ich etwas angepasst und
danach habe ich die Funktion in einer GUI-Anwendung getestet und sie hat funktioniert.
Jetzt wollte ich die Funktion in einer DLL nutzen, doch hier funktioniert sie nicht. NextHandle ist in der DLL immer 0

Ich komme also nie in die Schleife!

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:
function FindWindowByTitle(WindowTitle: string): Hwnd;
var
  NextHandle: Hwnd;
  NextTitle: array[0..260of char;
  tmpStr: String;
begin
  // Get the first window
  NextHandle := GetWindow(Application.Handle, GW_HWNDFIRST);
  while NextHandle > 0 do
  begin
    // retrieve its text
    GetWindowText(NextHandle, NextTitle, 255);
    tmpStr := 'x' + StrPas(NextTitle);
    if Pos(WindowTitle, tmpStr) > 0 then
    begin
      Result := NextHandle;
      Exit;
    end
    else
      // Get the next window
      NextHandle := GetWindow(NextHandle, GW_HWNDNEXT);
  end;
  Result := 0;
end;

_________________
Es gibt keine dummen Fragen nur dumme Antworten!!!
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19315
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Fr 15.07.11 09:02 
Wahrscheinlich ist Application.Handle in einer DLL ein anderer Fenstertyp. :nixweiss:

Aber warum nimmst du nicht einfach die in der Dokumentation stattdessen empfohlene Enum-Funktion? (Bei dir dann wohl eher EnumWindows statt EnumChildWindows)
msdn.microsoft.com/e...ibrary/ms633497.aspx