在对话框中我重载了OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor),能改变对话框背景色,文字颜色,但按钮的颜色改不掉,函数如下:
HBRUSH CMyDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
     HBRUSH hbr = MyColor;
// TODO: Change any attributes of the DC here
switch(nCtlColor) {
case CTLCOLOR_EDIT:
case CTLCOLOR_STATIC:
pDC->SetBkColor(RGB(122,177,184));
break;
case CTLCOLOR_BTN:
pDC->SetBkColor(RGB(255,0,245));
break;
case CTLCOLOR_MSGBOX:
pDC->SetBkColor(RGB(255,0,245));
break;
default:
break;
}
pDC->SetTextColor(RGB(0,255,249));

// TODO: Return a different brush if the default is not desired
return hbr;
}MyColor设定了背景颜色。我跟踪调试过,确定
        case CTLCOLOR_BTN:
pDC->SetBkColor(RGB(255,0,245));
break;执行到了。
请高手们指导!

解决方案 »

  1.   

    看看,按纽的
    http://www.codeguru.com/Cpp/controls/buttonctrl/article.php/c2087
      

  2.   

    按钮会重新用自己的颜色绘制的
    你可以下一个CButtonST直接来用,很简单,
    而且有源码,也可以参考自己写
      

  3.   

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

    // TODO: Change any attributes of the DC here
    switch(nCtlColor)
    {
         case CTLCOLOR_BTN:
        
    if(pWnd->GetDlgCtrlID() == IDC_BUTTON)
    {
                 return m_hbrush;
    } }

    // TODO: Return a different brush if the default is not desired
    return hbr;
    }
    在.h文件中定义好HBRUSH m_hbrush;
    最后再在你的BUTTON代码断加上m_hbrush=CreateSolidBrush(RGB(0,0,255));
    就可以了。
      

  4.   

    http://www.vckbase.com/code/listcode.asp?mclsid=3&sclsid=301
      

  5.   

    忘了说明,我一个界面上有近30个按钮,不能为每个按钮都定义一个BUTTON类。不过还是谢谢大家,希望继续想办法帮我
      

  6.   

    用油漆刷显示屏.在软件安装手册上注明.刷多少.vckbase上面有很多 这方面的
    vchelp.net也不错..
    再不行 去那个外国的 好象是 codeproject.com吧..旧知道这些了:__(