The information in this article applies to:
SUMMARYA WM_CTLCOLOR message is sent to a window each time one of its child window controls (radio button, check box, scroll bar, and so forth) is to be painted on the screen. This message precedes the painting of the control. When it is desirable to change the appearance of controls, this can be done by processing the WM_CTLCOLOR message. MORE INFORMATIONWhen WM_CTLCOLOR is sent, wParam contains a handle to the display context for the child window (in this case the control). The LOWORD of lParam identifies the child window by its ID number, and the HIWORD of lParam contains one of the following values, specifying the type of control that is to be drawn:
When WM_CTLCOLOR is processed, a handle to a brush must be returned.
Failure to return a brush handle will result in a Windows FatalExit on the
debugging monitor in the debug version of Windows.
DefWindowProc() already returns a handle in response to this message; however, an application can return a different handle to customize the color of controls. The handle that is returned specifies the brush to be used to paint the control. For example, in Windows 2.x, the following code paints the background of all buttons light gray:
In this case, the backgrounds for all other controls are painted white.
Note that GetStockObject() returns a handle to the stock brush specified by the parameter. To change the background color of a button control in Windows 3.0 and later, it is necessary to create an owner draw button.
Returning a brush handle presents some interesting possibilities because brush handles are not limited to those returned from GetStockObject(). Pattern brushes can be built from bitmaps. If a pattern brush handle is returned in response to a WM_CTLCOLOR message, the brush would be used to paint the background of controls. The following code changes the painting of a scroll bar's thumb track area to the basket-weave pattern found in Paint:
The WM_CTLCOLOR message also applies to the following five classes of
controls:
NOTE: In Windows 3.0 and later, an application cannot change the color of a button face. However, the user can use the Control Panel to change the button colors for all applications in the system. This can also be accomplished by modifying the [colors] section of the WIN.INI file to add a "ButtonFace=" line that specifies the RGB color value for the button face color. Processing the WM_CTLCOLOR message only changes the color of child windows created by an application. Windows sends the WM_CTLCOLOR message to the parent window of each of these controls. Scroll bars that are included by Windows as a part of edit controls or list boxes are not affected. The thumb track area of system-generated scroll bars can only be changed in WIN.INI or through the Control Panel. It is also possible to paint the entire background of a dialog box. The following code can be used to provide a dialog box color:
This code will ensure that a patterned bitmap will line up correctly
across the entire dialog box. "MyPatternBrush" is the name of a bitmap
created using SDKPaint. This bitmap must be included in the .RC file.
Additional query words: 3.00 3.10
Keywords : kb16bitonly kbCtrl kbSDKPlatform kbWndwMsg |
Last Reviewed: June 7, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |