@@ -49,7 +49,6 @@ internal class Win32Platform : IWindowingPlatform, IPlatformIconLoader, IPlatfor
49
49
50
50
public Win32Platform ( )
51
51
{
52
- SetDpiAwareness ( ) ;
53
52
CreateMessageWindow ( ) ;
54
53
_dispatcher = new Win32DispatcherImpl ( _hwnd ) ;
55
54
}
@@ -80,6 +79,9 @@ public static void Initialize()
80
79
public static void Initialize ( Win32PlatformOptions options )
81
80
{
82
81
s_options = options ;
82
+
83
+ SetDpiAwareness ( ) ;
84
+
83
85
var renderTimer = options . ShouldRenderOnUIThread ? new UiThreadRenderTimer ( 60 ) : new DefaultRenderTimer ( 60 ) ;
84
86
85
87
AvaloniaLocator . CurrentMutable
@@ -264,12 +266,31 @@ private static void SetDpiAwareness()
264
266
var user32 = LoadLibrary ( "user32.dll" ) ;
265
267
var method = GetProcAddress ( user32 , nameof ( SetProcessDpiAwarenessContext ) ) ;
266
268
269
+ var dpiAwareness = Options . DpiAwareness ;
270
+
267
271
if ( method != IntPtr . Zero )
268
272
{
269
- if ( SetProcessDpiAwarenessContext ( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 ) ||
270
- SetProcessDpiAwarenessContext ( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE ) )
273
+ if ( dpiAwareness == Win32DpiAwareness . Unaware )
271
274
{
272
- return ;
275
+ if ( SetProcessDpiAwarenessContext ( DPI_AWARENESS_CONTEXT_UNAWARE ) )
276
+ {
277
+ return ;
278
+ }
279
+ }
280
+ else if ( dpiAwareness == Win32DpiAwareness . SystemDpiAware )
281
+ {
282
+ if ( SetProcessDpiAwarenessContext ( DPI_AWARENESS_CONTEXT_SYSTEM_AWARE ) )
283
+ {
284
+ return ;
285
+ }
286
+ }
287
+ else if ( dpiAwareness == Win32DpiAwareness . PerMonitorDpiAware )
288
+ {
289
+ if ( SetProcessDpiAwarenessContext ( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 ) ||
290
+ SetProcessDpiAwarenessContext ( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE ) )
291
+ {
292
+ return ;
293
+ }
273
294
}
274
295
}
275
296
@@ -278,11 +299,20 @@ private static void SetDpiAwareness()
278
299
279
300
if ( method != IntPtr . Zero )
280
301
{
281
- SetProcessDpiAwareness ( PROCESS_DPI_AWARENESS . PROCESS_PER_MONITOR_DPI_AWARE ) ;
302
+ var awareness = ( dpiAwareness ) switch
303
+ {
304
+ Win32DpiAwareness . Unaware => PROCESS_DPI_AWARENESS . PROCESS_DPI_UNAWARE ,
305
+ Win32DpiAwareness . SystemDpiAware => PROCESS_DPI_AWARENESS . PROCESS_SYSTEM_DPI_AWARE ,
306
+ Win32DpiAwareness . PerMonitorDpiAware => PROCESS_DPI_AWARENESS . PROCESS_PER_MONITOR_DPI_AWARE ,
307
+ _ => PROCESS_DPI_AWARENESS . PROCESS_PER_MONITOR_DPI_AWARE ,
308
+ } ;
309
+
310
+ SetProcessDpiAwareness ( awareness ) ;
282
311
return ;
283
312
}
284
313
285
- SetProcessDPIAware ( ) ;
314
+ if ( dpiAwareness != Win32DpiAwareness . Unaware )
315
+ SetProcessDPIAware ( ) ;
286
316
}
287
317
}
288
318
}
0 commit comments