在OnInitDialog()函数中CEdit::EnableWidow(False)
或者在CEdit框的Properties中选上Disable以后
在对话框的
HBRUSH CNetChangeMsgDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
// TODO: Change any attributes of the DC here
if( nCtlColor == CTLCOLOR_EDIT )
{
//pDC->SetBkColor(RGB(255,255,255));
pDC->SetBkColor(RGB(255,0,0));
pDC->SetTextColor(RGB(0,0,0));
HBRUSH w_hbr= ::CreateSolidBrush(RGB(255,255,255));
return w_hbr;
}
// TODO: Return a different brush if the default is not desired
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
return hbr;
}
设置CEdit框背景色失败,一直是那种灰色的背景。
应该怎么做?
是不是在这种情况下就不能改变背景色了?
谢谢

解决方案 »

  1.   

    你的CBrush要是一个全局的,就可以了,
    比如在一个头文件中有
    CBrush brush;
    在一个CPP中有
    brush.CreateSolidBrush(RGB(255,255,255))
    然后再有你的代码if(nCrlColor == CTLCOLOR_EIDT)
    {
    pDC->SetBkColor(...)
    pDC->SetTextColor(...)
    hbr = brush;
    return hbr;
    }
      

  2.   

    HBRUSH CNetChangeMsgDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {
    // TODO: Change any attributes of the DC here
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if( nCtlColor == CTLCOLOR_EDIT )
    {
    //pDC->SetBkColor(RGB(255,255,255));
    pDC->SetBkColor(RGB(255,0,0));
    pDC->SetTextColor(RGB(0,0,0));
    HBRUSH w_hbr= ::CreateSolidBrush(RGB(255,255,255));
    return w_hbr;
    }
    // TODO: Return a different brush if the default is not desired
    return hbr;
    }