The Button Colors

COLOR_WINDOW and COLOR_WINDOWTEXT are used by many windows to color themselves. The button controls (with the exception of push buttons) use COLOR_WINDOW to color the background behind the button. (For a group box, COLOR_WINDOW is used only for the background behind the text.) The button controls use COLOR_WINDOWTEXT for text, for the box in a check box control, and for the round button in a radio-button control. The outline of push buttons and group boxes is defined by using COLOR_WINDOWFRAME.

You can use one of two methods to make your main window and the child window control consistent in their use of colors. The first method is to use system colors for your main window. To begin, you use COLOR_WINDOW for the background of your client area when defining the window class:

wndclass.hbrBackground = COLOR_WINDOW + 1 ;

(Windows requires that you add 1 when you use these identifiers in your wndclass structure, but doing so has no profound purpose other than to prevent the value from being 0.) But that causes another problem. When you display text using TextOut, Windows uses values defined in the device context for the text background color (which erases the background behind the text) and the text color. The default values are white (background) and black (text) regardless of both the system colors and the hbrBackground field of the window class structure. So you need to use SetTextColor and SetBkColor to change your text and text background colors to the system colors. You do this after you obtain the handle to a device context:

SetBkColor (hdc, GetSysColor (COLOR_WINDOW)) ;

SetTextColor (hdc, GetSysColor (COLOR_WINDOWTEXT)) ;

Now the client-area background, text background, and text color are all consistent with button colors. That's the first method.

The second method is to force the child window controls to use the colors you want to use. This method is a little more involved; it requires processing WM_CTLCOLOR messages.