vc中,为什么无法改变静态控件的背景色?????
来源:百度知道 编辑:UC知道 时间:2024/05/22 17:41:44
我的程序是这个样子的:
HBRUSH CInforDispDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
CBrush m_brush;
m_brush.CreateSolidBrush(RGB(0,255,0));
// TODO: Change any attributes of the DC here
switch (pWnd->GetDlgCtrlID())
{
case IDC_STATIC_PERCHECK:
// Set text color about STATIC
pDC->SetTextColor(RGB(255,255,255));
pDC->SetBkMode(TRANSPARENT);
return m_brush;
default:
// Set background mode about STATIC
break;
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
但是,IDC_STATIC_PERCHECK静态控件的背景色始终无法改变,为什么?请赐教!!!!
这两个答案都不行, 要得是整个控件的背景色改变,而不是单纯的字体背景色。
HBRUSH CInforDispDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
CBrush m_brush;
m_brush.CreateSolidBrush(RGB(0,255,0));
// TODO: Change any attributes of the DC here
switch (pWnd->GetDlgCtrlID())
{
case IDC_STATIC_PERCHECK:
// Set text color about STATIC
pDC->SetTextColor(RGB(255,255,255));
pDC->SetBkMode(TRANSPARENT);
return m_brush;
default:
// Set background mode about STATIC
break;
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
但是,IDC_STATIC_PERCHECK静态控件的背景色始终无法改变,为什么?请赐教!!!!
这两个答案都不行, 要得是整个控件的背景色改变,而不是单纯的字体背景色。
你好,希望我的回答对你有所帮助.
1.这是我写的例子,在VC6下编译通过,工程下载地址:http://sites.google.com/site/qiujiejia1/Home/Static_Background.zip
2.我返回的刷子是定义为成员变量的,并且在构造函数理初始化的
(1)CBrush m_RuntimeValueBkBrush;
(2)m_RuntimeValueBkBrush.CreateSolidBrush(RGB(46,89,121));
3.以下是工程的部分代码,仅供参考.
HBRUSH CDemoDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
switch(pWnd->GetDlgCtrlID())
{
case IDC_STATIC1:
case IDC_STATIC2:
case IDC_STATIC3:
case IDC_STATIC4:
case IDC_STATIC5:
{
pDC->SetTextColor(RGB(0, 255, 255));
pDC->SetB