Win32 GUI flickering on resize

wj32 picture wj32 · Jan 10, 2010 · Viewed 8.6k times · Source

I have a Win32 GUI program with a tab control, each tab having a list view control. There is massive flickering whenever the window is resized. I've tried the following things:

  • Handling WM_ERASEBKGND in the main wndproc and returning TRUE. No effect.
  • Filtering out all WM_ERASEBKGND messages in the event loop. No effect.
  • Setting the WM_CLIPCHILDREN style on the main window. Now when the window is resized the list view control is simply erased to a white background and doesn't redraw.
  • Using DefWindowPos instead of MoveWindow. No effect.
  • Passing FALSE for bRepaint in MoveWindow. Same effect as setting WS_CLIPCHILDREN (see above).

Here's the RegisterClassEx code:

memset(&wcex, 0, sizeof(WNDCLASSEX));
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = 0;
wcex.lpfnWndProc = PhMainWndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = PhInstanceHandle;
wcex.hIcon = LoadIcon(PhInstanceHandle, MAKEINTRESOURCE(IDI_PROCESSHACKER));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
//wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = MAKEINTRESOURCE(IDR_MAINWND);
wcex.lpszClassName = PhWindowClassName;
wcex.hIconSm = (HICON)LoadImage(PhInstanceHandle, MAKEINTRESOURCE(IDI_PROCESSHACKER), IMAGE_ICON, 16, 16, 0);

The WM_SIZE handler:

RECT rect;

// Resize the tab control.

GetClientRect(PhMainWndHandle, &rect);
MoveWindow(TabControlHandle, rect.left, rect.top,
    rect.right - rect.left, rect.bottom - rect.top, TRUE);

// Resize the list view.

TabCtrl_AdjustRect(TabControlHandle, FALSE, &rect);

MoveWindow(ListViewHandle, rect.left, rect.top,
    rect.right - rect.left, rect.bottom - rect.top, TRUE);

The styles are as follows:

  • Main window: WS_OVERLAPPEDWINDOW
  • Tab control: WS_CHILD (and WS_VISIBLE)
  • List view control: WS_CHILD | WS_BORDER | LVS_REPORT (and WS_VISIBLE)

Answer

wj32 picture wj32 · Jan 15, 2010

It turned out there was a problem with the Z-ordering - calling BringWindowToTop on the list view solved the problem.