CBitmap bitmapBkgnd; bitmapBkgnd.Attach (LoadBitmap (AfxGetInstanceHandle(), MAKEINTRESOURCE(m_iBitmapId))); BOOL CTestbed2Dlg::OnEraseBkgnd(CDC* pDC) { CRect rect; GetClientRect(&rect); CDC dc; dc.CreateCompatibleDC(pDC); CBitmap* pOldBitmap = dc.SelectObject(&bitmapBkgnd); int iBitmapWidth, iBitmapHeight ; int ixOrg, iyOrg; BITMAP bm; bitmapBkgnd.GetObject(sizeof(BITMAP),&bm); iBitmapWidth = bm.bmWidth; iBitmapHeight = bm.bmHeight; // If our bitmap is smaller than the background and tiling is // supported, tile it. Otherwise watch the efficiency - don't // spend time setting up loops you won't need. if (iBitmapWidth >= rect.Width() && iBitmapHeight >= rect.Height() ) { pDC->BitBlt (rect.left, rect.top, rect.Width(), rect.Height(), &dc, 0, 0, SRCCOPY); } else { for (iyOrg = 0; iyOrg < rect.Height(); iyOrg += iBitmapHeight) { for (ixOrg = 0; ixOrg < rect.Width(); ixOrg += iBitmapWidth) { pDC->BitBlt (ixOrg, iyOrg, rect.Width(), rect.Height(), &dc, 0, 0, SRCCOPY); } } } dc.SelectObject(pOldBitmap); return TRUE; }