We developed and are maintaining a Delphi VCL Application written in Delphi 2007. The application works fine on Windows 7. Some of the users who recently moved to Windows 10 complain that the application flickers once in a while, to a point that their system is unresponsive and not usable when this happens.
After some investigation, we noticed that this happens when the group policies are being updated. We can trigger the flickering by running the gpupdate command on the workstation.
The other applications flicker when our application is running on the Windows 10 workstations, even when our application is minimized.
We also did some research and it sounds like this is a fairly common problem. Microsoft explains that, screen flickering in Windows 10 is usually caused by an incompatible app or a display driver.
To determine whether an app or display driver is causing the problem, you can check to see if Task Manager flickers. Then, based on that information, you'll need to update or uninstall the app or update, rollback, or uninstall your display driver.
The issue is that Microsoft does not explain what an “incompatible app” means.
Even some of the Microsoft apps flicker.
We know that our application is faulty, but we don’t know why.
Did anybody else experience that?
You probably get that since updating the policies broadcasts a slew of WM_SETTINGSCHANGE messages to all applications running on the system. VCL apps react to that by reloading some UI related system settings and redrawing the UI. You can disable that by setting Application.UpdateMetricSettings and UpdateFormatSettings to false during your application start. That has side effects, though, if the user changes something the application should pick up.
You can be more selective by using Application.HookMainWindow or perhaps the OnMessage event to intercept the messages and let only those pass on to which the application should react. See https://docs.microsoft.com/en-us/windows/win32/winmsg/wm-settingchange
The wparam of the message tells you what caused it.
Thank you very much for your quick response Peter, it is well appreciated.
We wrote a small application capturing and logging the messages it receives through both Application.OnMessage as well as Application.HookMainWindow.We do not see a lot more of WM_SETTINGCHANGE messages coming our way when running a group policy update or changing a regional setting such as the short date format. We get around 3 messages on both Windows 7 and Windows 10, so I am not sure what triggers the applications to repaint and the flickering.Setting both Application.UpdateMetricSettings and UpdateFormatSettings to false during our application start (TForm1.FormCreate) however prevents the application from flickering, so there is hope :).We will now see if we can use Application.HookMainWindow or the OnMessage event to intercept the messages. Worth case, we can ask the users to close the application and restart it when they want to modify a regional setting. Most of the users don’t have the privileges to do that anyway.
Try to add a handler for the message to your main form as well, it will also receive broadcast messages, as will all other top-level windows. I don't remember where the VCL handles the message, you have to check the source (forms.pas) to figure that out.
We regression tested the application after setting Application.UpdateMetricSettings and Application.UpdateFormatSettings to false. The application works as expected and the change got rid of the flickering, so this is the solution we will use for now.
Thanks again for your help Peter.