Causes of WindowChrome flickering identified
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
People have had problems with WindowChrome flickering. In my situation I tracked the bug down to the loop in my code which was changing the window title 3 times a second to "scroll" it like WinAmp.
In WindowChromeWorker._HandleSetTextOrIcon() the WPF framework code plays a trick where it clears WS_VISIBLE before forwarding WM_SETTEXT to DefWindowProc, and then sets it back after returning. The comment says this is done to trick DefWindowProc into not redrawing the caption.
In WindowChromeWorker._UpdateSystemMenu() which is called on every WM_SIZE, the code does the same exact trick with WS_VISIBLE.
This means that every time your window is resized, or the caption is changed, or the window icon is changed, WindowChrome will clear WS_VISIBLE and then reset it.
https://github.com/dotnet/wpf/blob/master/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shell/WindowChromeWorker.cs
The problem is that this is the official way to hide and show a window and will not merely behave as a private-data-only change. If the DWM catches the window style change it will hide the window during the DefWindowProc call. Usually it happens fast but it can become a nuisance. This is horrible because if you try to click the window at the wrong time when it is briefly hidden, you will click into emptiness and activate the window underneath it instead. The Windows+Tab virtual desktop switcher is less subtle; every time the WndProc clears WS_VISIBLE for text or icon, the switcher will repeatedly remove the window from the list and add it back, shifting all the other windows around and causing a lot of redraws.
I don't know what the fix should be, but the current situation is unacceptable. Perhaps something could be done like in the _HandleNCActivate() call underneath, which passes an undocumented parameter to DefWindowProc to suppress unwanted behavior. In the meantime I need to phase out all usage of WindowChrome in my code until this is fixed and I advise others to do likewise.
Contributor guide
Assessment
This issue has not been assessed yet.