End Google Ads 201810 - BS.net 01 --> I have a SDI project. I try to change the background colors of both its View and Frame.

For the View, i try :


CMyView::CmainframeView()
{
// CBrush m_brush is a member of CMyView class
m_brush.CreateSolidBrush(RGB(100, 255, 100));
}

BOOL CMyView::OnEraseBkgnd(CDC* pDC)
{
return TRUE;
}

void CMyView::OnDraw(CDC* pDC)
{
pDC->SelectObject(&m_brush);
CRect rect;
pDC->GetClipBox(&rect);
pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), PATCOPY);
}


and it works really well ! But when i try to change background color of CMyFrame :


int CMyFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
//CBrush m_brush is a member of CMyFrame
m_brush.CreateSolidBrush(RGB(255, 0, 100));
}

BOOL CMyFrame::OnEraseBkgnd(CDC* pDC)
{
return TRUE;
}

void CMyFrame::OnPaint()
{
CPaintDC pDC(this); // device context for painting

pDC.SelectObject(&m_brush);

CRect rect;
pDC.GetClipBox(&rect);
pDC.Rectangle(rect);
pDC.PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), PATCOPY);
}


the background color only changes when the window is resize, but it flirt. I also try to hande WM_SIZE message but it doesn't help. Can you give me some suggestions ?