Double buffering problem

Discussion in 'Win32' started by kmudrovc, Apr 7, 2012.

  1. kmudrovc

    kmudrovc New Member

    Joined:
    Apr 7, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi, i want to periodically draw images on extended desktop and i cannot seem to do it double buffered. The screenflickers when drawing fast. Here is my code:

    Code:
    void SendImageToWindow(HWND WindowHandle, int horRes, int vertRes)
    {
        // get window handle
        HDC hdc = GetDC(WindowHandle);
    
        // increase counter
        ++counter;
        counter = counter % NUMBER_OF_COLORS;
    
        HDC dc = CreateCompatibleDC(hdc);
        HBITMAP hBitmap = CreateCompatibleBitmap (hdc, w, h);
        SelectObject(dc, hBitmap);
    
        InvalidateRect(WindowHandle, NULL, FALSE);
        UpdateWindow(WindowHandle);
    
        // get client rect
        GetClientRect(WindowHandle, &rcMonitor2);
    
        
    
        // create brush
        HBRUSH hBrush = CreateSolidBrush(RGB(colorTable[counter].r,colorTable[counter].g,colorTable[counter].b));
       
        FillRect(dc, &rcMonitor2, hBrush);
    
        // delete brush
        DeleteObject(hBrush);
    
        BitBlt(hdc, 0, 0, w, h, dc, 0, 0, SRCCOPY);
    
        ReleaseDC(0, dc);
        ReleaseDC(0, hdc);
        DeleteObject(hBitmap);
        DeleteDC(dc);
        DeleteDC(hdc);
    }
    
    What am i doing wrong?

    Thank you
     
    Last edited by a moderator: Apr 8, 2012

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice