I do as shown below. It will change the background of the read only edit control IDC_EDIT1 to white. This is a copy-paste straight out of one of my projects.
m_whitebrush is a private member of CTestOnCtlClorDlg of type HBRUSH and must be initialized to NULL in the constructor of CTestOnCtlClorDlg.
HBRUSH CTestOnCtlClorDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
int id = pWnd->GetDlgCtrlID( ) ;
if (id == IDC_EDIT1)
{
pDC->SetTextColor(RGB(0, 0, 0));
pDC->SetBkColor(RGB(255,255,255));
if (!m_whitebrush)
m_whitebrush = CreateSolidBrush(RGB(255,255,255)) ;
hbr = m_whitebrush ;
}
return hbr;
}
void CTestOnCtlClorDlg::OnDestroy()
{
CDialog::OnDestroy();
if (m_whitebrush !=NULL)
{
DeleteObject(m_whitebrush) ;
m_whitebrush = NULL ;
}
}