Windows向窗口发送一个WM_ERASEBKGND消息通知该窗口擦除背景,可以使用ClassWizard重载该消息的缺省处理程序来擦除背景(实际是画),并返回TRUE以防止Windows擦除窗口。
//Paint area that needs to be erased.
BOOL CSampleView : : OnEraseBkgnd (CDC* pDC)
{
// Create a pruple brush.
CBrush Brush (RGB (128 , 0 , 128) )// Select the brush into the device context .
CBrush* pOldBrush = pDC—>SelcetObject (&brush)// Get the area that needs to be erased .
CRect reClip
pDC—>GetCilpBox (&rcClip)
//Paint the area.
pDC—> PatBlt (rcClip.left , rcClip.top , rcClip.Width ( ) , rcClip.Height( ) , PATCOPY )//Unselect brush out of device context .
pDC—>SelectObject (pOldBrush )// Return nonzero to half fruther processing .
return TRUE
}
//Paint area that needs to be erased.
BOOL CSampleView : : OnEraseBkgnd (CDC* pDC)
{
// Create a pruple brush.
CBrush Brush (RGB (128 , 0 , 128) )// Select the brush into the device context .
CBrush* pOldBrush = pDC—>SelcetObject (&brush)// Get the area that needs to be erased .
CRect reClip
pDC—>GetCilpBox (&rcClip)
//Paint the area.
pDC—> PatBlt (rcClip.left , rcClip.top , rcClip.Width ( ) , rcClip.Height( ) , PATCOPY )//Unselect brush out of device context .
pDC—>SelectObject (pOldBrush )// Return nonzero to half fruther processing .
return TRUE
}
protected: afx_msg BOOL OnEraseBkgnd(CDC* pDC);
在你的YourFormView的.cpp文件中加入
BEGIN_MESSAGE_MAP(CYourFormView, CFormView)
//{{AFX_MSG_MAP(CFormViewTestView)
//}}AFX_MSG_MAP
ON_WM_ERASEBKGND()
END_MESSAGE_MAP()
BOOL CYourFormView::OnEraseBkgnd(CDC* pDC)
{
CFormView::OnEraseBkgnd(pDC);
CRect rect;
GetClientRect(rect);
CBrush m_yourbkBrush(RGB(100,0,0));
pDC->FillRect(&rect, &m_yourbkBrush);
return TRUE;
}