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 Vom Handle zur Position und Größe einer Form (https://www.delphipraxis.net/38214-vom-handle-zur-position-und-groesse-einer-form.html)

Jelly 16. Jan 2005 11:11


Vom Handle zur Position und Größe einer Form
 
Irgendwie komm ich nicht weiter.

Über GetActiveWindow erhalte ich das Handle der gerade aktive Form. Ich kann mit diesem Handle aber direkt nix anfangen. Ich suche nach ner Möglichkeit, aufgrund dieses Handle auf die Position und Größe des Fenster zu schließen, aber irgendwie hab ich da keine Ahnung, wie diese ganzen API Befehler heissen.

Zum Hintergrund, ich will einen Screenshot des aktuellen Fenster mache, und diesen und desse Thumbnail als JPG zu speichern.

Ultimator 16. Jan 2005 11:23

Re: Vom Handle zur Position und Größe einer Form
 
Ich glaube, da ist getWindowRect das richtige für dich ;-)

Zitat:

The GetWindowRect function retrieves the dimensions of the bounding rectangle of the specified window. The dimensions are given in screen coordinates that are relative to the upper-left corner of the screen.

BOOL GetWindowRect(

HWND hWnd, // handle of window
LPRECT lpRect // address of structure for window coordinates
);

Parameters

hWnd

Identifies the window.

lpRect

Points to a RECT structure that receives the screen coordinates of the upper-left and lower-right corners of the window.
Noch was zum o.g. Rect:

Zitat:

The RECT structure defines the coordinates of the upper-left and lower-right corners of a rectangle.

typedef struct _RECT { // rc
LONG left;
LONG top;
LONG right;
LONG bottom;
} RECT;


Members

left

Specifies the x-coordinate of the upper-left corner of the rectangle.

top

Specifies the y-coordinate of the upper-left corner of the rectangle.

right

Specifies the x-coordinate of the lower-right corner of the rectangle.

bottom

Specifies the y-coordinate of the lower-right corner of the rectangle.
[edit] Noch schnell n Beispiel, es geht nämlich einfach mit nem TRect als _RECT ;-)
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var MyRect:TRect;
begin
GetWindowRect(Form1.Handle,MyRect);
ShowMessage('Links oben: X: '+inttostr(MyRect.TopLeft.X) +', Y: '+ inttostr(MyRect.TopLeft.Y)+
  #10#13+'Rechts unten: X: '+inttostr(MyRect.BottomRight.X)+', Y: '+inttostr(MyRect.BottomRight.Y));
end;

Jelly 16. Jan 2005 11:50

Re: Vom Handle zur Position und Größe einer Form
 
Danke, genau das hab ich gesucht... Klappt einwandfrei... :firejump:

Aike 22. Mai 2005 19:40

Re: Vom Handle zur Position und Größe einer Form
 
Wie ist denn das Handle den "Windows-Fensters"? (sozusagen der explorer.exe (nicht der Datei-Manager)

marabu 22. Mai 2005 19:45

Re: Vom Handle zur Position und Größe einer Form
 
Der Explorer macht ganz viele Fenster auf, aber das prominenteste ist wohl der Desktop - meinst du den?

Delphi-Quellcode:
hWnd := GetDesktopWindow;
Grüße vom marabu


Alle Zeitangaben in WEZ +1. Es ist jetzt 16:50 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