943,513 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 895
  • C++ RSS
Nov 18th, 2008
0

bitmap dissapears on window resize

Expand Post »
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

C++ Syntax (Toggle Plain Text)
  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. }
kux
Reputation Points: 66
Solved Threads: 11
Junior Poster
kux is offline Offline
119 posts
since Jan 2008
Nov 18th, 2008
0

Re: bitmap dissapears on window resize

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 Nick Evan; Nov 18th, 2008 at 9:11 am.
Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is offline Offline
4,132 posts
since Oct 2006
Nov 19th, 2008
0

Re: bitmap dissapears on window resize

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
kux
Reputation Points: 66
Solved Threads: 11
Junior Poster
kux is offline Offline
119 posts
since Jan 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Question regarding base class and derived class
Next Thread in C++ Forum Timeline: Confusions related to Dll.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC