CWnd::OnCtlColor

Syntax

afx_msg HBRUSH OnCtlColor( CDC* pDC, CWnd* pWnd, UINT nCtlColor );

Parameters

pDC

Contains a pointer to the display context for the child window. May be temporary.

pWnd

Contains a pointer to the child CWnd. May be temporary.

nCtlColor

Contains one of the following values, specifying the type of control:

Value Meaning

CTLCOLOR_BTN Button control
CTLCOLOR_DLG Dialog box
CTLCOLOR_EDIT Edit control
CTLCOLOR_LISTBOX List box control
CTLCOLOR_MSGBOX Message box
CTLCOLOR_SCROLLBAR Scroll-bar control
CTLCOLOR_STATIC Static control

Remarks

Called when a child system-defined control class or a message box is about to be drawn. The following controls call OnCtlColor:

Combo boxes Buttons
Edit controls Static controls
List boxes Scroll bars

To change the background color of a single-line edit control, you must set the brush handle in both the CTLCOLOR_EDIT and CTLCOLOR_MSGBOX message codes, as well as calling the SetBkColor function in response to the CTLCOLOR_EDIT code.

The return value from the function has no effect on a button with the BS_PUSHBUTTON or BS_DEFPUSHBUTTON style.

This message-handler member function calls the Default member function. Override this member function in your derived class to handle the WM_CTLCOLOR message.

Return Value

OnCtlColor must return a handle to the brush that is to be used for painting the control background, or it must return NULL.

See Also

CDC::SetBkColor, WM_CTLCOLOR, CWnd::Default