Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi Applicationhandle eines Fensters ermitteln (https://www.delphipraxis.net/73901-applicationhandle-eines-fensters-ermitteln.html)

VizeTE 25. Jul 2006 16:27

Re: Applicationhandle eines Fensters ermitteln
 
Zitat:

Zitat von Vjay
Also wenn du prüfen willst ob das Fenster, dass vorher den Focus hatte zu deiner Anwendung gehört, machst du das am einfahcsten (meiner Meinung nach) über die Prozess ID.

Du holst dir mit getWindowThreadProcessId die Prozess Id und vergleichst diese mit der aktuellen ProzessId, sieht dann etwa so aus:

Delphi-Quellcode:
function getWindowPID( const h: integer): dword;
begin
 getWindowThreadProcessId( h, result);
end;

function gehoertFensterZuMir( const handle: integer): Boolean
begin
 result:= getWindowPID( handle) = getCurrentProcessid;
end;

Keine Ahnung ob ich das richtig mache...
Wenn ich versuche das alles so zu übernehmen:

Delphi-Quellcode:
  ...
var
  AForegroundPID   : dword;
  AMyWindow        : boolean;
begin
  getWindowThreadProcessId(GetForegroundWindow, AForegroundPID);
  AMyWindow := AForegroundPID = getCurrentProcessId;
  ...
Dann bekomme ich die Fehlermeldung "Inkompatible Typen: cardinal und pointer". (erste Zeile)

Na dann dachte ich mach ich halt ein Pointer draus:
Delphi-Quellcode:
  ...
var
  AForegroundPID   : ^dword;
  AMyWindow        : boolean;
begin
  getWindowThreadProcessId(GetForegroundWindow, AForegroundPID);
  AMyWindow := AForegroundPID^ = getCurrentProcessId;
  ...
Ich denke das hat ein oder zweimal funktioniert. Jetzt bekomme ich aber in der ersten Zeile eine Zugriffsverletztung. Ich glaube ich stell mich gerade ganz schön dumm an aber ich komm' nicht d'rauf.

Vjay 26. Jul 2006 01:25

Re: Applicationhandle eines Fensters ermitteln
 
Neues Projekt erstellen, einen Timer darauf machen, diesen Code rein:

Delphi-Quellcode:
var
  AForegroundPID   : dword;
  AMyWindow        : boolean;
begin
  getWindowThreadProcessId(GetForegroundWindow, AForegroundPID);
  AMyWindow := AForegroundPID = getCurrentProcessId;
  caption:= inttostr( integer( amywindow));
end;
und funktioniert doch wunderbar = ?

VizeTE 26. Jul 2006 09:02

Re: Applicationhandle eines Fensters ermitteln
 
Stimmt, funktioniert unter Delphi7 einwandfrei. Unter Delphi5 bekomme ich aber die Fehlermeldung: "Inkompatible Typen: Cardinal und Pointer"
(Hätte wohl gleich dazuschreiben sollen das es sich um D5 handelt, sorry)

VizeTE 26. Jul 2006 10:05

Re: Applicationhandle eines Fensters ermitteln
 
juhuuu...ich glaube ich habs

Delphi-Quellcode:
var
  AForegroundPID   : dword;
  AMyWindow        : boolean;
begin
  AForegroundPID := 0;
  getWindowThreadProcessId(GetForegroundWindow, @AForegroundPID);
  AMyWindow := AForegroundPID = getCurrentProcessId;
  caption := BoolToStr(AMyWindow);
end;
Mit dem @-Operator funktionierts auch unter Delphi5. :zwinker:


Alle Zeitangaben in WEZ +1. Es ist jetzt 06:11 Uhr.
Seite 2 von 2     12   

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