Jump to content

Recommended Posts

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

 

  • 3 years later...
Posted

Nice solution @InnI .

Here is my little refactored example:

#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)

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

    Local $aDPI, $_fake
    For $i = 1 To $aMonitors[0][0]
        $aDPI = _WinAPI_GetDpiForMonitor($aMonitors[$i][0], $MDT_DEFAULT)
        $_fake = IsArray($aDPI) ? MsgBox(0, "Monitor #" & $i, $aDPI[0] & ":" & $aDPI[1]) : MsgBox(0, "Monitor #" & $i, "error")
    Next
    #forceref $_fake
EndFunc   ;==>_Example

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

Func _WinAPI_GetDpiForMonitor($hMonitor, $dpiType)
    Local $X, $Y
    Local $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   ;==>_WinAPI_GetDpiForMonitor

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...