-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
60 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
|
||
namespace FanCtrl | ||
{ | ||
public enum THEME_TYPE | ||
{ | ||
SYSTEM, | ||
LIGHT, | ||
DARK, | ||
} | ||
|
||
public enum DWMWINDOWATTRIBUTE | ||
{ | ||
DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1 = 19, | ||
DWMWA_USE_IMMERSIVE_DARK_MODE = 20, | ||
} | ||
|
||
class Theme | ||
{ | ||
public static bool isWindows10OrGreater(int build = -1) | ||
{ | ||
var version = Environment.OSVersion.Version; | ||
return version.Major >= 10 && version.Build >= build; | ||
} | ||
|
||
public static void setTheme(IntPtr handle, bool isDarkMode) | ||
{ | ||
if (isWindows10OrGreater(17763)) | ||
{ | ||
int attribute = (int)DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1; | ||
if (isWindows10OrGreater(18985)) | ||
{ | ||
attribute = (int)DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE; | ||
} | ||
|
||
int useImmersiveDarkMode = isDarkMode ? 1 : 0; | ||
DwmSetWindowAttribute(handle, attribute, ref useImmersiveDarkMode, sizeof(int)); | ||
} | ||
} | ||
|
||
[DllImport("dwmapi.dll", CharSet = CharSet.Unicode, PreserveSig = false)] | ||
public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters