I have an SDI / CView app (VS 2010). All works well until I minimize the app using the minimize button or drag it partially off of the screen. In the former instance, any attempt to restore the app results in an appcrash with a tight freeze up of the machine. In the later instance the same happens immediately.

In building the app, I scoured the web for code to accomplish the loading and display of the bitmap. After some experimentation I settled on overriding the OnPaint. Below is the code. Note that m_Map is a CBitmap member and IDB_BITMAP1 is a loaded bitmap resource.

 void CMyDragViewView::OnPaint()
	// CPaintDC dc(this); // device context for painting
	 // TODO: Add your message handler code here
	 // Do not call CView::OnPaint() for painting messages

	// http://msgroups.net/microsoft.public.vc.mfc/loading-bitmaps-into-main-window/563285
	int x = m_Map.LoadBitmap(IDB_BITMAP1);
	TRACE1(" x = %d\n", x);
	CPaintDC* dc = new CPaintDC(this);
	CDC cdc;
	CBitmap* pOldBitmap = cdc.SelectObject(&m_Map);
	BITMAP MapInfo;
	m_Map.GetObject(sizeof(MapInfo), &MapInfo);
	dc->BitBlt(0, 0, MapInfo.bmWidth, MapInfo.bmHeight, &cdc, 0, 0, SRCCOPY);


I suspect that the problem is OnPaint trying to repaint the bitmap which requires reloading it, but I don't know how to work around this.

Any help greatly appreciated.