Muokkaa

Jaa


WM_CTLCOLORSTATIC message

A static control, or an edit control that is read-only or disabled, sends the WM_CTLCOLORSTATIC message to its parent window when the control is about to be drawn. By responding to this message, the parent window can use the specified device context handle to set the text foreground and background colors of the static control.

A window receives this message through its WindowProc function.

WM_CTLCOLORSTATIC

    WPARAM wParam;
    LPARAM lParam; 

Parameters

wParam

Handle to the device context for the static control window.

lParam

Handle to the static control.

Return value

If an application processes this message, the return value is a handle to a brush that the system uses to paint the background of the static control.

Remarks

If the application returns a brush that it created (for example, by using the CreateSolidBrush or CreateBrushIndirect function), the application must free the brush. If the application returns a system brush (for example, one that was retrieved by the GetStockObject or GetSysColorBrush function), the application does not need to free the brush.

By default, the DefWindowProc function selects the default system colors for the static control.

You can set the text background color of a disabled edit control, but you cannot set the text foreground color. The system always uses COLOR_GRAYTEXT.

Edit controls that are not read-only or disabled do not send the WM_CTLCOLORSTATIC message; instead, they send the WM_CTLCOLOREDIT message.

The WM_CTLCOLORSTATIC message is never sent between threads; it is sent only within the same thread.

If a dialog box procedure handles this message, it should cast the desired return value to a INT_PTR and return the value directly. If the dialog box procedure returns FALSE, then default message handling is performed. The DWL_MSGRESULT value set by the SetWindowLong function is ignored.

Examples

The following C++ example shows how to set the text foreground and background colors of a static control in response to the WM_CTLCOLORSTATIC message. The hbrBkgnd variable is a static HBRUSH variable that is initialized to NULL, and stores the background brush between calls to WM_CTLCOLORSTATIC. The brush must be destroyed by a call to the DeleteObject function when it is no longer needed, typically when the associated dialog box is destroyed.

   case WM_CTLCOLORSTATIC:
        {
        HDC hdcStatic = (HDC) wParam;
        SetTextColor(hdcStatic, RGB(255,255,255));
        SetBkColor(hdcStatic, RGB(0,0,0));

        if (hbrBkgnd == NULL)
        {
            hbrBkgnd = CreateSolidBrush(RGB(0,0,0));
        }
        return (INT_PTR)hbrBkgnd;
        }

Requirements

Requirement Value
Minimum supported client
Windows Vista [desktop apps only]
Minimum supported server
Windows Server 2003 [desktop apps only]
Header
Winuser.h (include Windows.h)

See also

Reference

WM_CTLCOLORBTN

WM_CTLCOLOREDIT

WM_CTLCOLORLISTBOX

WM_CTLCOLORSCROLLBAR

Other Resources

DefWindowProc

RealizePalette

SelectPalette

WM_CTLCOLORDLG