Search code examples
cwindowswinapigraphicsgdi

Why we need add 1 to background brush color?


One of member of the WNDCLASS structure is handle to the class background brush.

From description:

This member can be a handle to the physical 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).

QUESTION:

Why must add 1 to this value?


Solution

  • It may be because the hbrBackground field accept NULL value.

    It's for RegisterClass() function to make the difference between COLOR_SCROLLBAR which is 0 and NULL which is an acceptable value.