I have a document/view aplication that opens a bitmap

I use the following OnDraw override to draw the bitmap on a window and OnOpenDocument to opening the image from file

The bitmap handle ( HBITMAP bmaphandle ) is taken from the Document object that does LoadImage in it's OnOpenDocument method
HBITMAP bmaphandle = pDoc->GetHandleToBitmap();

The problem I have is that on resizeing the window or when i move another window over it the image dissapears from the view. How do I make it persistent?


BOOL CImageFilterDoc::OnOpenDocument( LPCTSTR strFilename )
	if ( ( m_hBitmap = (HBITMAP)LoadImage(NULL, strFilename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE) )  == NULL ) 
		return FALSE;

	return TRUE;


void CImageFilterView::OnDraw(CDC* pDC)
	CImageFilterDoc* pDoc = GetDocument();
	if (!pDoc)

	// TODO: add draw code for native data here
	HBITMAP bmaphandle = pDoc->GetHandleToBitmap();
	if ( bmaphandle )
		CClientDC dc(this);
		CDC *mdc=new CDC;

		CBitmap bitmap;
		bitmap.m_hObject = bmaphandle;
		CRect rect;


		delete mdc;


I'm not sure, and I haven't done this for a few years, but you could try a this->refresh() when you're done resizing

Ok, i found the problem.
The CBitmap bitmap object from OnDraw(CDC*) took a handle to the bitmap and on destruction deleted the object pointed by the handle

This question has already been answered. Start a new discussion instead.