Actually the constants are:
#DPI_AWARENESS_CONTEXT_UNAWARE = $6010 ;24592
#DPI_AWARENESS_CONTEXT_SYSTEM_AWARE = $7811 ;30737 ;$9011 ;36881
#DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE = $12 ;18
#DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 = $22 ;34
#DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED = $40006010 ;1073766416
(it's not a simple integer value, but a pointer to a static structure or whatever... I double checked by comparing with results from GetWindowDpiAwarenessContext() and you can also check with task manager after setting it in code (tab details, add column DPI Awareness).
Code: Select all
#define DECLARE_HANDLE(name) struct name##__{int unused;}; typedef struct name##__ *name
#define _DPI_AWARENESS_CONTEXTS_
DECLARE_HANDLE(DPI_AWARENESS_CONTEXT);
typedef enum DPI_AWARENESS {
DPI_AWARENESS_INVALID = -1,
DPI_AWARENESS_UNAWARE = 0,
DPI_AWARENESS_SYSTEM_AWARE = 1,
DPI_AWARENESS_PER_MONITOR_AWARE = 2
} DPI_AWARENESS;
#define DPI_AWARENESS_CONTEXT_UNAWARE ((DPI_AWARENESS_CONTEXT)-1)
#define DPI_AWARENESS_CONTEXT_SYSTEM_AWARE ((DPI_AWARENESS_CONTEXT)-2)
#define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE ((DPI_AWARENESS_CONTEXT)-3)
#define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 ((DPI_AWARENESS_CONTEXT)-4)
#define DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED ((DPI_AWARENESS_CONTEXT)-5)
Not that it helps much, you have to do the scaling all yourself then and disable DPI aware in compiler settings. Hence the bug report (technically feature implementation request)...
Code: Select all
EnableExplicit
Global _User32 = OpenLibrary(#PB_Any, "User32.dll")
If _User32
#DPI_AWARENESS_CONTEXT_UNAWARE = $6010 ;24592
#DPI_AWARENESS_CONTEXT_SYSTEM_AWARE = $9011 ;36881
#DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE = $12 ;18
#DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 = $22 ;34
#DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED = $40006010 ;1073766416
Prototype SetProcessDpiAwarenessContext(value)
Prototype GetWindowDpiAwarenessContext(hwnd)
Global SetProcessDpiAwarenessContext_.SetProcessDpiAwarenessContext = GetFunction(_User32, "SetProcessDpiAwarenessContext")
Global GetWindowDpiAwarenessContext_.GetWindowDpiAwarenessContext = GetFunction(_User32, "GetWindowDpiAwarenessContext")
EndIf
SetProcessDpiAwarenessContext_(#DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2)
OpenWindow(0, 0, 0, 400, 300, "Test")
Define dpic = GetWindowDpiAwarenessContext_(WindowID(0))
Debug dpic
Debug #DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2
ButtonGadget(0, 10, 10, 60, 21, "Test")
Define e
Repeat
e = WaitWindowEvent()
Until e = #PB_Event_CloseWindow
;task manager says 'Per-Monitor (v2)'
(it won't do any scaling, just shows that the process dpi awareness is set to DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2, tested on both 32 and 64 bit PB)
Possibly useful to some:
Code: Select all
Procedure GetDPI(hwnd = 0, *p.POINT = 0)
Protected hmon, dpiX = 96, dpiY = 96
If *p
hmon = MonitorFromPoint_(PeekQ(*p), #MONITOR_DEFAULTTONULL)
EndIf
If Not hmon
hmon = MonitorFromWindow_(hwnd, #MONITOR_DEFAULTTOPRIMARY)
EndIf
If hmon
If GetDpiForMonitor_(hmon, #MDT_EFFECTIVE_DPI, @dpiX, @dpiY) = #S_OK
;
EndIf
EndIf
ProcedureReturn dpiX
EndProcedure
Procedure.f GetScale(hwnd = 0, *p.POINT = 0)
ProcedureReturn GetDPI(hwnd, *p) / 96
EndProcedure