@@ -90,6 +90,10 @@ public partial class MainWindow : Window
9090 private const uint WM_MOUSEMOVE = 0x0200 ;
9191 private const uint WM_SYSCOMMAND = 0x0112 ;
9292 private const uint WM_SETTINGCHANGE = 0x001A ;
93+ private const uint WM_SIZE = 0x0005 ;
94+ private const uint WM_SHOWWINDOW = 0x0018 ;
95+ private const nint SIZE_RESTORED = 0 ;
96+ private const nint SIZE_MAXIMIZED = 2 ;
9397 private const uint WM_DWMCOLORIZATIONCOLORCHANGED = 0x0320 ;
9498 private const nint SC_MAXIMIZE = 0xF030 ;
9599 private const nint SC_RESTORE = 0xF120 ;
@@ -112,6 +116,7 @@ public partial class MainWindow : Window
112116 // accent-colored window border that tracks focus.
113117 private const int DWMWA_WINDOW_CORNER_PREFERENCE = 33 ;
114118 private const int DWMWA_BORDER_COLOR = 34 ;
119+ private const int DWMWCP_DONOTROUND = 1 ;
115120 private const int DWMWCP_ROUND = 2 ;
116121 private const int WINDOW_BORDER_COLOR_LIGHT = 0x00B9B9B9 ;
117122 private const int WINDOW_BORDER_COLOR_DARK = 0x004A4A4A ;
@@ -218,6 +223,7 @@ protected override void OnOpened(EventArgs e)
218223 }
219224
220225 SetupMicaAndAccentBorder ( ) ;
226+ UpdateWindowCornerPreference ( ) ;
221227
222228 ActualThemeVariantChanged += ( _ , _ ) =>
223229 {
@@ -1042,17 +1048,25 @@ private void SetupMicaAndAccentBorder()
10421048 return ;
10431049 }
10441050
1045- // The custom NCCALCSIZE frame keeps WS_THICKFRAME, so DWM still has a frame to round.
1046- int corner = DWMWCP_ROUND ;
1047- NativeMethods . DwmSetWindowAttribute ( handle , DWMWA_WINDOW_CORNER_PREFERENCE , ref corner , sizeof ( int ) ) ;
1048-
10491051 // Transparent window + transparent MicaPageBackground (from Styles.WindowsMica) let
10501052 // the backdrop show through the chrome and page area.
10511053 Background = Brushes . Transparent ;
10521054
10531055 ApplyWindowBorderColor ( handle ) ;
10541056 }
10551057
1058+ private void UpdateWindowCornerPreference ( )
1059+ {
1060+ if ( ! OperatingSystem . IsWindowsVersionAtLeast ( 10 , 0 , 22000 ) )
1061+ return ;
1062+
1063+ if ( TryGetPlatformHandle ( ) ? . Handle is not { } handle || handle == 0 )
1064+ return ;
1065+
1066+ int corner = WindowState == WindowState . Normal ? DWMWCP_ROUND : DWMWCP_DONOTROUND ;
1067+ NativeMethods . DwmSetWindowAttribute ( handle , DWMWA_WINDOW_CORNER_PREFERENCE , ref corner , sizeof ( int ) ) ;
1068+ }
1069+
10561070 private void ApplyWindowBorderColor ( nint handle )
10571071 {
10581072 int color ;
@@ -1093,6 +1107,12 @@ private static nint OnWindowsWndProc(nint hWnd, uint msg, nint wParam, nint lPar
10931107 borderOwner . ApplyWindowBorderColor ( hWnd ) ;
10941108 }
10951109
1110+ if ( ( msg == WM_SHOWWINDOW || ( msg == WM_SIZE && ( wParam == SIZE_RESTORED || wParam == SIZE_MAXIMIZED ) ) )
1111+ && Instance is { } cornerOwner )
1112+ {
1113+ Dispatcher . UIThread . Post ( cornerOwner . UpdateWindowCornerPreference ) ;
1114+ }
1115+
10961116 if ( msg == WM_SETTINGCHANGE && Instance is { } trayOwner )
10971117 {
10981118 trayOwner . UpdateSystemTrayStatus ( ) ;
0 commit comments