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;
}
}