tags:

views:

196

answers:

2

To reduce flickering I create my parent windows using the WS_CLIPCHILDREN flag and I call InvalidateRect during the WM_SIZE event. This approach has worked well in Windows XP. However, I recently started programming on Windows 7 and I'm now experiencing rendering issues when resizing windows. When resizing a window its contents is not refreshed until I do something that forces a redraw, like minimizing and restoring the window.

I've tried following up the InvalidateRect with a UpdateWindow call but with no effect.

Does anyone know how to do it correctly?

Edit
I found a workaround: calling
InvalidateRect(childHWND, NULL, FALSE)
on all child windows followed by a InvalidateRect(parentHWND, NULL, TRUE) on the parent window fixes the rendering problem without introducing noticable flickering.

Other suggestions are still welcome!

Edit2
@interjay: I tried the ::RedrawWindow(handle(), 0, 0, RDW_INVALIDATE | RDW_ALLCHILDREN); but that resulted in some rendering issues (left-over pixels):

alt text

Edit3
The RedrawWindow works when followed by a ::InvalidateRect(handle(), NULL, TRUE). Thanks @interjay!

+1  A: 

You can try calling RedrawWindow, passing flags RDW_INVALIDATE and RDW_ALLCHILDREN.

Edit:

To redraw the background, you can add RDW_ERASE. If you want to redraw the background on the parent but not the children, call both RedrawWindow and InvalidateRect(...,TRUE).

interjay
Thanks, that works too.
StackedCrooked
A: 

I found this snippet somewhere recently when browsing for something else - and it indicated that by removing CS_VREDRAW and CS_HREDRAW from the WNDCLASS for your window, that it would reduce the artifacts created when resizing a window.

I use the following snippet to achieve this, though I cannot say how much real impact I have actually noticed it having:

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;
}
Mordachai