MFC 基本操作 --修改对话框、静态文本背景颜色

来源:互联网 发布:天人网络电视官网 编辑:程序博客网 时间:2024/05/22 16:07

具体步骤:

1,为所要改变颜色的对话框类添加WM_CTLCOLOR消息函数。

2,把你原来添加消息函数的代码改成如下:

  HBRUSH   CEX06aDialog::OnCtlColor(CDC*   pDC,   CWnd*   pWnd,   UINT   nCtlColor)

   { 

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

   

         if(nCtlColor==CTLCOLOR_DLG||CTLCOLOR_STATIC)   //CTLCOLOR_DLG  和CTLCOLOR_STATIC 为你要改变的控件ID,一定是ID啊

         {

              pDC->SetTextColor(RGB(0,0,0));//设置文本背景色
              pDC->SetBkColor(RGB(213,229,243));//设置当前的背景色     

              HBRUSH B=CreateSolidBrush(RGB(213,229,243));//设置对话框背景色
              return B;//返回刚才创建的背景刷子

         }

         //TODO:如果默认的不是所需画笔,则返回另一个画笔

         return   hbr;

    }

附加:在MSDN中,关于参数nCtlColor,取以下值:

nCtlColor

Contains one of the following values, specifying the type of control:

·         CTLCOLOR_BTN    Button control

·         CTLCOLOR_DLG    Dialog box

·         CTLCOLOR_EDIT    Edit control

·         CTLCOLOR_LISTBOX    List-box control

·         CTLCOLOR_MSGBOX    Message box

·         CTLCOLOR_SCROLLBAR    Scroll-bar control

·         CTLCOLOR_STATIC    Static control

0 0
原创粉丝点击