11using System . Runtime . InteropServices ;
2- using System . Text ;
32using System . Windows ;
43using System . Windows . Controls ;
5- using System . Windows . Data ;
6- using System . Windows . Documents ;
7- using System . Windows . Input ;
84using System . Windows . Interop ;
95using System . Windows . Media ;
10- using System . Windows . Media . Imaging ;
11- using System . Windows . Navigation ;
12- using System . Windows . Shapes ;
136
14- namespace GameController_Helper ;
7+ namespace Controller2Mouse ;
158
169/// <summary>
1710/// Interaction logic for MainWindow.xaml
@@ -40,12 +33,6 @@ public MainWindow()
4033
4134 if ( Application . Current != null )
4235 {
43- #pragma warning disable WPF0001
44- // 尝试监听主题变化 (如果支持)
45- try {
46- // Application.Current.ActualThemeModeChanged += (s, e) => { UpdateThemeResources(); ApplyThemeToTitleBar(); };
47- } catch { }
48- #pragma warning restore WPF0001
4936 UpdateThemeResources ( ) ;
5037 }
5138
@@ -62,41 +49,47 @@ public MainWindow()
6249 private void MainWindow_SourceInitialized ( object ? sender , EventArgs e )
6350 {
6451 var hwnd = new WindowInteropHelper ( this ) . Handle ;
65-
66- // 启用 Mica
67- int micaValue = DWMSBT_MICA ;
68- DwmSetWindowAttribute ( hwnd , DWMWA_SYSTEMBACKDROP_TYPE , ref micaValue , Marshal . SizeOf ( typeof ( int ) ) ) ;
69-
70- // 标题栏主题
52+
53+ try
54+ {
55+ int micaValue = DWMSBT_MICA ;
56+ DwmSetWindowAttribute ( hwnd , DWMWA_SYSTEMBACKDROP_TYPE , ref micaValue , Marshal . SizeOf ( typeof ( int ) ) ) ;
57+ }
58+ catch ( Exception ex )
59+ {
60+ System . Diagnostics . Debug . WriteLine ( $ "Failed to set Mica backdrop: { ex . Message } ") ;
61+ }
62+
7163 ApplyThemeToTitleBar ( ) ;
7264 }
7365
7466 private void ApplyThemeToTitleBar ( )
7567 {
7668 var hwnd = new WindowInteropHelper ( this ) . Handle ;
77- bool isDark = false ;
78-
79- try {
80- #pragma warning disable WPF0001
81- // 尝试获取实际主题
82- var theme = Application . Current . ThemeMode ;
83- #pragma warning restore WPF0001
84- isDark = IsCurrentlyDarkMode ( ) ;
85- } catch { }
86-
87- int darkValue = isDark ? 1 : 0 ;
88- DwmSetWindowAttribute ( hwnd , DWMWA_USE_IMMERSIVE_DARK_MODE , ref darkValue , Marshal . SizeOf ( typeof ( int ) ) ) ;
69+ bool isDark = IsCurrentlyDarkMode ( ) ;
70+
71+ try
72+ {
73+ int darkValue = isDark ? 1 : 0 ;
74+ DwmSetWindowAttribute ( hwnd , DWMWA_USE_IMMERSIVE_DARK_MODE , ref darkValue , Marshal . SizeOf ( typeof ( int ) ) ) ;
75+ }
76+ catch ( Exception ex )
77+ {
78+ System . Diagnostics . Debug . WriteLine ( $ "Failed to set title bar theme: { ex . Message } ") ;
79+ }
8980 }
9081
91- private bool IsCurrentlyDarkMode ( )
82+ private static bool IsCurrentlyDarkMode ( )
9283 {
93- // 简单的深色模式检测逻辑
9484 try
9585 {
9686 var res = Microsoft . Win32 . Registry . GetValue ( @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize" , "AppsUseLightTheme" , 1 ) ;
9787 if ( res != null && ( int ) res == 0 ) return true ;
9888 }
99- catch { }
89+ catch ( Exception ex )
90+ {
91+ System . Diagnostics . Debug . WriteLine ( $ "Failed to detect dark mode: { ex . Message } ") ;
92+ }
10093 return false ;
10194 }
10295
@@ -178,7 +171,10 @@ private void SetLanguage(string cultureCode)
178171 }
179172 }
180173 }
181- catch { }
174+ catch ( Exception ex )
175+ {
176+ System . Diagnostics . Debug . WriteLine ( $ "Failed to set language: { ex . Message } ") ;
177+ }
182178 }
183179
184180 private void LanguageComboBox_SelectionChanged ( object sender , SelectionChangedEventArgs e )
0 commit comments