therms

Get per-monitor DPI scaling factor

4 posts in this topic

#1 ·  Posted

I need to get the scaling factor for each monitor in a multi-monitor setup on Windows 10.  As far as I can find no one has posted anything like that here.

I think this is probably what I need: https://msdn.microsoft.com/en-us/library/windows/desktop/dn280510(v=vs.85).aspx

I'm just not a windows programmer and I haven't quite figured out how to use DLLCall to get the info from that function.

Any pointers or help?

Share this post


Link to post
Share on other sites



#2 ·  Posted

Share this post


Link to post
Share on other sites

#3 ·  Posted

#include <WinAPIGdi.au3>

; enum _PROCESS_DPI_AWARENESS
Global Const $PROCESS_DPI_UNAWARE = 0
Global Const $PROCESS_SYSTEM_DPI_AWARE = 1
Global Const $PROCESS_PER_MONITOR_DPI_AWARE = 2

; enum _MONITOR_DPI_TYPE
Global Const $MDT_EFFECTIVE_DPI = 0
Global Const $MDT_ANGULAR_DPI = 1
Global Const $MDT_RAW_DPI = 2
Global Const $MDT_DEFAULT = $MDT_EFFECTIVE_DPI

_WinAPI_SetProcessDpiAwareness($PROCESS_PER_MONITOR_DPI_AWARE)

$aMonitors = _WinAPI_EnumDisplayMonitors()
If Not IsArray($aMonitors) Then Exit MsgBox(0, "", "EnumDisplayMonitors error")

For $i = 1 To $aMonitors[0][0]
  $aDPI = _WinAPI_GetDpiForMonitor($aMonitors[$i][0], $MDT_DEFAULT)
  $_ = IsArray($aDPI) ? MsgBox(0, "", $aDPI[0] & ":" & $aDPI[1]) : MsgBox(0, "", "error")
Next

Func _WinAPI_SetProcessDpiAwareness($DPIAware)
  DllCall("Shcore.dll", "long", "SetProcessDpiAwareness", "int", $DPIAware)
  If @error Then Return SetError(1, 0, 0)
EndFunc

Func _WinAPI_GetDpiForMonitor($hMonitor, $dpiType)
  Local $X, $Y
  $aRet = DllCall("Shcore.dll", "long", "GetDpiForMonitor", "long", $hMonitor, "int", $dpiType, "uint*", $X, "uint*", $Y)
  If @error Or Not IsArray($aRet) Then Return SetError(1, 0, 0)
  Local $aDPI[2] = [$aRet[3],$aRet[4]]
  Return $aDPI
EndFunc

 

1 person likes this

Share this post


Link to post
Share on other sites

#4 ·  Posted

@InnI That's perfect, and that even helps me understand DllCall, so I really appreciate it a lot!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now