31 lines
1.1 KiB
C#
31 lines
1.1 KiB
C#
using System.Runtime.InteropServices;
|
|
|
|
namespace CursorLang.Interop;
|
|
|
|
/// <summary>
|
|
/// Оформление рамки окна средствами системы: заголовок рисует Windows,
|
|
/// и в тёмной теме его нужно переключать отдельно от содержимого окна.
|
|
/// </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>
|
|
/// Перекрашивает заголовок окна. На сборках Windows 10 до 2004 атрибут
|
|
/// не поддерживается — заголовок просто останется светлым.
|
|
/// </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));
|
|
}
|
|
}
|