@@ -36,7 +36,9 @@ public partial class MainWindow : FluentWindow
3636 {
3737
3838
39-
39+ [ SecurityCritical ]
40+ [ DllImport ( "dwmapi.dll" , SetLastError = false , ExactSpelling = true ) ]
41+ public static extern int DwmSetWindowAttribute ( IntPtr hwnd , uint dwAttribute , IntPtr pvAttribute , int cbAttribute ) ;
4042
4143 [ DllImport ( "user32.dll" , SetLastError = true ) ]
4244 private static extern int GetWindowLong ( IntPtr hWnd , int nIndex ) ;
@@ -1469,33 +1471,27 @@ private async void ChangeBackground_Click(object sender, RoutedEventArgs e)
14691471
14701472
14711473
1472- [ SecurityCritical ]
1473- [ DllImport ( "dwmapi.dll" , SetLastError = false , ExactSpelling = true ) ]
1474- public static extern int DwmSetWindowAttribute ( IntPtr hwnd , uint dwAttribute , IntPtr pvAttribute , int cbAttribute ) ;
14751474
14761475
14771476
14781477 private void fluentWindow_Loaded ( object sender , RoutedEventArgs e )
14791478 {
1480- var hwnd = new WindowInteropHelper ( this ) . Handle ;
1481- var attribute = GCHandle . Alloc ( ( uint ) 4 , GCHandleType . Pinned ) ;
1482- var result = DwmSetWindowAttribute ( hwnd , ( uint ) 33 , attribute . AddrOfPinnedObject ( ) , sizeof ( uint ) ) ;
1483- attribute . Free ( ) ;
1484- if ( result != 0 )
1479+ if ( FileVersionInfo . GetVersionInfo ( "C:\\ Windows\\ System32\\ kernel32.dll" ) . FileBuildPart >= 22000 ) // Makes sure it doesn't change on Windows 10 as it crashes the program
14851480 {
1486- throw Marshal . GetExceptionForHR ( result ) ;
1481+ var hwnd = new WindowInteropHelper ( this ) . Handle ;
1482+ var attribute = GCHandle . Alloc ( ( uint ) 4 , GCHandleType . Pinned ) ;
1483+ var result = DwmSetWindowAttribute ( hwnd , ( uint ) 33 , attribute . AddrOfPinnedObject ( ) , sizeof ( uint ) ) ;
1484+ attribute . Free ( ) ;
1485+ if ( result != 0 )
1486+ {
1487+ Debug . WriteLine ( "Couldn't change DWM" ) ;
1488+ }
14871489 }
1488-
14891490 }
14901491
14911492
14921493
14931494
1494-
1495-
1496-
1497-
1498-
14991495 private void SelectOtherInstnaceBTN_Click ( object sender , RoutedEventArgs e )
15001496 {
15011497 OtherInstanceContextMenu . Items . Clear ( ) ;
0 commit comments