How does Windows (or other OSes) update the client's background image area?
Or to ask this differently, how does OnEraseBkgnd () work?
I am creating a custom control and I hit this issue.
The child is rectangles as usual. I had to disable OnEraseBkgnd () and I only use OnPaint ().
What do I need to effectively clear the area behind the childs and without flickering. using backbuffers is not an option.
Edit : I'm very interested in the algorithm that's under the hood OnEraseBkgnd (). But any helpful answer will also be accepted.
a source to share
Usually in Windows, the simplest (but not the most effective) means of reducing flickering is to turn off notification handling WM_ERASEBKGND
. This is because if you remove the background in the notification handler, then paint the window into the handler WM_PAINT
, there will be a small delay between them - this delay is treated as flickering.
Instead, if you erase and paint everything in the handler WM_PAINT
, you will generally see much less flicker. This is due to the fact that the delay between them decreases. You will still see flickering, especially when resizing, because there is still a slight delay between these two actions, and you cannot always get the entire drawing until the next vertical blanking interrupt occurs for the monitor. If you cannot use double buffering, then this is probably the most efficient method you can use.
You can get the best drawing performance by following most of the usual guidelines for invalidating client area - don't invalidate the entire window if you really need to. Try to invalidate only the areas that have changed. Also, you should use functions BeginDeferWindowPos
if you are updating the positions of the child windows collection at the same time.
a source to share