-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathShellDarkMode.cs
36 lines (31 loc) · 1.13 KB
/
ShellDarkMode.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Runtime.InteropServices;
namespace EverythingNET
{
public class ShellDarkMode
{
public static void BeforeWindowCreation()
{
try {
int APPMODE_ALLOWDARK = 1;
SetPreferredAppMode(APPMODE_ALLOWDARK);
} catch (Exception) { }
}
public static void AfterWindowCreation(IntPtr hWnd)
{
try {
SetWindowTheme(hWnd, "DarkMode_Explorer", null);
IntPtr dark = new IntPtr(1);
DwmSetWindowAttribute(hWnd, 20, ref dark, Environment.Is64BitProcess ? 8 : 4);
} catch (Exception) { }
}
[DllImport("uxtheme.dll", EntryPoint = "#135")]
public static extern int SetPreferredAppMode(int appMode);
[DllImport("uxtheme.dll", CharSet = CharSet.Unicode)]
public static extern int SetWindowTheme(IntPtr hWnd, string pszSubAppName, string pszSubIdList);
[DllImport("dwmapi.dll")]
public static extern int DwmSetWindowAttribute(
IntPtr hwnd, int dwAttribute, ref IntPtr pvAttribute, int cbAttribute);
}
}