Question : Color of edit box


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


Answer : Color of edit box

MSDN. CWnd::OnCtlColor

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());

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

delete the brush when you close the window.

Changing the Background Color of an Edit Control

Random Solutions  
programming4us programming4us