How to get the screen position of a GUI without the titlebar?

Get help with using AutoHotkey and its commands and hotkeys
KilliK
Posts: 224
Joined: 10 Mar 2016, 21:19

How to get the screen position of a GUI without the titlebar?

21 Oct 2019, 19:55

Hello.

How do I get the top left coordinates of a GUI without the window's titlebar, relative to the monitor's Screen?

here is what I mean, I use the mouse to point out which coordinates I want:

AHK's Window Spy gives the position X:1115 and Y:627
Image

and here it gives the position X:1115 Y:652
Image

it is this position I want to get with some way. Is there a native variable or command which gives it? or some other way?
User avatar
boiler
Posts: 3315
Joined: 21 Dec 2014, 02:44

Re: How to get the screen position of a GUI without the titlebar?

22 Oct 2019, 00:41

Use SysGet to get the height of the window caption/title bar (SM_CYCAPTION) and the border around the window, which is different depending on whether it is re-sizable (SM_CYSIZEFRAME) or not (SM_CYFIXEDFRAME). You can make your Gui re-sizable if you use the +Resize option in your initial Gui statement. Run the code at the bottom. It should show:

Code: Select all

Caption height: 23
Height of fixed window border: 3
Height of resizable window border: 8
...which is a total of 23+3=26 for your GuiWindow. If you made it resizable, it would be 23+8=31.

Code:

Code: Select all

SysGet, SM_CYCAPTION, 4
SysGet, SM_CYFIXEDFRAME, 8
SysGet, SM_CYSIZEFRAME, 33

MsgBox, % "Caption height: " SM_CYCAPTION "`n"
	. "Height of fixed window border: " SM_CYFIXEDFRAME "`n"
	. "Height of resizable window border: " SM_CYSIZEFRAME
teadrinker
Posts: 1126
Joined: 29 Mar 2015, 09:41
Contact:

Re: How to get the screen position of a GUI without the titlebar?

22 Oct 2019, 02:53

boiler wrote: ...which is a total of 23+3=26 for your GuiWindow. If you made it resizable, it would be 23+8=31.
Such calculation doesn't always give the correct result. To get the coordinates of the client area GetWindowInfo function is used:

Code: Select all

Gui, +hwndhGui
Gui, Show, w300 h200

VarSetCapacity(WINDOWINFO, 60)
NumPut(60, WINDOWINFO)
DllCall("GetWindowInfo", "Ptr", hGui, "Ptr", &WINDOWINFO)
MsgBox, % "ClientX: " . NumGet(WINDOWINFO, 20, "Int") . "`n"
        . "ClientY: " . NumGet(WINDOWINFO, 24, "Int")

Return to “Ask For Help”

Who is online

Users browsing this forum: badnecros, Bing [Bot], flyingDman, fracsh, malcev and 215 guests