请问如何改变一个static控件的背景颜色?
解决方案 »
- 如何导出MYSQL的结果集呐?
- VC突然有问题了,请教熟悉的大虾
- 在evc下,如何播放大型的wav音乐文件
- 因不同用户的操作权限不一样,怎样使菜单部分隐藏起来?
- 初学,问一个VC中getch()的问题
- 怎么处理MDI里的MDIChildWnd(初始化程序时候不产生子窗口)?
- ATL开发COM的问题,很简单的问题,可小弟迷惑!!
- 为什么受伤的总是我? 关注 关注 !!!!!
- ocx 在本地通过ie D:/a.html 能访问能显示,发布后http://localhost/a.html不能访问不显示
- 关于OICQ的msg.db,高分相送
- 如何在自己写的DLL里面加入版本信息?
- 我要怎么做才能学好VC呢?郁闷呵~~~~
HBRUSH CZilchDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
// Call the base class implementation first! Otherwise, it may
// undo what we're trying to accomplish here.
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); // Are we painting the IDC_MYSTATIC control? We can use
// CWnd::GetDlgCtrlID() to perform the most efficient test.
if (pWnd->GetDlgCtrlID() == IDC_MYSTATIC)
{
// Set the text color to red
pDC->SetTextColor(RGB(255, 0, 0)); // Set the background mode for text to transparent
// so background will show thru.
pDC->SetBkMode(TRANSPARENT); // Return handle to our CBrush object
//hbr = m_brush;
} return hbr;
}
st->SetBkColor(RGB(255,0,0));
HBRUSH CLBView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor); if(pWnd->GetDlgCtrlID()==IDC_MYSTATIC)
{
pDC->SetBkColor(...);
hbr=m_brush;
}
return hbr;
}
//上面那个if(pWnd->GetDlgCtrlID() == IDC_MYSTATIC)在VC6下大概只能这样:
if(pWnd == GetDlgItem( IDC_MYSTATIC ))
我这样做,不行
HBRUSH CSamplesView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
pWnd=GetDlgItem(IDC_GASCON);
if(pWnd==GetDlgItem(IDC_GASCON))
{
pDC->SetBkColor(RGB(255,255,255));
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
CBrush brush;
初始化
brush.CreateSolidBrush(RGB(0,0,255));
HBRUSH CSamplesView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
pWnd=GetDlgItem(IDC_GASCON);
if(pWnd==GetDlgItem(IDC_GASCON))
{
retrun (HBRUSH)brush.m_hObject ;
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
补充:用SetBkColor设成与画刷相同的RGB颜色HBRUSH CSamplesView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
pWnd=GetDlgItem(IDC_GASCON);
if(pWnd==GetDlgItem(IDC_GASCON))
{
pDC->SetBkColor(RGB(0,0,255));
retrun (HBRUSH)brush.m_hObject ;
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
或在CStatic的派生类中响应WM_CTLCOLOR_REFLACT反射消息。