Thread: WM_PAINT and PeekMessage

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    36

    GDI leaks

    Edit: Can't change thread title...This problem is not really related to PeekMessage.

    Nevermind my earlier post, I have a working draw routine, but it leaks GDI resources by the thousands...

    Code:
    	
    HBITMAP hbmOld;
    	
    HDC hdc = GetDC(hwnd);
    HDC hdcMem = CreateCompatibleDC(hdc);
    hbmTemp = CreateCompatibleBitmap(hdc, 256, 240);
    	
    SetDIBits(hdcMem, hbmTemp, 0, 256, bmMainBits, bmiMain, DIB_RGB_COLORS);
    	
    hbmOld = SelectObject(hdcMem, hbmTemp);
    BitBlt(hdc, 0, 0, 240, 256, hdcMem, 0, 0, SRCCOPY);
    
    SelectObject(hdcMem, hbmOld);
    DeleteDC(hdcMem);
    ReleaseDC(hwnd, hdc);
    I clean up the compatible DC with DeleteDC, I clean up the window DC with ReleaseDC and select the default bitmap before I delete the memory DC. I read the MSDN section several times but I still can't see what I'm leaking.
    Last edited by Gerread; 03-23-2007 at 11:37 PM. Reason: old problem solved, new problem though

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    1. Check the return values
    If the function fails, the return value is zero.

    Windows NT/2000/XP: To get extended error information, call GetLastError.
    2.
    CreateCompatibleBitmap creates a DIB section.

    When you no longer need the bitmap, call the DeleteObject function to delete it.
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Jun 2006
    Posts
    36
    When you no longer need the bitmap, call the DeleteObject function to delete it.
    That patched up the leaks. Thanks!.

Popular pages Recent additions subscribe to a feed