forked from jeremybytes/SlideShow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Native.cs
41 lines (34 loc) · 1.09 KB
/
Native.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
37
38
39
40
41
using System.Windows;
using System.Windows.Interop;
using Windows.Win32;
using Windows.Win32.Foundation;
using Windows.Win32.Graphics.Dwm;
using Windows.Win32.System.Power;
namespace SlideShow;
internal static partial class Native
{
internal static void KeepAwake()
{
PInvoke.SetThreadExecutionState(EXECUTION_STATE.ES_DISPLAY_REQUIRED);
}
internal static void AllowSleep()
{
PInvoke.SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS);
}
unsafe internal static bool UseImmersiveDarkMode(Window window, bool enabled)
{
if (IsWindows10OrGreater(18985))
{
HWND hwnd = new(new WindowInteropHelper(window).Handle);
BOOL dark = new(enabled);
return 0 == PInvoke.DwmSetWindowAttribute(hwnd,
DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE,
&dark, sizeof(int));
}
return false;
}
private static bool IsWindows10OrGreater(int build = -1)
{
return Environment.OSVersion.Version.Major >= 10 && Environment.OSVersion.Version.Build >= build;
}
}