WS_CLIPCHILDREN and InvalidateRect Behavior on Windows 7

To reduce flickering, I create parent windows using the WS_CLIPCHILDREN flag, and call InvalidateRect during the WM_SIZE event. This approach has worked well in Windows XP. However, I recently started programming in Windows 7, and now I'm having trouble rendering when resizing windows. When the window is resized, its contents are not updated until I do something that forces me to redraw, for example, minimize and restore the window.

I tried to execute an InvalidateRect with an UpdateWindow call, but with no effect.

Does anyone know how to do this correctly?

Update
I found a workaround: a call InvalidateRect(childHWND, NULL, FALSE) on all child windows followed by InvalidateRect(parentHWND, NULL, TRUE)the parent window fixed the rendering problem without introducing noticeable flicker.

Other suggestions are still welcome!

Update 2
I tried RedrawWindow(hwnd, 0, 0, RDW_INVALIDATE | RDW_ALLCHILDREN), but this led to some rendering problems (left pixels).

Update 3
RedrawWindow works, followed by InvalidateRect(hwnd, NULL, TRUE). Thanks @interjay!

+3
source share
3 answers

You can try RedrawWindowskipping the flags RDW_INVALIDATEand RDW_ALLCHILDREN.

Edit

, RDW_ERASE. , , RedrawWindow, InvalidateRect(...,TRUE).

+1

. , :

void WindowClass::Invalidate(BOOL bErase)
{
    base::Invalidate(bErase);

    // traverse along all the child windows.
    for (CWnd* pChild = GetWindow(GW_CHILD); pChild != NULL; pChild = pChild->GetWindow(GW_HWNDNEXT))
    {
        // Let them do the invalidate also.
        pChild->Invalidate(bErase);
    }
}

, .,.

+2

- - - , CS_VREDRAW CS_HREDRAW WNDCLASS , .

, , , :

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT & cs)
{
    // do standard thing
    if (!CMFCToolboxMDIFrameWnd::PreCreateWindow(cs))
        return FALSE;

    // ensure a thinner border
    cs.dwExStyle &= ~WS_EX_CLIENTEDGE;

    // avoid repainting when resized by changing the class style
    WNDCLASS wc;
    VERIFY(GetClassInfo(AfxGetInstanceHandle(), cs.lpszClass, &wc));
    cs.lpszClass = AfxRegisterWndClass(0, wc.hCursor, wc.hbrBackground, wc.hIcon);

    return TRUE;
}
0

Source: https://habr.com/ru/post/1725823/


All Articles