vs2005 mfc_color
2018-02-23 17:13
204 查看
在MFC类库提供了CWnd::OnCtlColor函数,在工作框架的子窗口被重画时将调用该成员函数.因此可以重载WM_CTLCOLOR消息的响应函数.此函数的原型:
afx_msg HBRUSH OnCtlColor(CDC *pDC,CWnd *pWnd,UINT
nCtlColor);
参数nCtlColor用于指定控件的类型,可以是:
.CTLCOLOR_BTN 按钮控件
.CTLCOLOR_DLG 对话框
.CTLCOLOR_EDIT 编辑框
.CTLCOLOR_LISTBOX 列表控件
.CTLCOLOR_MSGBOX 消息控件
.CTLCOLOR_SCROLLBAR 滚动条控件
.CTLCOLOR_STATIC 静态控件
[程序实现]
假设你已有了名为My的对话框工程.你有了一个STATIC的控件,ID为IDC_STATIC1.
HBRUSH CMyDlg::OnCtlColor(CDC*
pDC, CWnd*
pWnd, UINT nCtlColor)
{
HBRUSH hbr
= CDialog::OnCtlColor(pDC, pWnd,
nCtlColor);
// TODO: Change any attributes
of the DC here
if (nCtlColor==CTLCOLOR_STATIC)
{
pDC-> SetTextColor(RGB(255,0,0)); //字体颜色
pDC-> SetBkColor(RGB(0, 0,
255)); //字体背景色
}
// TODO: Return a
different brush if the default is not
desired
return hbr;
}
如果要指定某个特定控件可以这样写:ID为IDC_STATIC1
if (pWnd-> GetDlgCtrlID()==IDC_STATIC1)
{
pDC-> SetTextColor(RGB(255,0,0)); //设置字体颜色
pDC-> SetBkMode(TRANSPARENT); //设置字体背景为透明
// TODO: Return a different brush if the default is
not desired
return (HBRUSH)::GetStockObject(BLACK_BRUSH); //
设置背景色
}
else
return hbr;
【注】
BLACK_BRUSH:黑色
WHITE_BRUSH:白色
GRAY_BRUSH:灰色
NULL_BRUSH:透明
HOLLOW_BRUSH :透明
afx_msg HBRUSH OnCtlColor(CDC *pDC,CWnd *pWnd,UINT
nCtlColor);
参数nCtlColor用于指定控件的类型,可以是:
.CTLCOLOR_BTN 按钮控件
.CTLCOLOR_DLG 对话框
.CTLCOLOR_EDIT 编辑框
.CTLCOLOR_LISTBOX 列表控件
.CTLCOLOR_MSGBOX 消息控件
.CTLCOLOR_SCROLLBAR 滚动条控件
.CTLCOLOR_STATIC 静态控件
[程序实现]
假设你已有了名为My的对话框工程.你有了一个STATIC的控件,ID为IDC_STATIC1.
HBRUSH CMyDlg::OnCtlColor(CDC*
pDC, CWnd*
pWnd, UINT nCtlColor)
{
HBRUSH hbr
= CDialog::OnCtlColor(pDC, pWnd,
nCtlColor);
// TODO: Change any attributes
of the DC here
if (nCtlColor==CTLCOLOR_STATIC)
{
pDC-> SetTextColor(RGB(255,0,0)); //字体颜色
pDC-> SetBkColor(RGB(0, 0,
255)); //字体背景色
}
// TODO: Return a
different brush if the default is not
desired
return hbr;
}
如果要指定某个特定控件可以这样写:ID为IDC_STATIC1
if (pWnd-> GetDlgCtrlID()==IDC_STATIC1)
{
pDC-> SetTextColor(RGB(255,0,0)); //设置字体颜色
pDC-> SetBkMode(TRANSPARENT); //设置字体背景为透明
// TODO: Return a different brush if the default is
not desired
return (HBRUSH)::GetStockObject(BLACK_BRUSH); //
设置背景色
}
else
return hbr;
【注】
BLACK_BRUSH:黑色
WHITE_BRUSH:白色
GRAY_BRUSH:灰色
NULL_BRUSH:透明
HOLLOW_BRUSH :透明
相关文章推荐
- 用&a 4000 mp;nbsp;MFC 类库编程实现工作者线程
- 【转载】MFC实现串口通信编程 - yu…
- mfc,WM_CTLCOLOR,WM_PAINT
- 重置VS2005设置/Reset VS2005 settings
- 线段树 count color
- MFC获取文档 视图 程序 框架类的指…
- VS2005 Web Application Project的一些问题
- MFC应用程序中指针的使用
- MFC+SQL server 数据库…
- 重置VS2005设置/Reset VS2005 settings
- MFC无法为控件添加变量(Add Variab…
- 安卓 setTextColor()的参数设置方…
- VS2005 Web Application Project的一些问题
- MFC/Windows_WM_CTLCOLOR消息
- MFC-WM_CTLCOLOR消息绘制控件颜色
- MFC笔记(2)OnCtrlColor
- 如何: 如何禁用在 MFC&…
- VC MFC SDI/MDI框架各部分指针获取…
- MFC 颜色对话框 字体对话框 WM_CTLCOLOR消息总结
- matlab colorbar 绘图中显示颜色条