February 10th, 2013, 11:58 AM
Problem with SDI CView covered with bitmap resource
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.
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.
// CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// Do not call CView::OnPaint() for painting messages
int x = m_Map.LoadBitmap(IDB_BITMAP1);
TRACE1(" x = %d\n", x);
CPaintDC* dc = new CPaintDC(this);
CBitmap* pOldBitmap = cdc.SelectObject(&m_Map);
dc->BitBlt(0, 0, MapInfo.bmWidth, MapInfo.bmHeight, &cdc, 0, 0, SRCCOPY);
Any help greatly appreciated.
Click Here to Expand Forum to Full Width