bitmap dissapears on window resize

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jan 2008
Posts: 119
Reputation: kux is on a distinguished road 
Solved Threads: 10
kux kux is offline Offline
Junior Poster

bitmap dissapears on window resize

 
0
  #1
Nov 18th, 2008
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

  1. BOOL CImageFilterDoc::OnOpenDocument( LPCTSTR strFilename )
  2. {
  3. if ( ( m_hBitmap = (HBITMAP)LoadImage(NULL, strFilename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE) ) == NULL )
  4. return FALSE;
  5.  
  6. return TRUE;
  7.  
  8. }
  9.  
  10. void CImageFilterView::OnDraw(CDC* pDC)
  11. {
  12. CImageFilterDoc* pDoc = GetDocument();
  13. ASSERT_VALID(pDoc);
  14. if (!pDoc)
  15. return;
  16.  
  17. // TODO: add draw code for native data here
  18. HBITMAP bmaphandle = pDoc->GetHandleToBitmap();
  19. if ( bmaphandle )
  20. {
  21. CClientDC dc(this);
  22. CDC *mdc=new CDC;
  23. mdc->CreateCompatibleDC(&dc);
  24.  
  25. CBitmap bitmap;
  26.  
  27. bitmap.m_hObject = bmaphandle;
  28.  
  29. mdc->SelectObject(bitmap);
  30. CRect rect;
  31. GetClientRect(&rect);
  32.  
  33. dc.BitBlt(0,0,rect.right,rect.bottom,mdc,0,0,SRCCOPY);
  34.  
  35. delete mdc;
  36.  
  37. }
  38. }
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,936
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 305
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Cenosillicaphobiac

Re: bitmap dissapears on window resize

 
0
  #2
Nov 18th, 2008
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
Last edited by niek_e; Nov 18th, 2008 at 9:11 am.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 119
Reputation: kux is on a distinguished road 
Solved Threads: 10
kux kux is offline Offline
Junior Poster

Re: bitmap dissapears on window resize

 
0
  #3
Nov 19th, 2008
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
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC