As I continue to work through the various flicker issues on individual controls in the VCL I thought it worth mentioning a bit more “global” way to tackle the “flicker” problem. If you’re running Windows XP there is a window style called WS_EX_COMPOSITED which you’ll find documented on MSDN under CreateWindowEx here. This style bit instructs the OS to apply double buffered painting for you. Here is how you would add this to a Delphi VCL form:
1 type 2 TMyForm = class(TForm) 3 protected 4 procedure CreateParams(var Params: TCreateParams); override; 5 end; 6 7 ... 8 9 procedure TMyForm.CreateParams(var Params: TCreateParams); 10 begin 11 inherited; 12 // This only works on Windows XP and above 13 if CheckWin32Version(5, 1) then 14 Params.ExStyle := Params.ExStyle or WS_EX_COMPOSITED; 15 end; 16
You should be able to use this on any 32-bit version of Delphi as long as your app is running on Windows XP.
The downside is that depending on your application this change could have rather serious performance implications during a window resize particularly with aligned controls. The upside of course is that it’s flicker free! 🙂
I’ve read that there may be some issues related to using this window style with GDI+ so be sure to look for that if it affects you.
There is no comment on the MSDN as to how this works under Windows Vista but I’d guess there may be some differences.
[UPDATE: May, 2008] Related posts: