views:

109

answers:

1

Or to ask it another way, how OnEraseBkgnd() works?

I'm building a custom control and I hit on this problem.

Childs are rectangles, as usual. I had to disable OnEraseBkgnd() and I use only the OnPaint().
What I need is to efficiently clear the area behind the childs and without flickering.

Techniques like using back buffers are not an option.

Edit: I am very interested in the algorithm that's under the hood of OnEraseBkgnd(). But any helpful answer will also be accepted.

+2  A: 

Usually in Windows, the easiest (but not most effective) means of reducing flicker, is to turn off the WM_ERASEBKGND notification handling. This is because if you erase the background in the notification handler, then paint the window in the WM_PAINT handler, there is a short delay between the two - this delay is seen as a flicker.

Instead, if you do all of the erasing and drawing in the WM_PAINT handler, you will tend to see a lot less flicker. This is because the delay between the two is reduced. You will still see some flicker, especially when resizing because there is still a small delay between the two actions, and you cannot always get in all of the drawing before the next occurance of the vertical blanking interrupt for the monitor. If you cannot use double buffering, then this is probably the most effective method you will be able to use.

You can get better drawing performance by following most of the usual recommendations around client area invalidation - do not invalidate the whole window unless you really need to. Try to invalidate only the areas that have changed. Also, you should use the BeginDeferWindowPos functions if you are updating the positions of a collection of child windows at the same time.

1800 INFORMATION
+1 for the BeginDeferWindowsPos()
Nick D