WM_PAINT and PeekMessage

This is a discussion on WM_PAINT and PeekMessage within the Windows Programming forums, part of the Platform Specific Boards category; Edit: Can't change thread title...This problem is not really related to PeekMessage. Nevermind my earlier post, I have a working ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,456
    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.
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21