How to check whether a GUI used DPIScale ?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jly
Posts: 89
Joined: 30 Sep 2020, 06:06

How to check whether a GUI used DPIScale ?

Post by jly » 02 Dec 2022, 09:33

How to check whether a GUI used DPIScale ?

User avatar
mikeyww
Posts: 26595
Joined: 09 Sep 2014, 18:38

Re: How to check whether a GUI used DPIScale ?

Post by mikeyww » 02 Dec 2022, 09:59

Since you control the script, you know what's in it.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: How to check whether a GUI used DPIScale ?

Post by swagfag » 02 Dec 2022, 13:37

Code: Select all

processID := ???

if !hProcess := DllCall("OpenProcess", "UInt", PROCESS_QUERY_INFORMATION := 0x0400, "Int", false, "UInt", processID, "Ptr")
	throw

if !DllCall("shcore\GetProcessDpiAwareness", "Ptr", hProcess, "Int*", value)
	throw

DllCall("CloseHandle", "Ptr", hProcess)

switch value
{
case 0: MsgBox PROCESS_DPI_UNAWARE`nValue: 0`nDPI unaware. This app does not scale for DPI changes and is always assumed to have a scale factor of 100% (96 DPI). It will be automatically scaled by the system on any other DPI setting.
case 1: MsgBox PROCESS_SYSTEM_DPI_AWARE`nValue: 1`nSystem DPI aware. This app does not scale for DPI changes. It will query for the DPI once and use that value for the lifetime of the app. If the DPI changes, the app will not adjust to the new DPI value. It will be automatically scaled up or down by the system when the DPI changes from the system value.
case 2: MsgBox PROCESS_PER_MONITOR_DPI_AWARE`nValue: 2`nPer monitor DPI aware. This app checks for the DPI when it is created and adjusts the scale factor whenever the DPI changes. These applications are not automatically scaled by the system.
}

jly
Posts: 89
Joined: 30 Sep 2020, 06:06

Re: How to check whether a GUI used DPIScale ?

Post by jly » 02 Dec 2022, 21:38

swagfag wrote:
02 Dec 2022, 13:37

Code: Select all

processID := ???

if !hProcess := DllCall("OpenProcess", "UInt", PROCESS_QUERY_INFORMATION := 0x0400, "Int", false, "UInt", processID, "Ptr")
	throw

if !DllCall("shcore\GetProcessDpiAwareness", "Ptr", hProcess, "Int*", value)
	throw

DllCall("CloseHandle", "Ptr", hProcess)

switch value
{
case 0: MsgBox PROCESS_DPI_UNAWARE`nValue: 0`nDPI unaware. This app does not scale for DPI changes and is always assumed to have a scale factor of 100% (96 DPI). It will be automatically scaled by the system on any other DPI setting.
case 1: MsgBox PROCESS_SYSTEM_DPI_AWARE`nValue: 1`nSystem DPI aware. This app does not scale for DPI changes. It will query for the DPI once and use that value for the lifetime of the app. If the DPI changes, the app will not adjust to the new DPI value. It will be automatically scaled up or down by the system when the DPI changes from the system value.
case 2: MsgBox PROCESS_PER_MONITOR_DPI_AWARE`nValue: 2`nPer monitor DPI aware. This app checks for the DPI when it is created and adjusts the scale factor whenever the DPI changes. These applications are not automatically scaled by the system.
}
mikeyww wrote:
02 Dec 2022, 09:59
Since you control the script, you know what's in it.
Thank you both for the suggestions .

I searched MSDN,
the return code is S_OK(0), if "GetProcessDpiAwareness" successfully retrieved the DPI awareness of the specified process.

Code: Select all


gui,+hwndhg1  -DPIScale
gui,Margin,30,20
gui,Color,white
gui,add,Text,% "xm w150 "  " hwndhT_"1  , % " hello world "1
gui,add,Edit,% "xm w150 " " vE"1   " hwndhE"1 " r1 +Multi  "  , % " hello world 1"
gui,show,AutoSize

;processID := ""
;WinGet processID, PID, ahk_id %hg1%
processID := DllCall("GetCurrentProcessId")    ;Same to  "WinGet"



if !hProcess := DllCall("OpenProcess", "UInt", PROCESS_QUERY_INFORMATION := 0x0400, "Int", false, "UInt", processID, "Ptr")
	throw


;S_OK              0x00000000  The function successfully retrieved the DPI awareness of the specified process.
;E_INVALIDARG      0x80070057  The handle or pointer passed in is not valid.
;E_ACCESSDENIED    0x80070005  The application does not have sufficient privileges.
;if !DllCall("shcore\GetProcessDpiAwareness", "Ptr", hProcess, "Int*", value)   ;S_OK : 0
ret := DllCall("shcore\GetProcessDpiAwareness", "Ptr", hProcess, "Int*", value)
DllCall("CloseHandle", "Ptr", hProcess)

if(ret=0){             ;S_OK := 0
	switch value
	{
	case 0: MsgBox PROCESS_DPI_UNAWARE`nValue: 0`nDPI unaware. This app does not scale for DPI changes and is always assumed to have a scale factor of 100`% (96 DPI). It will be automatically scaled by the system on any other DPI setting.
	case 1: MsgBox PROCESS_SYSTEM_DPI_AWARE`nValue: 1`nSystem DPI aware. This app does not scale for DPI changes. It will query for the DPI once and use that value for the lifetime of the app. If the DPI changes, the app will not adjust to the new DPI value. It will be automatically scaled up or down by the system when the DPI changes from the system value.
	case 2: MsgBox PROCESS_PER_MONITOR_DPI_AWARE`nValue: 2`nPer monitor DPI aware. This app checks for the DPI when it is created and adjusts the scale factor whenever the DPI changes. These applications are not automatically scaled by the system.
	}
}
Return

GuiClose:
ExitApp


esc::ExitApp


User avatar
mikeyww
Posts: 26595
Joined: 09 Sep 2014, 18:38

Re: How to check whether a GUI used DPIScale ?

Post by mikeyww » 02 Dec 2022, 21:59

Here's mine.

Code: Select all

Gui, % dpi := "-DPIScale"
Gui, Font, s10
Gui, Add, Text,, DPI:
Gui, Font, w700 cBlue
Gui, Add, Text, x+m w200, %dpi%
Gui, Show,, DPI
8-)

Post Reply

Return to “Ask for Help (v1)”