Is there a way in C# to retrieve the current titlebar color?
If you're asking about the old Win32 COLOR_ACTIVECAPTION
color then in .NET Framework and .NET 5+ (and maybe .NET Core?) you can use System.Drawing.SystemColors.ActiveCaption
- if you're drawing text on top of that then use ActiveCaptionText
.
If you're after the DWM color then you'll need to use DwmGetColorizationColor
:
internal static class NativeMethods
{
[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern void DwmGetColorizationColor( out UInt32 colorizationColor, [MarshalAs(UnmanagedType.Bool)] out Boolean colorizationOpaqueBlend );
}
(PreserveSig = false
is what allows this to be void
so we don't need to faff around with parsing HRESULT
in C#)
You'll need to bitshift colorizationColor
to get the RGBA values out.