@@ -122,8 +122,6 @@ public Win32Host(Func<Application> appBuilder)
122122
123123 protected override void Initialize ( )
124124 {
125- SetProcessDpiAwareness ( ) ;
126-
127125 CoreDispatcher . DispatchOverride = Win32EventLoop . Schedule ;
128126 CoreDispatcher . HasThreadAccessOverride = ( ) => _isDispatcherThread ;
129127
@@ -132,42 +130,6 @@ protected override void Initialize()
132130 CompositionTargetTimer . Start ( ) ;
133131 }
134132
135- private void SetProcessDpiAwareness ( )
136- {
137- // This call ensures that the application is properly marked as per-monitor DPI aware (PerMonitorV2).
138- // When launched via `dotnet.exe` (e.g., `dotnet MyApp.dll` or `dotnet run`), the host process is the .NET CLI runtime,
139- // which does NOT contain a DPI-awareness declaration in its embedded application manifest (RT_MANIFEST).
140- // Consequently, Windows assumes the process is DPI-unaware, applies bitmap scaling, and reports a logical DPI of 96,
141- // leading to incorrect pointer coordinates, layout glitches, and drag-and-drop offsets.
142- //
143- // In contrast, when launching a native application executable (e.g., `MyApp.exe`), the process inherits the
144- // DPI-awareness setting defined in the manifest block:
145- //
146- // <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
147- // <asmv3:application>
148- // <asmv3:windowsSettings>
149- // <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
150- // </asmv3:windowsSettings>
151- // </asmv3:application>
152- // </assembly>
153- //
154- // Important: Calling SetThreadDpiAwarenessContext() affects only the DPI behavior of user32/GDI calls **on that thread**,
155- // but it does NOT update the global DPI-awareness context of the process, nor does it affect how the OS scales
156- // the window or reports DPI-related metrics to frameworks like Skia or WinUI. To enable proper DPI scaling and
157- // accurate coordinate transformation, the process DPI-awareness must be set at launch or via SetProcessDpiAwarenessContext().
158- //
159- // NOTE: DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 (-4) provides the most accurate and modern DPI behavior available
160- // on Windows 10+ with improved scaling, child-window consistency, and multi-monitor support.
161- //
162- // More details on DPI Awareness contexts and behaviors:
163- // - https://learn.microsoft.com/en-us/windows/win32/hidpi/setting-the-default-dpi-awareness-for-a-process
164- //
165- // This call must be made BEFORE any window is initialized.
166-
167- var success = PInvoke . SetProcessDpiAwarenessContext ( DPI_AWARENESS_CONTEXT . DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 ) != 0 ;
168- if ( ! success ) { this . LogError ( ) ? . Error ( $ "{ nameof ( PInvoke . SetProcessDpiAwarenessContext ) } failed: { Win32Helper . GetErrorMessage ( ) } ") ; }
169- }
170-
171133 protected override Task RunLoop ( )
172134 {
173135 Win32EventLoop . Schedule ( ( ) => Application . Start ( _ =>
0 commit comments