wj32
wj32

Reputation: 8463

Win32 GUI flickering on resize

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:

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:

Upvotes: 5

Views: 9586

Answers (4)

wj32
wj32

Reputation: 8463

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

Upvotes: 5

Chris Becke
Chris Becke

Reputation: 36121

Windows supports a re-size batching operation that is meant to avoid flicker caused when lots of child windows are indepently resized. See BeginDeferWindowPos for more information on that.

If that is not working, then try the WM_SETREDRAW message. It looks possible to stop drawing of the parent window - which will inhibit all the child controls, then, when the layout is finished, enable drawing again, and call RedrawWindow to repaint the entire window in one pass. I did rather think that this is what Defered window positioning would use internally.

Upvotes: 2

Eran Medan
Eran Medan

Reputation: 45775

I may be stating the obvious, but I thought double buffering is the solution to Win32 flickers. I'm a Java Developer and it has been a while sine I wrote win32 so please let me know if I'm talking nonsense

Here is the how to: http://www.gamedev.net/community/forums/topic.asp?topic_id=411559

Here is some sampe code: http://www.codeproject.com/KB/cpp/DoubleBuffering.aspx

Here is the .NET equivalent question (?): How to prevent a Windows Forms TextBox from flickering on resize?

Upvotes: 1

Jonke
Jonke

Reputation: 6533

When a ListView is Docked, as in Windows Explorer (and you have a good amount of items), resizing the main form will cause all of the items to flicker. http://www.codeproject.com/KB/list/listviewxp.aspx

Upvotes: 0

Related Questions