VC设置控件字体颜色

来源:互联网 发布:语音搜索软件 编辑:程序博客网 时间:2024/06/02 07:56

VC设置控件字体颜色

 

编号A3GS_TV20100325003

 

描述

 

本文以例子代码的形式讲述了VC中如实现设置控件字体颜色。

 

技术实现

 

OnCtlColor函数中如下代码:

 

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

 // TODO:  Change any attributes of the DC here
   if(nCtlColor == CTLCOLOR_STATIC)
       {
       if(pWnd->GetDlgCtrlID()== IDC_REGARD)
           {
               pDC->SetTextColor(RGB(255,0,0));
               pDC->SetBkColor(RGB(251, 247, 200));//设置文本背景色
               pDC->SetBkMode(TRANSPARENT);//设置背景透明
                   
           }
       }

 // TODO:  Return a different brush if the default is not desired
 return hbr;
}

 

 

其他控件的宏定义为:

CTLCOLOR_BTN 按钮控件

CTLCOLOR_DLG 对话框

CTLCOLOR_EDIT 编辑框

CTLCOLOR_LISTBOX 列表控件

CTLCOLOR_MSGBOX 消息控件

CTLCOLOR_SCROLLBAR 滚动条控件

CTLCOLOR_STATIC 静态控件

原创粉丝点击