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?

thx

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();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

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

		CBitmap bitmap;
		
		bitmap.m_hObject = bmaphandle;
		
		mdc->SelectObject(bitmap);
		CRect rect;
		GetClientRect(&rect);

		dc.BitBlt(0,0,rect.right,rect.bottom,mdc,0,0,SRCCOPY);

		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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.