我的做法是把它的背景色先更改了
再用SetReadOnly()函数
但是背景色还是被变成灰色了
如何在设置ReadOnly以后还能把EditBox的背景色也能更改呢?
谢谢

解决方案 »

  1.   

    先调用SetReadOnly函数然后背景色
      

  2.   

    不行~
    只看见红色一闪
    代码如下
    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));
    m_editWnd.SetReadOnly(TRUE);
    pDC->SetBkColor(RGB(255,0,0));
    pDC->SetTextColor(RGB(0,0,0));
    //HBRUSH w_hbr= ::CreateSolidBrush(RGB(255,255,255));

    HBRUSH w_hbr= ::CreateSolidBrush(RGB(255,0,0));

    //HBRUSH w_hbr = brush;
    return w_hbr;
    }
    // TODO: Return a different brush if the default is not desired
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
    return hbr;
    }
      

  3.   

    关于编辑框的背景色的修改需要在OnCtlColor中设置编辑框的颜色。
    但是对于只读的编辑框,它取的颜色不是编辑框的颜色而是静态控件的颜色,也就是说楼上的错法是看不到效果的,将判断改为if( nCtlColor == CTLCOLOR_STATIC )就好了。
      

  4.   

    同意楼上,应该是判断nCtlColor==CTLCOLOR_STATIC