[英]How to get window title bar (active and inactive) color in Windows 8?
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). 我在Windows 8中得到了完全不同的颜色。它总是返回橙色或棕色,而不是实际的颜色(比如说蓝色)。
Using DwmGetColorizationColor
works, but the color is darker because I need to eliminate alpha. 使用
DwmGetColorizationColor
可以,但是颜色较深,因为我需要消除Alpha。 I try to do it like this: 我尝试这样做:
BYTE r = ((RED * ALPHA) + (255 * (255 - ALPHA))) / 255; // R' = (R * A) + (1 - A)
BYTE g = ((GREEN * ALPHA) + (255 * (255 - ALPHA))) / 255; // G' = (G * A) + (1 - A)
BYTE b = ((BLUE * ALPHA) + (255 * (255 - ALPHA))) / 255; // B' = (B * A) + (1 - A)
So, my problems are: 所以,我的问题是:
EDIT: My ARGB to RGB code seems to work unless I set color intensity in Control Panel to max (because somehow alpha is 0, and the color is green) or min. 编辑:我的ARGB到RGB代码似乎可以正常工作,除非我在“控制面板”中将颜色强度设置为max(因为不知何故alpha为0,颜色为绿色)或min。
EDIT2: This is not a duplicate because this is specifically about W8+. EDIT2:这不是重复的,因为这是专门针对W8 +的。
This is a hackish solution and will probably only work with Windows 8 and 8.1 (I'm going to test later with 10). 这是一个棘手的解决方案,可能仅适用于Windows 8和8.1(我将在稍后的10中进行测试)。
I analysed the windows colors and this is what I could see: 我分析了窗户的颜色,这是我可以看到的:
0xD9D9D9
and the color in \\HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\DWM\\ColorizationColor
using the value in \\HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\DWM\\ColorizationColorBalance
(it's in a 0-100 scale) as a "alpha". 0xD9D9D9
和颜色\\HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\DWM\\ColorizationColor
使用的值\\HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\DWM\\ColorizationColorBalance
(它在0-100比例)作为“ alpha”。 So... 所以...
if (fActive)
{
DWORD ColorizationColor;
DWORD ColorizationColorBalance;
DWORD size = sizeof(DWORD);
RegGetValue(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\DWM", L"ColorizationColor", RRF_RT_REG_DWORD, 0, &ColorizationColor, &size);
RegGetValue(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\DWM", L"ColorizationColorBalance", RRF_RT_REG_DWORD, 0, &ColorizationColorBalance, &size);
BYTE ALPHA = 255 * ColorizationColorBalance / 100; // Convert from 0-100 to 0-255
BYTE RED = (ColorizationColor >> 16) & 0xFF;
BYTE GREEN = (ColorizationColor >> 8) & 0xFF;
BYTE BLUE = ColorizationColor & 0xFF;
BYTE r = ((RED * ALPHA) + (0xD9 * (255 - ALPHA))) / 255;
BYTE g = ((GREEN * ALPHA) + (0xD9 * (255 - ALPHA))) / 255;
BYTE b = ((BLUE * ALPHA) + (0xD9 * (255 - ALPHA))) / 255;
graphics.FillRectangle(&SolidBrush(Color(r, g, b)), Rect(...);
}
else
{
graphics.FillRectangle(&SolidBrush(0xFFEBEBEB), Rect(...));
}
Because this probably won't work at Windows 7 different code should be user for different systems. 因为这可能在Windows 7上不起作用,所以不同系统的用户应该使用不同的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.