AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Handle von Control

Ein Thema von Jeopardize · begonnen am 4. Apr 2009 · letzter Beitrag vom 4. Apr 2009
Antwort Antwort
Jeopardize

Registriert seit: 20. Mär 2007
Ort: Villach
65 Beiträge
 
Turbo Delphi für .NET
 
#1

Handle von Control

  Alt 4. Apr 2009, 14:25
Moin DPler ,
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
  Mit Zitat antworten Zitat
Benutzerbild von toms
toms
(CodeLib-Manager)

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

Re: Handle von Control

  Alt 4. Apr 2009, 14:34
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.
Thomas
  Mit Zitat antworten Zitat
Jeopardize

Registriert seit: 20. Mär 2007
Ort: Villach
65 Beiträge
 
Turbo Delphi für .NET
 
#3

Re: Handle von Control

  Alt 4. Apr 2009, 14:41
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
  Mit Zitat antworten Zitat
Jeopardize

Registriert seit: 20. Mär 2007
Ort: Villach
65 Beiträge
 
Turbo Delphi für .NET
 
#4

Re: Handle von Control

  Alt 4. Apr 2009, 15:05
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;
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 12: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