CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2001
    Location
    jordan
    Posts
    63

    freeing gdi resources

    Hi
    I have global variables :
    CDC g_dc;
    CBitmap g_bmp;

    both of these are deleted and recreated in OnSize
    Code:
       
       ...
        
        g_bmp.DeleteObject();  
        g_dc.DeleteDC();
    
        g_dc.CreateCompatibleDC(&ScreenDC);
        g_bmp.CreateCompatibleDC(&g_dc, newWidth, newHeight); 
       
        ...
    the resources don't seem to be freed correctly, because after
    resizing the window a few times, the application cannot create a bitmap anymore using CreateCompatibleBitmap(..)

    what can i do to fully free the resources?

    thanks

    awni

  2. #2
    Join Date
    Sep 2002
    Location
    DC Metro Area, USA
    Posts
    1,509
    This would not be my prefered approach; I'd tend to put the bitmap creation in the paint handler and either create the global dc once, or as needed in the paint (The compatible DC does not need to be recreated on size or bitmap changes). Other than that, you need to ensure that the bitmap is not selected into the DC when you delete it.
    bytz
    --This signature left intentionally blank--

  3. #3
    Join Date
    Sep 1999
    Location
    malaysia
    Posts
    191
    Hi Awni,

    Before you DeleteObject(), you need to select the old bitmap back into DC...maybe thats what eating up resources...

    Code:
    CBitmpap* pOldBitmap=g_dc.SelectObject(&g_bmp);
    
    //use it then
    
    g_dc.SelectObject(pOldBitmap);// selecting back the original bitmap
    
    g_bmp.DeleteObject();
    
    //etc
    Hope that helps

    Regards

    Mustafa
    ______________________________
    To err is human, it's the computer that causes blunders !!!

    DO: Dazzle me with your intelligence
    DON'T : Confuse me with your bullshit

  4. #4
    Join Date
    Jul 2001
    Location
    jordan
    Posts
    63
    thanks everyone

    resources are being freed as they should be
    awni

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured