Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi Handle von Control (https://www.delphipraxis.net/132017-handle-von-control.html)

Jeopardize 4. Apr 2009 14:25


Handle von Control
 
Moin DPler :mrgreen: ,
ich versuche gerade an das Handle von einer Control-Instanz(so wie Button1,Button2) in einer anderen Anwendung zu kommen.
Zuerst hole ich das Handle vom Fenster:
Delphi-Quellcode:
var H1, H2: HWND;
...
H := FindWindow('MozillaUIWindowClass',nil);
(Das funktioniert noch)

Und dann versuche ich das Handle von einer Control-Instanz zu bekommen
(Fenster-Klasse = MozillaUIWindowClass, Control-Klasse = MozillaWindowClass)
Von der Control-Klasse will ich die 6te Instanz.

Dafür habe ich diese Funktion im Swiss Delphi-Center gefunden:
Delphi-Quellcode:
function FindControlByNumber(hApp: HWND; ControlClassName: 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(ControlClassName), nil);
      if hControl = 0 then
        Exit;
    end;
  end;
  Result := hControl;
end;
Aufruf:
Delphi-Quellcode:
H2 := iFindControlByNumber(H1,'MozillaWindowClass',6);
  if H2 <> 0 then ShowMessage('Control gefunden');
Die MsgBox erscheint aber nie.
So funktioniert es komischerweise:
Delphi-Quellcode:
H2 := iFindControlByNumber(H1,'MozillaWindowClass',1);
  if H2 <> 0 then ShowMessage('Control gefunden');
Nun, ich will aber die 6te Instanz, nicht die erste^^
Hoffe jemand hat eine Lösung oder wenigstens eine Idee. :)
mfg, Jeopardize

toms 4. Apr 2009 14:34

Re: Handle von Control
 
Hallo

Zitat:

Von der Control-Klasse will ich die 6te Instanz.
Die Controls müssen sich auf der gleichen Child-Ebene befinden, damit FindControlByNumber funktioniert.
Die Mozilla (resp. Firefox) Fenster-Hierarchie ist aber so aufgebaut:

Code:
MozillaUIWindowClass
  MozillaWindowClass
   MozillaWindowClass
    MozillaWindowClass
     MozillaContentWindowClass
      MozillaWindowClass
       MozillaWindowClass
Mein WinSpy Tool hat folgenden Code erzeugt.

Delphi-Quellcode:
var
  wndMain, wndChild: HWND;
begin
  wndMain := FindWindow('MozillaUIWindowClass', nil);
  if wndMain <> 0 then
  begin
    wndChild := FindWindowEx(wndMain, 0, 'MozillaWindowClass', nil);
    wndChild := FindWindowEx(wndChild, 0, 'MozillaWindowClass', nil);
    wndChild := FindWindowEx(wndChild, 0, 'MozillaWindowClass', nil);
    wndChild := FindWindowEx(wndChild, 0, 'MozillaContentWindowClass', nil);
    wndChild := FindWindowEx(wndChild, 0, 'MozillaWindowClass', nil);
    wndChild := FindWindowEx(wndChild, 0, 'MozillaWindowClass', nil);
    if wndChild <> 0 then
    begin
      ShowMessage('Window Handle: ' + IntToStr(wndChild));
    end;
  end;
end.

Jeopardize 4. Apr 2009 14:41

Re: Handle von Control
 
Danke erstmal, ganz schön kompliziert.
Das macht es recht schwer den ich hatte vor eine Funktion zu schreiben die immer das Handle des Controls zurückgibt. Aber dann muss ich das wohl anders lösen. :)

EDIT: WinSpy funktioniert super, echt praktisch :mrgreen:

Jeopardize 4. Apr 2009 15:05

Re: Handle von Control
 
Schon habe ich das nächste Problem: :(
Delphi-Quellcode:
function GetWindowLeft(Window: HWND): Integer;
var Place:TWindowPlacement;
begin
  Place.Length:=SizeOf(TWindowPlacement);
  GetWindowPlacement(Window,@Place);
  result := Place.rcNormalPosition.Left;
end;

function GetWindowTop(Window: HWND): Integer;
var Place:TWindowPlacement;
begin
  Place.Length:=SizeOf(TWindowPlacement);
  GetWindowPlacement(Window,@Place);
  result := Place.rcNormalPosition.Top;
end;
Diese Funktionen liefern nicht die Position vom Control auf dem Bildschirm, sondern offensichtlich nur Abstand von der nächst-höheren Instanz weg. Gibts da ne bessere Möglichkeit?

EDIT: Habe es selbst gefunden, wenn es jemand wissen will^^:
Delphi-Quellcode:
 GetWindowRect(Handle,TRect);
X := TRect.Left;
Y := Trect.Top;


Alle Zeitangaben in WEZ +1. Es ist jetzt 16:30 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz