2

When listening to the AdvancedCustomDraw event of a TTreeView event this way:

if Stage = cdPrePaint then begin
    // modify some Sender.Canvas properties and let it draw itself
end else if Stage = cdPostPaint then begin
    // draw 'something extra' using a separate TControlCanvas
    TControlCanvas.TextOut(SomeRect, 'Hello');
end;

... it seems that when I enable DoubleBuffered the control decides not to copy the 'something extra' to the offscreen buffer. This means that as long as I don't disturb the window in question, all is fine. When I do, the 'something extra' is only visible in random parts of the window.

What am I missing here?

Orwell
  • 1,468
  • 1
  • 13
  • 28
  • Sounds like the simple solution is to switch `DoubleBuffered` to `False`. Why can't you do that? – David Heffernan Feb 02 '13 at 19:09
  • 1
    @DavidHeffernan well, that makes erasing visible when resizing the control in question. And that's what I am trying to prevent. – Orwell Feb 02 '13 at 21:15
  • 2
    That's easy to do. Just add the extended window style `WS_EX_COMPOSITED` whilst in the sizing loop. Personally I have made flicker free Delphi apps, flicker free during resize, without `DoubleBuffered`, a property which I regard to be evil. More details at my answer here: http://stackoverflow.com/questions/8058745/tlabel-and-tgroupbox-captions-flicker-on-resize – David Heffernan Feb 02 '13 at 21:19
  • It works, with the usual CreateParams override! – Orwell Feb 02 '13 at 21:26

1 Answers1

4

Since your comment gave me carte blanche to suggest an alternative solution, here's what I would do:

  1. Stop using DoubleBuffered. It leads to lots of visual oddities in lots of controls. I personally avoid it like the plague.
  2. Solve your flickering problem by adding the WS_EX_COMPOSITED extended window style to your control. This window style can be a bit of a performance drag and I'd recommend that you only add this during the sizing loop, which is when you need it. I describe how to do that in my answer here: TLabel and TGroupbox Captions Flicker on Resize.
Community
  • 1
  • 1
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490