Windows Dialog Background Color

Started by
10 comments, last by SmkViper 9 years, 4 months ago

I guess I don't even know what the "default" on Windows 7 looks like... I'm doing this now to get a darker gray than I'd anticipated, but at least it's doing something I'd expect:


		case WM_ERASEBKGND:
			RECT rc;
			GetClientRect(hwnd, &rc);
			FillRect((HDC)wParam, &rc, GetSysColorBrush(COLOR_BTNSHADOW));
			return TRUE;
Advertisement
To get it to look "right" on modern versions of Windows you should be looking into being theme-aware and using the theme-aware API.

For example, for drawing backgrounds you should probably use DrawThemeBackground instead of FillRect.

(Note: Error checking omitted)


auto theme = GetWindowTheme(hwnd);
DrawThemeBackground(theme, hdc, WP_DIALOG, 0, &rc, nullptr);
Of course, if all you want is the color...


auto theme = GetWindowTheme(hwnd);
COLORREF color;
GetThemeColor(theme, WP_DIALOG, 0, TMT_BACKGROUND, &color);
Course, you'll need to make sure visual styles are enabled for your program. And you may want to respond to WM_THEMECHANGED as well.

For a nice example as well as a theme exploring tool - check out this article on CodeProject

This topic is closed to new replies.

Advertisement