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 shabbir; 8Apr2012 at 08:34.. Reason: Code blocks