Files
cursor-lang/CursorLang.Settings/Interop/WindowThemeNative.cs
T
alex 55ac8e6556 lightweight variant (#1)
Reviewed-on: #1
Co-authored-by: Aleksandr Neychev <alexnejchev73@gmail.com>
2026-08-12 13:37:30 +00:00

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));
}
}