Reputation: 7160
Usually most colors used by standard controls can be got from GetSysColor
, I ran a test with all the COLOR_
constants (0-30) and compared it to the color of a group box border and none of them matched. I'm using XP, and the colour of the group box border is 0xD0D0BF
.
How do you get the system color used for drawing the group box border?
Upvotes: 2
Views: 1163
Reputation: 244692
Using the "Classic" theme (on XP, or the only theme in previous versions of Windows), the group box border is not a single color. It is actually an "etched" line, composed of two lines of different colors. Each of those colors have a COLOR_*
value, but you don't want to try and recreate the line this way. Instead, use GDI's DrawEdge
function with the EDGE_ETCHED
flag.
But if you have themes enabled, the group box border actually is a single color and that color varies depending on the selected theme. There's no way to retrieve theme colors using GetSysColor
because they don't have corresponding COLOR_*
values. That API was invented long before themes were conceived. Instead, there's a whole new set of Themes APIs. The one you're interested in here is GetThemeColor
, but in order to use that you'll also need OpenThemeData
and CloseThemeData
.
The tricky part is figuring out what to pass to the OpenThemeData
function. This question might help with that. A group box control is actually a special type of button control, so the style you want is:
BUTTON
BP_GROUPBOX
GBS_NORMAL
(and possibly also GBS_DISABLED
)TMT_BORDERCOLOR
Do make sure that your code has proper fallback support for when themes are disabled! Use the IsAppThemed
function to determine that dynamically at runtime and select the appropriate drawing code path.
EDIT: After some testing on an XP VM, I can't find the right TMT_*
property ID to specify to get the right color for a group box's border. I'm not sure what's up with that. But you can get the border drawn for you using the DrawThemeBackground
function:
HTHEME hTheme = OpenThemeData(grpBox->m_hWnd, L"Button");
DrawThemeBackground(hTheme, hDC, BP_GROUPBOX, GBS_NORMAL, &rcArea, NULL);
CloseThemeData(hTheme);
Unfortunately, that doesn't tell you how to get the color value itself.
Upvotes: 4