CLabelEx继承CStatic类重载以下消息函数
HBRUSH CLabelEx::CtlColor(CDC *pDC, UINT nCtlColor)
{
if (m_bHover)
pDC->SetTextColor(m_clrHotText);
else
pDC->SetTextColor(m_clrText); pDC->SetBkColor(m_clrBack);
return (HBRUSH)m_brBkgnd;
}
用MoveWindow(CRect)函数确定改CLabelEx对象的位置和大小问题是为什么设置的背景色只是显示在文字的后面,而没有对整个CStatic控件进行填充呢????
HBRUSH CLabelEx::CtlColor(CDC *pDC, UINT nCtlColor)
{
if (m_bHover)
pDC->SetTextColor(m_clrHotText);
else
pDC->SetTextColor(m_clrText); pDC->SetBkColor(m_clrBack);
return (HBRUSH)m_brBkgnd;
}
用MoveWindow(CRect)函数确定改CLabelEx对象的位置和大小问题是为什么设置的背景色只是显示在文字的后面,而没有对整个CStatic控件进行填充呢????
CRect rcBounds;
GetClientRect(&rcBounds);
CPoint pt=GetScrollPosition();
rcBounds+=pt;
pDC->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
// This OnCtlColor handler will change the color of a static control
// with the ID of IDC_MYSTATIC. The code assumes that the CMyDialog
// class has an initialized and created CBrush member named m_brush.
// The control will be painted with red text and a background
// color of m_brush.HBRUSH CZilchDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
// Call the base class implementation first! Otherwise, it may
// undo what we are 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;
}