Home > Blockchain >  Different colors of COLOR_WINDOW in Windows 10 and Windows XP
Different colors of COLOR_WINDOW in Windows 10 and Windows XP

Time:07-19

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;

Window in Windows 10 Window in Windows XP

What is color I should use as window background in Windows XP?

CodePudding user response:

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_3DFACE
15
Face color for three-dimensional display elements and for dialog box backgrounds.
COLOR_BTNFACE
15
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