- WIN11のみ
- ウィンドウがアクティブの時に青色、非アクティブ時はグレーアウトされます
RGB値を可変して下さい - WIN95,XPはアクティブウィンドウは勝手に青色になったがWIN11はアクティブでもグレーのままで分かりづらい
- 自身が開発している DetailAllData(DADシステム)で採用
- 元はOPEN AIの回答です
SRC
using System;
using System.Runtime.InteropServices;
using System.Windows.Interop;
// TITLE COLOR
private const int DWMWA_CAPTION_COLOR = 35;
[DllImport("dwmapi.dll")]
private static extern int DwmSetWindowAttribute(IntPtr hwnd,int dwAttribute,ref int pvAttribute,int cbAttribute);
private void SetTitleBarColor(int color){
IntPtr hwnd = new WindowInteropHelper(this).Handle;
DwmSetWindowAttribute( hwnd, DWMWA_CAPTION_COLOR, ref color, Marshal.SizeOf<int>());
}
private void Window_Activated(object sender, EventArgs e) {
// 青
SetTitleBarColor(0x00FF0000);
}
private void Window_Deactivated(object sender, EventArgs e) {
// グレー
SetTitleBarColor(0x00A0A0A0);
}
// public MainWindow() の中に追記 無くても可かも
SetTitleBarColor(0x00FF0000);
XAML 頭の <Window 内に追記
Activated="Window_Activated" Deactivated="Window_Deactivated"