Steve Trefethen
Contact me
About Me View my LinkedIn profile

Powered by discountASP.NET
referal ID: sdtref
Why recommend discountASP.NET?
Need consulting?
Need Consulting?

Disclaimer

The posts on this weblog are provided AS IS with no warranties, and confer no rights. The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Using the WS_EX_COMPOSITE window style to eliminate flicker on Windows XP

February 05 2007 6:38AM
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:

Quick Tip: FullRepaint and fixing flicker in a Delphi VCL app
Quick Tip #2: Fixing flicker caused by WM_ERASEBKGND in a Delphi VCL app

Tags: , ,

Comments

2/5/2007 8:24:31 AM #

glob

i think you should also mention that if the application is running over remote desktop, you should NOT do double buffering.

blogs.msdn.com/.../508694.aspx

glob

2/5/2007 8:52:53 AM #

Steve Trefethen

glob,
Yes, I've read that article and I'd hope Windows would resolve it for you if you decided to use WS_EX_COMPOSITE since it seems like that should be possible without any additional coding. You'll notice the MSDN doesn't mention the remote desktop situation at all so I guess it's up to the developer to do the testing.

Steve Trefethen

2/5/2007 10:55:39 AM #

Nardev

There seems to be a problem with caption button painting too; if you have a visual style applied the buttons won't react to to MouseOver.

Nardev

2/5/2007 2:00:14 PM #

Sebastian Zierer

This appears to be a great workaround for QC37403 (ALT Key press causes controls to disappear under Themes in Vista and XP):

procedure TCustomCheckBox.CreateParams(var Params: TCreateParams);
[...]
begin
  inherited CreateParams(Params);
  if CheckWin32Version(5, 1) then
    Params.ExStyle := Params.ExStyle or WS_EX_COMPOSITED;

Sebastian Zierer

2/14/2007 3:43:56 PM #

Bill Meyer

This seems to work without trouble on Vista 64, though with a TImage, the flicker is gone, but glitches are still visible. I suspect these are simply the result of asynchronous repaint with respect to vertical refresh.

Bill Meyer

2/14/2007 4:29:08 PM #

Steve Trefethen

Bill,
FYI, I've seen numerous visual glitches on WinXP 64 that aren't present in XP Win32 and it wouldn't surprise me if the same were true for Vista, so it might be worth a quick check.

Steve Trefethen

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Spam filtering provided by: Spam Counter
337 comments approved, 1525 spam caught since October 28, 2009
Powered by Commentor