Gui Object GetPos method returns wrong values Topic is solved

Report problems with documented functionality
SAbboushi
Posts: 252
Joined: 08 Dec 2014, 22:13

Gui Object GetPos method returns wrong values

18 Jan 2024, 00:46

Updating my code from v2.0-a122 to v2.0.11.

I’m finding that GuiGetPos() is returning incorrect values in v2.0.11 (and correct values in v2.0-a122).

======
v2.0.11
======

Code: Select all

/*
  v2.0.11
*/
; DPIScaleEnabled =======================================================================================

MyGui_DPIScaleEnabled := Gui( Options := "+AlwaysOnTop +Owner", Title := "DPIScaleEnabled")
MyGui_DPIScaleEnabled.Show("x50 y50 w400 h150") ; W and H are client area (the client area excludes the window's borders, title bar, and menu bar).

MyGui_DPIScaleEnabled.Add("Text",, "A_AhkVersion:       " A_AhkVersion)
MyGui_DPIScaleEnabled.Add("Text",, "A_ScreenDPI:        " A_ScreenDPI)



MyGui_DPIScaleEnabled.GetPos(       ; Per Documentation: applies DPI scaling to Width and Height (unless the -DPIScale option was used).
    &X_DPIScaleEnabled      := "",   
    &Y_DPIScaleEnabled      := "",  
    &Width_DPIScaleEnabled  := "",  
    &Height_DPIScaleEnabled := ""   
)

MyGui_DPIScaleEnabled.Add("Text",, "GetPos():        X" X_DPIScaleEnabled " Y" Y_DPIScaleEnabled " W" Width_DPIScaleEnabled " H" Height_DPIScaleEnabled)


WinGetPos(
    &OutX_DPIScaleEnabled      := "",
    &OutY_DPIScaleEnabled      := "",
    &OutWidth_DPIScaleEnabled  := "",
    &OutHeight_DPIScaleEnabled := "",
    WinTitle := MyGui_DPIScaleEnabled
)

MyGui_DPIScaleEnabled.Add("Text",, "WinGetPos(): X" OutX_DPIScaleEnabled " Y" OutY_DPIScaleEnabled " W" OutWidth_DPIScaleEnabled " H" OutHeight_DPIScaleEnabled)



; DPIScaleDisabled =======================================================================================

MyGui_DPIScaleDisabled := Gui( Options := "+AlwaysOnTop +Owner -DPIScale", Title := "DPIScaleDisabled")
MyGui_DPIScaleDisabled.Show("x850 y50 w400 h150")

MyGui_DPIScaleDisabled.Add("Text",, "A_AhkVersion:       " A_AhkVersion)
MyGui_DPIScaleDisabled.Add("Text",, "A_ScreenDPI:        " A_ScreenDPI)

MyGui_DPIScaleDisabled.GetPos(       ; Per Documentation: applies DPI scaling to Width and Height (unless the -DPIScale option was used).
    &X_DPIScaleDisabled      := "",  
    &Y_DPIScaleDisabled      := "",  
    &Width_DPIScaleDisabled  := "",  
    &Height_DPIScaleDisabled := ""   
)

MyGui_DPIScaleDisabled.Add("Text",, "GetPos():        X" X_DPIScaleDisabled " Y" Y_DPIScaleDisabled " W" Width_DPIScaleDisabled " H" Height_DPIScaleDisabled)

hwnd2 := MyGui_DPIScaleDisabled.Hwnd

WinGetPos(
    &OutX_DPIScaleDisabled      := "",
    &OutY_DPIScaleDisabled      := "",
    &OutWidth_DPIScaleDisabled  := "",
    &OutHeight_DPIScaleDisabled := "",
    WinTitle := MyGui_DPIScaleDisabled
)

MyGui_DPIScaleDisabled.Add("Text",, "WinGetPos(): X" OutX_DPIScaleDisabled " Y" OutY_DPIScaleDisabled " W" OutWidth_DPIScaleDisabled " H" OutHeight_DPIScaleDisabled)

pause
Primary display Scale at 100% and 150%:
v2.0.11.png
v2.0.11.png (158.18 KiB) Viewed 436 times



========
v2.0-a122
========

Code: Select all

/*
  v2.0-a122
*/
; DPIScaleEnabled =======================================================================================

MyGui_DPIScaleEnabled := Gui.New( Options := "+AlwaysOnTop +Owner", Title := "DPIScaleEnabled")
MyGui_DPIScaleEnabled.Show("x50 y50 w400 h150") ; W and H are client area (the client area excludes the window's borders, title bar, and menu bar).

MyGui_DPIScaleEnabled.Add("Text",, "A_AhkVersion:       " A_AhkVersion)
MyGui_DPIScaleEnabled.Add("Text",, "A_ScreenDPI:        " A_ScreenDPI)


MyGui_DPIScaleEnabled.GetPos(       ; Per Documentation: applies DPI scaling to Width and Height (unless the -DPIScale option was used).
    X_DPIScaleEnabled      := "",   
    Y_DPIScaleEnabled      := "",  
    Width_DPIScaleEnabled  := "",  
    Height_DPIScaleEnabled := ""   
)

MyGui_DPIScaleEnabled.Add("Text",, "GetPos():        X" X_DPIScaleEnabled " Y" Y_DPIScaleEnabled " W" Width_DPIScaleEnabled " H" Height_DPIScaleEnabled)


WinGetPos(
    OutX_DPIScaleEnabled      := "",
    OutY_DPIScaleEnabled      := "",
    OutWidth_DPIScaleEnabled  := "",
    OutHeight_DPIScaleEnabled := "",
    WinTitle := MyGui_DPIScaleEnabled
)

MyGui_DPIScaleEnabled.Add("Text",, "WinGetPos(): X" OutX_DPIScaleEnabled " Y" OutY_DPIScaleEnabled " W" OutWidth_DPIScaleEnabled " H" OutHeight_DPIScaleEnabled)



; DPIScaleDisabled =======================================================================================

MyGui_DPIScaleDisabled := Gui.New( Options := "+AlwaysOnTop +Owner -DPIScale", Title := "DPIScaleDisabled")
MyGui_DPIScaleDisabled.Show("x850 y50 w400 h150")

MyGui_DPIScaleDisabled.Add("Text",, "A_AhkVersion:       " A_AhkVersion)
MyGui_DPIScaleDisabled.Add("Text",, "A_ScreenDPI:        " A_ScreenDPI)

MyGui_DPIScaleDisabled.GetPos(       ; Per Documentation: applies DPI scaling to Width and Height (unless the -DPIScale option was used).
    X_DPIScaleDisabled      := "",  
    Y_DPIScaleDisabled      := "",  
    Width_DPIScaleDisabled  := "",  
    Height_DPIScaleDisabled := ""   
)

MyGui_DPIScaleDisabled.Add("Text",, "GetPos():        X" X_DPIScaleDisabled " Y" Y_DPIScaleDisabled " W" Width_DPIScaleDisabled " H" Height_DPIScaleDisabled)

hwnd2 := MyGui_DPIScaleDisabled.Hwnd

WinGetPos(
    OutX_DPIScaleDisabled      := "",
    OutY_DPIScaleDisabled      := "",
    OutWidth_DPIScaleDisabled  := "",
    OutHeight_DPIScaleDisabled := "",
    WinTitle := MyGui_DPIScaleDisabled
)

MyGui_DPIScaleDisabled.Add("Text",, "WinGetPos(): X" OutX_DPIScaleDisabled " Y" OutY_DPIScaleDisabled " W" OutWidth_DPIScaleDisabled " H" OutHeight_DPIScaleDisabled)

pause
Primary display Scale at 100% and 150%:
v2-a122.png
v2-a122.png (165.64 KiB) Viewed 436 times
SAbboushi
Posts: 252
Joined: 08 Dec 2014, 22:13

Re: Gui Object GetPos method returns wrong values

18 Jan 2024, 10:48

(updated Subject Title to remove "when -DPIScale option used": GetPos() values are incorrect regardless of whether DPI scaling is enabled or not)
lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: Gui Object GetPos method returns wrong values

19 Jan 2024, 05:35

This happens when the GUI has an owner window, which the method incorrectly assumes is a parent window.

DPI scaling is also erroneously applied to the X and Y coordinates.

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 7 guests