我的对话框中有一个“只读”的编辑框,我在Dialog的OnCtlColor中用以下代码无法改变编辑框为白底黑字。(因为我在CWinApp的InitInstance()中调用了SetDialogBkColor(RGB(33,64,156),RGB(255,255,255));所以这里想改变编辑框)如果将编辑框设置成可编辑,则不用重载OnCtlColor(),编辑框也是白底黑字的。
各位能帮我解决一下吗?
为什么“只读”的编辑框会无法改变底色和字体颜色?HBRUSH CDlgMessage::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{ HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

if (CTLCOLOR_EDIT == nCtlColor)
{
pDC->SetBkColor(RGB(255,255,255));
pDC->SetTextColor(RGB(0,0,0));
}
return hbr;}

解决方案 »

  1.   

    应该使用brush来设置背景
    if(nCtlColor == CRLCOLOR_EDIT)
    {
    hbr = 背景刷子;
    }
    return hbr;
      

  2.   

    我已经改成如下了,可是还是不能改变我的只读编辑框的底色和字体颜色。
    谁能帮帮忙?
    if (CTLCOLOR_EDIT == nCtlColor)
    {
    pDC->SetBkColor(RGB(255,255,255));
    pDC->SetTextColor(RGB(0,0,0)); HBRUSH hbr = CreateSolidBrush(RGB(255,255,255));
    return hbr;
    }
      

  3.   

    只读编辑框被当成STATIC看待的,所以你不能用CTLCOLOR_EDIT,而应该用CTLCOLOR_STATIC,即         if (CTLCOLOR_STATIC == nCtlColor)
                 // ^^^^^注意这里不是EDIT
    {
                   //  .....
    }
      

  4.   

    补充一下,如果编辑框是Disabled的,也如此。我是在MSDN找到的。WM_CTLCOLORSTATIC
    A static control, or an edit control that is read-only or disabled, sends the WM_CTLCOLORSTATIC message to its parent window when the control is about to be drawn. By responding to this message, the parent window can use the specified device context handle to set the text and background colors of the static control.