阿诺德·施瓦辛格样子:文本框字体色,对话框和静态文件背景色设置方法(OnCtlColor消息)
来源:百度文库 编辑:偶看新闻 时间:2024/10/05 21:12:57
在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 :透明
EditView设置背景色
怎么样恢复网页的字体和背景色?
flash如何设置背景色?
如何设置网页背景色
JLabel怎么样设置背景色?
Authorware7中导入图片后如何设置前景色和背景色
怎样改变psp看电子书时候的背景色和字体颜色?
如何给WORD设置背景色?
VC中如何设置dlg背景色?
CoreDraw如何设置文字的背景色?
如何设置QQ空间的背景色?
在VB.NET中如何将窗体、按钮和标签的背景色设置为透明?
photoshop中的前景色和背景色到底该怎样区别?
PS中蒙版的前景色和背景色怎么修改?
怎么调PS的“前景色”和“背景色”啊?
前景色 背景色
请教VC怎样改变静态文本框的说明文字(captions)的字体,3Q
qq 空间的问题,如何设置留言板的背景色?
演示文稿的背景色 要求 是 金色 怎么设置?
CoreDraw中如何设置文字的背景色呢?
HTML中text的背景色,如何设置?
如何在PS中设置背景色为黑色!
请教:VB操作EXCEL怎么设置一行的背景色?
百度空间背景色的半透明设置,怎么做??