Different colors of COLOR_WINDOW in Windows 10 and Windows XP - c++

In Windows 10 color of window equal of background colors of GUI elements. However, in Windows XP color of window is white, that is not equal of background colors of elements.
WNDCLASSEX configuration:
WNDCLASSEX wincl;
//...
wincl.hbrBackground = (HBRUSH)COLOR_WINDOW; // Set background color
//...
if (!RegisterClassEx (&wincl))
return 1;
What is color I should use as window background in Windows XP?

COLOR_3DFACE/COLOR_BTNFACE is the color constant you are looking for. COLOR_WINDOW is the color inside a text box.
GetSysColor function
Value
Meaning
COLOR_3DFACE15
Face color for three-dimensional display elements and for dialog box backgrounds.
COLOR_BTNFACE15
Face color for three-dimensional display elements and for dialog box backgrounds. The associated foreground color is COLOR_BTNTEXT.
You must add +1 to the system color constant when using it as a class brush:
WNDCLASSEXA structure
WNDCLASSEXW structure
hbrBackground
Type: HBRUSH
A handle to the class background brush. This member can be a handle to the brush to be used for painting the background, or it can be a color value. A color value must be one of the following standard system colors (the value 1 must be added to the chosen color). If a color value is given, you must convert it to one of the following HBRUSH types:
Why do I have to add one when setting a class background brush to a system color?
To make sure that the result is not zero.
The COLOR_SCROLL­BAR system color is index zero. If we didn’t add one to the system color indices, then an attempt to set the background color to the scroll bar color would end up with (HBRUSH)0, which is a null pointer. When the system saw that you set hbrBackground to a null pointer, it wouldn’t know whether you meant the window to have no background color (null pointer), or whether you wanted it to have the system scroll bar color (COLOR_SCROLL­BAR).

Related

How Do I Set the Background Color of buttons including a Checkbox button?

How Do I Set the Background Color of buttons including a Checkbox button?
I struggled to find the answer to this today - thinking it should be simple to answer this, but the information I stumbled on was less than helpful, so at the risk of duplicating stuff that's out there but I couldn't find, I'll make this quick'n'dirty how-to...
All 'Button' class windows send WM_CTLCOLORSTATIC to their parent window, which can then call ::SetBkColor((HDC)wParam, rgbBkColor), and return a brush for that color.
If this is all using system colors, then the brush handle doesn't need to be managed, you can simply ask for the ::GetSysColor(sysIndex), and return the ::GetSysColorBrush(sysIndex) for the returned brush.
If you're using a custom color, then you'll need to create your own brush and manage the handle for that.
I needed this code for a Message Box replacement, which has the upper part using a white background, and the lower part using a gray background, per the Windows standard message box. So my static control (icon) needed to be white, while my other buttons (including a "Don't ask again" checkbox) needed to have a gray background (checkboxes normally have a white background).
So, I handle WM_ERASEBKGND to paint the two portions of the background correctly, and then I handle WM_CLTLCOLORSTATIC to ensure that all buttons are properly "transparent" for the background that they appear on. In my case, the I used a "Static" control for the icon, which draws its background in gray, and a couple of push-buttons plus a checkbox button - which a checkbox button always paints its background in white, so both required a fix.
My example is using MFC, but hopefully you can translate that trivially enough for your purposes:
// add to the message map:
ON_MESSAGE(WM_CTLCOLORSTATIC, OnCtlColorStatic)
// create the implementation:
LRESULT CRTFMessageBox::OnCtlColorStatic(WPARAM wParam, LPARAM lParam)
{
// buttons and static controls (icon) send WM_CTLCOLORSTATIC, so we can force them to use the correct background color here...
const HDC hdc = (HDC)wParam;
const int idc = ::GetDlgCtrlID((HWND)lParam);
// choose a system color or brush based on if this is icon (static) or another control (a button)
const int idx = idc == IDC_STATIC ? COLOR_WINDOW : COLOR_3DFACE;
// select system color
::SetBkColor(hdc, GetSysColor(idx));
// return system brush (which we don't need to delete!)
return (LRESULT)GetSysColorBrush(idx);
}

All-aero window have controls' colors blended - how to avoid it

I'm looking for a way to paint my custom controls into both the client and non-client area of a dialog. More or less the white area below
I used DwmExtendFrameIntoClientArea and I managed to get that effect by extending the client area on the entire window with
MARGINS mar = {-1, -1, -1, -1};
DwmExtendFrameIntoClientArea ( hWnd, &mar );
but now every control which I set with a transparent background
SetBkMode(hdc, TRANSPARENT);
have their colors blended with the aero stuff (the same problem you can see here).
Is there a way for the controls to retain their right color and avoid blending with the background?
It is because the window treated the black colour as the transparency key.
You just need to set another value:
SetWindowLong(hWnd,GWL_EXSTYLE,WS_EX_LAYERED);
// Choose a colour that you will not use in the program, eg RGB(200,201,202)
SetLayeredWindowAttributes(hWnd,RGB(200,201,202),0,LWA_COLORKEY);

GetSysColorBrush constant for background color of a tab control?

I'm using the following APIs to draw a small stock icon on the background of my tab control window (with class name SysTabControl32):
DrawIconEx(hDC, rcIcon.left, rcIcon.top,
hIconSmInfo, rcIcon.Width(), rcIcon.Height(), NULL,
::GetSysColorBrush(COLOR_WINDOW),
DI_NORMAL);
But it doesn't seem to draw consistent background. Let me show.
On a themed Windows 7:
It draws it correctly:
But if I remove themes:
It draws this white background:
So what constant do I need to use for GetSysColorBrush?

c++ DrawText() font color and background color

How do I change the text color and font background color that is displayed when I use the DrawText() function?
Whenever I use the DrawText() function, I always output a present font as well as a "white" background color. I understand to change the font I must create the HFONT and use SelectObject to set the font, however... I did not find any color options in the CreateFont parameters (searched in msdn):
http://msdn.microsoft.com/en-us/library/windows/desktop/dd183499(v=vs.85).aspx
Now, on msdn page for the DrawText() function (http://msdn.microsoft.com/en-us/library/windows/desktop/dd162498(v=vs.85).aspx) I found the following comment:
"The DrawText function uses the device context's selected font, text color, and background color to draw the text. "
And that is all I could find relative to text color and background color. From that sentence, I am unsure if I should be using some other GDI functions to select other objects that specify text color or background color (if those objects exist), nor am I sure if I missed something in the parameters for CreatFont().
QUESTION:
How do I change the text color and font background color that is displayed when I use the DrawText() function?

Set background color of entire window in PDCurses

wattron and a color pair only sets the background color of text when it is printed inside a window. What is the best way to set the background color of the entire window without filling it with spaces (i.e. a title or status bar)?
A call to wbkgd with a pointer to a WINDOW object and a color pair sets the background color of the window.