On a color display, the interiors of the three scroll bars in COLORS1 are red, green, and blue. This coloring is accomplished by processing WM_CTLCOLOR messages.
In WndProc we define a static array of three handles to brushes:
static HBRUSH hBrush [3] ;
During processing of WM_CREATE, we create the three brushes:
hBrush[0] = CreateSolidBrush (RGB (255, 0, 0)) ;
hBrush[1] = CreateSolidBrush (RGB (0, 255, 0)) ;
hBrush[2] = CreateSolidBrush (RGB (0, 0, 255)) ;
During the WM_CTLCOLOR processing, the text and text background colors are set to the normal values for scroll bars. The brush that's returned from this message is one of the three brushes created earlier:
case WM_CTLCOLOR :
if (HIWORD (lParam) == CTLCOLOR_SCROLLBAR)
{
SetBkColor (wParam, GetSysColor (COLOR_CAPTIONTEXT)) ;
SetTextColor (wParam, GetSysColor (COLOR_WINDOWFRAME)) ;
n = GetWindowWord (LOWORD (lParam), GWW_ID) ;
point.x = point.y = 0 ;
ClientToScreen (hwnd, &point) ;
UnrealizeObject (hBrush[n]) ;
SetBrushOrg (wParam, point.x, point.y) ;
return ((DWORD) hBrush[n]) ;
}
break ;
These brushes must be destroyed during processing of the WM_DESTROY message:
for (n = 0 ; n < 3 ; DeleteObject (hBrush [n++])) ;