31 lines
975 B
C#
31 lines
975 B
C#
using System.Runtime.InteropServices;
|
|
|
|
namespace CursorLang.Settings.Interop;
|
|
|
|
/// <summary>
|
|
/// Window frame styling by the system: the title bar is drawn by Windows,
|
|
/// and in the dark theme it has to be switched separately from the window content.
|
|
/// </summary>
|
|
internal static class WindowThemeNative
|
|
{
|
|
[DllImport("dwmapi.dll")]
|
|
private static extern int DwmSetWindowAttribute(IntPtr hWnd, int attribute, ref int value, int size);
|
|
|
|
private const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
|
|
|
|
/// <summary>
|
|
/// Recolours the window title bar. On Windows 10 builds before 2004 the attribute
|
|
/// is not supported — the title bar simply stays light.
|
|
/// </summary>
|
|
internal static void SetDarkTitleBar(IntPtr hWnd, bool isDark)
|
|
{
|
|
if (hWnd == IntPtr.Zero)
|
|
{
|
|
return;
|
|
}
|
|
|
|
int value = isDark ? 1 : 0;
|
|
DwmSetWindowAttribute(hWnd, DWMWA_USE_IMMERSIVE_DARK_MODE, ref value, sizeof(int));
|
|
}
|
|
}
|