Question : Color of edit box

Hiya

How can I change the background color of an edit box if it is read-only or disabled? For example, change its colour from the default grey to red?

Thanks in advance

John

Answer : Color of edit box

MSDN. CWnd::OnCtlColor
http://msdn.microsoft.com/en-us/library/0wwk06hc(VS.80).aspx

When you create a window, create a brush:
m_Brush = new CBrush(RGB(150, 150, 150));

and in OnCtlColor when the parameter is CTLCOLOR_EDIT, set the color for the text and the background and return the brush:

             pDC->SetTextColor(RGB(0, 255, 0));
             pDC->SetBkColor(RGB(0, 0, 0));
             return (HBRUSH)(m_Brush->GetSafeHandle());

otherwise:
             return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

delete the brush when you close the window.

More:
Changing the Background Color of an Edit Control
http://www.codeguru.com/cpp/controls/editctrl/backgroundcolor/article.php/c9047


Random Solutions  
 
programming4us programming4us