how to set color for static control text in dialog?

27 08 2008

Colors convey meanings too. For instance, if something is written in red – that means something to be cautious. If its in green, its treated as safe. Well, usually in window dialogs, the static control texts are black in color. Is it possible to color them to convey more meaning?

Yes! You have to handle WM_CTLCOLOR message. For each control, this message will be triggered and you’re free to do modification on your control. Have a look at the code snippet in MFC framework.

// Message Map

HBRUSH CDlgDlg::OnCtlColor( CDC* pDC, CWnd* pWnd, UINT nCtlColor )
    // Call base class version at first. Or else it will override your changes.
    HBRUSH hbr = CDialog::OnCtlColor( pDC, pWnd, nCtlColor );

    // Check whether which static label its.
    if( pWnd->GetDlgCtrlID() == IDC_STATIC_OK )
        // Set color as red.
        pDC->SetTextColor( RGB( 255, 0, 0 ));
        pDC->SetBkMode( TRANSPARENT );

    return hbr;

Always call CDialog::OnCtlColor() at first. Or else it will override your modifications.

Targeted Audience – Intermediate.



4 responses

10 09 2008

Hi, It really works, ive done it already, But im searching a messive way of the same thing to be done in simple WIN32, not MFC. Can u help me please

10 09 2008

If you seek plain win32, you could handle WM_CTLCOLORSTATIC and can change the static text color.

Have a look at this link – It contains code samples. Hope it helps.


21 10 2008

Is it applicable only to static control or i can use it for other

21 10 2008

You could change the color of other controls as well. Controls such as – Button, Dialog, edit, Listbox, scrollbars etc. For instance, see how to change the color of push button here –


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: