HBRUSH CMyDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
if (nCtlColor==CTLCOLOR_EDIT){
pDC->SetBkColor(RGB(255,0,0));
return m_hYellowBrush;
}
if (nCtlColor==CTLCOLOR_DLG){
pDC->SetBkColor(RGB(255,255,0));
return m_hRedBrush;
} HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

// TODO: Change any attributes of the DC here

// TODO: Return a different brush if the default is not desired
return hbr;
}在OnInitDialog()中初始化m_hRedBrush和m_hYellowBrush如下:
CBrush m_YellowBrush(RGB(255,255,0));
CBrush m_RedBrush(RGB(255,0,0));
HBRUSH m_hYellowBrush=(HBRUSH)m_YellowBrush;
HBRUSH m_hRedBrush=(HBRUSH)m_RedBrush;还是改变不了~为什么~简单问题50分相赠

解决方案 »

  1.   

    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

    // TODO: Change any attributes of the DC here
    if(nCtlColor==CTLCOLOR_DLG)
    {
    // Set the text color to red
    pDC->SetTextColor(RGB(255, 0, 0));

    // Set the background mode for text to transparent 
    // so background will show thru.
    pDC->SetBkMode(TRANSPARENT);

    pDC->SetBkColor(RGB(255,255,0));

    // Return handle to our CBrush object
    hbr = m_brush;
    }
    // TODO: Return a different brush if the default is not desired
    return hbr;
      

  2.   

    还是不行啊~请问变量m_brush怎么定义?
      

  3.   

    还是要谢谢SatanLi1982(红魔)~为什么简单的问题都没有人回答呢~欺负菜鸟么~
      

  4.   

    在OnInitDialog里加 m_brush=CreateSolidBrush(RGB(255,255,0));