Problem with SDI CView covered with bitmap resource
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Problem with SDI CView covered with bitmap resource

  1. #1
    Join Date
    May 2002
    Posts
    1,717

    Problem with SDI CView covered with bitmap resource

    I have an SDI / CView app (VS 2010). All works well until I minimize the app using the minimize button or drag it partially off of the screen. In the former instance, any attempt to restore the app results in an appcrash with a tight freeze up of the machine. In the later instance the same happens immediately.

    In building the app, I scoured the web for code to accomplish the loading and display of the bitmap. After some experimentation I settled on overriding the OnPaint. Below is the code. Note that m_Map is a CBitmap member and IDB_BITMAP1 is a loaded bitmap resource.

    Code:
     void CMyDragViewView::OnPaint()
     {
    	// CPaintDC dc(this); // device context for painting
    	 // TODO: Add your message handler code here
    	 // Do not call CView::OnPaint() for painting messages
    
    	// http://msgroups.net/microsoft.public.vc.mfc/loading-bitmaps-into-main-window/563285
    	int x = m_Map.LoadBitmap(IDB_BITMAP1);
    	TRACE1(" x = %d\n", x);
    	CPaintDC* dc = new CPaintDC(this);
    	CDC cdc;
    	cdc.CreateCompatibleDC(dc);
    	CBitmap* pOldBitmap = cdc.SelectObject(&m_Map);
    	BITMAP MapInfo;
    	m_Map.GetObject(sizeof(MapInfo), &MapInfo);
    	dc->BitBlt(0, 0, MapInfo.bmWidth, MapInfo.bmHeight, &cdc, 0, 0, SRCCOPY);
    
    	cdc.SelectObject(pOldBitmap);
    
     }
    I suspect that the problem is OnPaint trying to repaint the bitmap which requires reloading it, but I don't know how to work around this.

    Any help greatly appreciated.
    mpliam

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,286

    Re: Problem with SDI CView covered with bitmap resource

    Quote Originally Posted by Mike Pliam View Post
    Code:
     void CMyDragViewView::OnPaint()
     {
    	// CPaintDC dc(this); // device context for painting
    	 // TODO: Add your message handler code here
    	 // Do not call CView::OnPaint() for painting messages
    
    	// http://msgroups.net/microsoft.public.vc.mfc/loading-bitmaps-into-main-window/563285
    	int x = m_Map.LoadBitmap(IDB_BITMAP1);
    	TRACE1(" x = %d\n", x);
    	CPaintDC* dc = new CPaintDC(this);
    	CDC cdc;
    	cdc.CreateCompatibleDC(dc);
    	CBitmap* pOldBitmap = cdc.SelectObject(&m_Map);
    	BITMAP MapInfo;
    	m_Map.GetObject(sizeof(MapInfo), &MapInfo);
    	dc->BitBlt(0, 0, MapInfo.bmWidth, MapInfo.bmHeight, &cdc, 0, 0, SRCCOPY);
    
    	cdc.SelectObject(pOldBitmap);
     }
    I suspect that the problem is OnPaint trying to repaint the bitmap which requires reloading it, but I don't know how to work around this.
    Mike, I don't understand your problem with "minimize the app" but your code produces a series of memory leaks!
    Why do you create CPaintDC instance in the heap?
    Why don't you free it?
    Victor Nijegorodov

  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,927

    Re: Problem with SDI CView covered with bitmap resource

    Mike, you're not an absolute beginner here on the forum. So I do not understand why you prefer asking elementary questions along with descriptions that explain nothing instead of trivial modelling your problem in a standalone app, and posting it here in case the problem remains. This is not the first time when you get real help this and only this way. Please see the working sample and compare it with your code.
    Attached Files Attached Files
    Best regards,
    Igor

  4. #4
    Join Date
    May 2002
    Posts
    1,717

    Re: Problem with SDI CView covered with bitmap resource

    Victor, I am clearly not experienced in building custom MFC interfaces as I have spent most of my efforts in dealing with mathematical and statistical code underlying my applications, so in that sense, I am very much a beginner when it comes to interfaces. Igor, your point is well taken and I respect it. I apologize for not posting a demo app but yours works beautifully. Once again I am greatly indebted to you both and to Codeguru from whence most of my programming knowledge has come from. Thank you both.
    mpliam

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center