Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Win32 (http://www.go4expert.com/forums/win32/)
-   -   Double buffering problem (http://www.go4expert.com/forums/double-buffering-problem-t28150/)

kmudrovc 8Apr2012 03:05

Double buffering problem
 
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


All times are GMT +5.5. The time now is 13:55.