Hi
I want to share the result of a flicker reduction strategy for normal windows.
When experimenting with dynamic layouts, I've found that dialogs flicker a lot less when they are resized than regular windows. It seems that dialogs have a smarter implementation to redraw the background. Unfortunately, this feature doesn't seem to be available for regular windows. That said, if you want better flicker behaviour, you'll have to write your own code.
A common painting strategy in coding examples is to paint the entire background first, and then paint any remaining child windows. This is fine for immutable windows, but when they have to be changed and redrawn frequently, such as resizing, the poor design quickly becomes apparent.
In this situation, the goal is to paint the background only where it is needed and avoid painting over the areas covered by child windows. This requires the creation of a dynamic array of rectangular areas, starting with the client window and excluding all areas of the child windows.
I wrote the code in the form of a WndBackground object (derived from DataCollection) to do this job. The result is impressive; the window practically no longer flickers!
Regions were candidates for the implementation, but they lack the ability to exclude other regions, so I went with a collection of RECT structures. Maybe a linked list of RECTs would be a better performance choice, but for the moment, I use a DataCollection, that is easier to handle.
Attached the source code and a demo binary from a project I’m working on.
To see the impact of the implementation, run one of the binaries and create an MDI child by pressing Ctrl+N. Now change the size by dragging the border.
Compare the visual result with the other binary.
Have fun!
Biterider