22using System . Runtime . InteropServices ;
33using System . Runtime . Versioning ;
44
5- namespace LogExpert . Core . Classes
5+ namespace LogExpert . UI . Extensions
66{
77 [ SupportedOSPlatform ( "windows" ) ]
8- public static class Win32
8+ internal static class Win32
99 {
1010 #region Fields
1111
@@ -115,6 +115,34 @@ private static extern uint ExtractIconEx(string fileName,
115115 uint numIcons
116116 ) ;
117117
118+ #region TitleBarDarkMode
119+ [ DllImport ( "dwmapi.dll" ) ]
120+ private static extern int DwmSetWindowAttribute ( nint hwnd , int attr , ref int attrValue , int attrSize ) ;
121+
122+ private const int DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1 = 19 ;
123+ private const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20 ;
124+
125+ public static bool UseImmersiveDarkMode ( nint handle , bool enabled )
126+ {
127+
128+ var attribute = DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1 ;
129+ if ( IsWindows10OrGreater ( 18985 ) )
130+ {
131+ attribute = DWMWA_USE_IMMERSIVE_DARK_MODE ;
132+ }
133+
134+ int useImmersiveDarkMode = enabled ? 1 : 0 ;
135+ return DwmSetWindowAttribute ( handle , attribute , ref useImmersiveDarkMode , sizeof ( int ) ) == 0 ;
136+
137+ }
138+
139+ private static bool IsWindows10OrGreater ( int build = - 1 )
140+ {
141+ return Environment . OSVersion . Version . Major >= 10 && Environment . OSVersion . Version . Build >= build ;
142+ }
143+
144+ #endregion TitleBarDarkMode
145+
118146 #endregion
119147 }
120148}
0 commit comments