i'm getting flickers on windows. the windows have CW_USEDEFAULT size and i use the WS_CLIPCHILDREN.
on WM_PAINT i use my image class with client rect size.
it's big. but not more big than screen.
the WM_PAINT:

case WM_ERASEBKGND:
                {
                    return (LRESULT)1;;
                }
                break;

                case WM_PAINT:
                {
                    PAINTSTRUCT  ps;
                    BeginPaint(inst->hwnd, &ps);
                    RECT a;
                    GetClientRect(inst->hwnd, &a);

                    image imgpaint(a.right,a.bottom);//creates an image with form\window size
                    imgpaint.Brush(inst->clrBackColor);
                    pen test;
                    imgpaint.Pen(test);
                    imgpaint.DrawRectangle(0,0,imgpaint.width()+1, imgpaint.height()+1);
                    if (inst->Paint!=NULL)
                        inst->Paint(imgpaint);
                    //draws the image on HDC form\window
                    BitBlt(ps.hdc, inst->pntScrollDC.x,inst->pntScrollDC.y , imgpaint.width(), imgpaint.height(), imgpaint,0 ,0, SRCCOPY);
                    //inst->pntScrollDC it's the scroll position, but on start it's 0(zero)
                    EndPaint(inst->hwnd, &ps);
                    return 0;
                }
                break;

and see the Refresh() function:

void Refresh()
        {
            RECT a;
            GetClientRect(hwnd,&a);
            InvalidateRect(hwnd,&a,FALSE);
        }

creating the window:

hwnd = CreateWindowEx(WS_EX_LAYERED,classname, strCaption.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN,
                                  CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, parent, NULL, mod, this);

showing these: how can i avoid the flickers on form?
(i use a timer animation in these situation)
i can Refresh() the window with a RECT, but the brush color must be changed to backcolor;

Edited 1 Year Ago by cambalinho

You need to either double buffer the window/painting OR use a Real-Time-Message-Loop (this option is usually used in OpenGL & Direct-X in combination with a double buffer. It can also be used with a single buffer just fine)..

while(true)
{
    while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    if(msg.message == WM_QUIT)
        break;

    onDraw(msg.hwnd, msg.message, msg.wParam, msg.lParam);
}


void onDraw(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    //BitBlit or draw whatever you want here..

    Sleep(1); //might not be needed but is a good idea..
}

Note: You do not need to invalidate the window with the above.

Edited 1 Year Ago by triumphost

the problem was that i was drawing 2 times on HDC control(background color and image). so i did another double buffering and no more flickers ;)
thanks for all

This question has already been answered. Start a new discussion instead.