Skip to main content

MFC: Fill the Client area with a bitmap

· One min read

In MFC to fill the client area with a bitmap use the following code.

BOOL CMySDIView::OnEraseBkgnd(CDC\* pDC)
{
CDC mymem;
//Create a dc to represent display surface
mymem.CreateCompatibleDC(pDC);

CBitmap bmp;
bmp.LoadBitmap(IDB\_MYBITMAP);
mymem.SelectObject(&bmp);

//BitBlt Copyes bitbamp from source (mymem) to destination (pDC)
pDC->BitBlt(0,0,740, 520, &mymem,0,0, SRCCOPY);

return TRUE; // CView::OnEraseBkgnd(pDC);
}