CListCtrl::SetBkColor BOOL SetBkColor( COLORREF cr );Return ValueNonzero if successful; otherwise zero.ParameterscrBackground color to set, or the CLR_NONE value for no background color. List view controls with background colors redraw themselves significantly faster than those without background colors. For information, seeCOLORREF in the Platform SDK.ResSets the background color of the list view control.Example// The pointer to my list view control. extern CListCtrl* pmyListCtrl;// Use the 3D button face color for the background. COLORREF crBkColor = ::GetSysColor(COLOR_3DFACE); pmyListCtrl->SetBkColor(crBkColor); ASSERT(pmyListCtrl->GetBkColor() == crBkColor);CListCtrl Overview | Class Members | Hierarchy ChartSee Also CListCtrl::GetBkColor
响应WM_CTLCOLOR消息,返回一个HBRUSH. OnCtlColorHBRUSH 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; }
BOOL SetBkColor( COLORREF cr );Return ValueNonzero if successful; otherwise zero.ParameterscrBackground color to set, or the CLR_NONE value for no background color. List view controls with background colors redraw themselves significantly faster than those without background colors. For information, seeCOLORREF in the Platform SDK.ResSets the background color of the list view control.Example// The pointer to my list view control.
extern CListCtrl* pmyListCtrl;// Use the 3D button face color for the background.
COLORREF crBkColor = ::GetSysColor(COLOR_3DFACE);
pmyListCtrl->SetBkColor(crBkColor);
ASSERT(pmyListCtrl->GetBkColor() == crBkColor);CListCtrl Overview | Class Members | Hierarchy ChartSee Also CListCtrl::GetBkColor
COLORREF m_clrBack;
CBrush brush;在构造函数中
m_clrBack=RGB(255,0,0);
brush.createsolidbrush(m_clrBack);处理WM_CTLCOLOR消息
pDC->setbkcolor(m_clrBack);
return (HBRUSH)brush.getsafehandle();
OnCtlColorHBRUSH 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;
}