A_GuiWidth and A_GuiHeight

Share your ideas as to how the documentation can be improved.
iPhilip
Posts: 832
Joined: 02 Oct 2013, 12:21

A_GuiWidth and A_GuiHeight

30 May 2022, 13:12

Three is an inconsistency in the documentation for the built-in variables A_GuiWidth and A_GuiHeight.
https://www.autohotkey.com/docs/Variables.htm#GuiWidth wrote:These values are affected by DPI scaling.
should be (my emphasis)
https://www.autohotkey.com/docs/Variables.htm#GuiWidth wrote:These values are not affected by DPI scaling.
To support this change, the documentation for DPIScale states:
https://www.autohotkey.com/docs/commands/Gui.htm#DPIScale wrote:For example, with a DPI of 144 (150%), Gui Show, w100 would make the Gui 150 pixels wide, but A_GuiWidth would still return 100.
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)
User avatar
boiler
Posts: 17328
Joined: 21 Dec 2014, 02:44

Re: A_GuiWidth and A_GuiHeight

30 May 2022, 18:16

The way I read it (and apparently the author did as well), they are affected by DPI scaling. If they weren’t, in the example where the GUI is actually 150 pixels wide, it would be reported as 150 pixels wide. But instead, it reports the size as 100 because it applies the DPI scaling factor (by multiplying the actual size by the inverse of the DPI scaling factor).
iPhilip
Posts: 832
Joined: 02 Oct 2013, 12:21

Re: A_GuiWidth and A_GuiHeight

31 May 2022, 19:54

@boiler, Thank you for the feedback. I would argue that, if a variable y is affected by another variable x, then when x changes y changes as well. As written, the documentation implies that the values of A_GuiWidth and A_GuiHeight change with changes in the DPI scaling factor. That's not my observation. My understanding is that the actual size of the Gui client area is affected by the DPI scaling factor but that A_GuiWidth and A_GuiHeight, because they are normalized variables (by dividing by the DPI scaling factor), are not. I would agree that the DPI scaling factor is used in the calculation of A_GuiWidth and A_GuiHeight but doesn't mean that the value of those variables are affected by it.

Below is a script to test this point.

Code: Select all

#NoEnv

DPIScaling := true
Gui, % (DPIScaling ? "" : "-DPIScale ") "+Resize +LastFound"
Gui Show, w500 h500
GetClientRect(WinExist(), W, H)
return

GuiSize:
   MsgBox % (DPIScaling ? "Screen DPI: " A_ScreenDPI : "DPI scaling disabled.") "`nActual size of client area: " W " x " H "`nNormalized size of client area: " A_GuiWidth " x " A_GuiHeight
return

Esc::
GuiClose:
GuiEscape:
   ExitApp

GetClientRect(hwnd, ByRef W, ByRef H) {
   VarSetCapacity(RECT, 16)
   if DllCall("GetClientRect", "Ptr", hwnd, "Ptr", &RECT, "Int")
      W := NumGet(RECT, 8, "Int"), H := NumGet(RECT, 12, "Int")
}
Here are results of several tests:

Code: Select all

             |            -DPIScale                     |            +DPIScale
-------------------------------------------------------------------------------------------------
A_ScreenDPI  |  Width  Height  A_GuiWidth  A_GuiHeight  |  Width  Height  A_GuiWidth  A_GuiHeight
-------------------------------------------------------------------------------------------------
 96 (100%)   |   500    500        500         500      |   500    500        500         500
168 (175%)   |   500    500        500         500      |   875    875        500         500
192 (200%)   |   500    500        500         500      |  1000   1000        500         500
288 (300%)   |   500    500        500         500      |  1500   1500        500         500
As can be seen from the above numbers, the values of A_GuiWidth and A_GuiHeight are invariant with the DPI scaling factor.

EDIT: Corrected miscalculation. Thank you @boiler.
Last edited by iPhilip on 31 May 2022, 21:39, edited 1 time in total.
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)
User avatar
boiler
Posts: 17328
Joined: 21 Dec 2014, 02:44

Re: A_GuiWidth and A_GuiHeight

31 May 2022, 21:23

iPhilip wrote: As can be seen from the above numbers, the values of A_GuiWidth and A_GuiHeight are invariant with the DPI scaling factor.
I suppose we should just agree to disagree. If it weren’t affected by DPI scale, it would report the actual size of the window, but instead it is reporting the actual size of the window multiplied by 96 divided by A_ScreenDPI. The fact that the calculation includes dividing by A_ScreenDPI is another way of saying that they “are affected by DPI scaling.” Again, if they weren’t affected, they would report the actual size of the window.

What may be confusing is that the size of the window without DPI scaling would be 500 x 500. But the window is not 500 x 500. It is 875 x 875, or 1000 x 1000, etc. And those are not the sizes the variables contain because they are affected by DPI scaling.

By the way, 168 isn’t 150% of 96, it’s 175%. 144 is 150% of 96.
iPhilip
Posts: 832
Joined: 02 Oct 2013, 12:21

Re: A_GuiWidth and A_GuiHeight

31 May 2022, 21:54

I think we can all agree that, when DPI scaling is enabled (by default),

Code: Select all

A_GuiWidth  := Actual_Width_of_Client_Area  * 96 / A_ScreenDPI
A_GuiHeight := Actual_Height_of_Client_Area * 96 / A_ScreenDPI
As to whether A_GuiWidth and A_GuiHeight are affected by the DPI Scaling factor, I will let the above results stand on their own. I hope it helps clarify any confusion.
boiler wrote:
31 May 2022, 21:23
By the way, 168 isn’t 150% of 96, it’s 175%. 144 is 150% of 96.
Thank you for catching that. I corrected the post.
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)
User avatar
boiler
Posts: 17328
Joined: 21 Dec 2014, 02:44

Re: A_GuiWidth and A_GuiHeight

31 May 2022, 22:03

iPhilip wrote: I think we can all agree that, when DPI scaling is enabled (by default),

Code: Select all

A_GuiWidth  := Actual_Width_of_Client_Area  * 96 / A_ScreenDPI
A_GuiHeight := Actual_Height_of_Client_Area * 96 / A_ScreenDPI
As to whether A_GuiWidth and A_GuiHeight are affected by the DPI Scaling factor, I will let the above results stand on their own. I hope it helps clarify any confusion.
Yes, that makes it very clear that “These values are affected by DPI scaling” since A_ScreenDPI is used to arrive at their values.

Return to “Suggestions on Documentation Improvements”

Who is online

Users browsing this forum: No registered users and 5 guests