samedi 27 juin 2015

How to get window title bar (active and inactive) color?

I'm making a program and I need to paint a rectangle of the same color as the title bar.

If I try to get the color like this:

ARGB rgbActiveColor = GetSysColor(COLOR_ACTIVECAPTION);
ARGB rgbInactiveColor = GetSysColor(COLOR_INACTIVECAPTION);
rgbActiveColor |= 0xFF000000;    // Because of alpha
rgbInactiveColor |= 0xFF000000;

I get a totally different color in Windows 8. It always returns a orange or brown color instead of the actual color (let's say, blue).

Using DwmGetColorizationColor works, but the color is darker because I need to eliminate alpha. I try to do it like this:

BYTE r = ((RED * ALPHA) + (255 - ALPHA)) / 255; // R' = (R * A) + (1 - A)
BYTE g = ((GREEN * ALPHA) + (255 - ALPHA)) / 255; // G' = (G * A) + (1 - A)
BYTE b = ((BLUE * ALPHA) + (255 - ALPHA)) / 255; // B' = (B * A) + (1 - A)

So, my problems are:

  1. I don't know how I can correctly convert the return color from ARGB to RGB
  2. I don't know how to get the inactive title bar color

Aucun commentaire:

Enregistrer un commentaire