C++基于对话框的程序,运行时候编辑框不显示颜色,字体也不变化,怎么回事?

我添加三处代码如下:就是不显示颜色和字体

HBRUSH CADODataBase2Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
try
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

    // TODO:  Change any attributes of the DC here
    if(IDC_CONNECT == pWnd->GetDlgCtrlID())
    {
        //pDC->SelectObject(&m_Midft);
        pDC->SetTextColor(RGB(255,255,0));
        //pDC->SetBkMode(TRANSPARENT);
        return m_Grancybh;
    }
    //else if(nCtlColor==CTLCOLOR_EDIT)   //更改编辑框

    //{

    //   //pDC->SetBkMode(TRANSPARENT);

    //  pDC->SetTextColor(RGB(0,0,0));

    //  pDC->SetBkColor(RGB(165,254,236));

    //  HBRUSH b=CreateSolidBrush(RGB(165,254,236));

    //  return b;

    //}


    if(IDC_RESULT==pWnd->GetDlgCtrlID())
    {
        pDC->SelectObject(&m_Maxft);
        pDC->SetBkMode(TRANSPARENT);


        if(!strcmp("UNZIP And UPload please waiting", m_strTestResult))
        {
            pDC->SetTextColor(RGB(0,255,0));
            return m_Yellowbh;
        }
        if(!strcmp("PASS", m_strTestResult))
        {
            pDC->SetTextColor(RGB(0,0,255));
            return m_Greenbh;
        }

    }


    if(IDC_TESTTIME == pWnd->GetDlgCtrlID())
    {
        pDC->SelectObject(&m_Minft);
        pDC->SetTextColor(RGB(0,0,255));
        pDC->SetBkMode(TRANSPARENT);
    }

    // TODO:  Return a different brush if the default is not desired
    return hbr;
}
catch(...)
{
    AfxMessageBox("OnCtlColor fail");   
    return 0 ;
}

}

private:

CFont           m_SupMinft, m_Minft, m_Midft, m_Maxft, m_Supft;
CBrush          m_Redbh,    m_Greenbh, m_Yellowbh, m_Grancybh, m_brush, m_  Blackbh;



m_SupMinft.CreatePointFont(100, _T("Arial"));
m_Minft.CreatePointFont(200, _T("Arial"));
m_Midft.CreatePointFont(350, _T("Arial"));
m_Maxft.CreatePointFont(1000,_T("Arial"));

m_Redbh.CreateSolidBrush(RGB(255,0,0));
m_Greenbh.CreateSolidBrush(RGB(0,255,0));
m_Yellowbh.CreateSolidBrush(RGB(255,255,0));
m_Grancybh.CreateSolidBrush(RGB(82,64,111));
m_brush.CreateSolidBrush(RGB(0,   255,   0));  

OnCtlColor 这个是否函数是否有被调用,你是否绑定了对应的消息

使用断点查找函数有没有被调用不就行了

咳,最好对于VC++编写的对话框程序还是不要变色吧。

你是怎么定义的函数,要按ctrl+w调出类向导,然后把WM_CTLCOLOR消息和OnCtlColor函数关联起来才行。