All the friends who have done self-painting know that if they are directly painted on the DC of the window, frequent updates will cause the window to flash. Therefore, we all like to use double buffering to solve this problem. (That is, the image is first painted to the memory DC, and then copied to the window DC after all the image is finished ).
When writing the directui interface, the Child control is not a real window, but is directly painted to some subareas in the same window. If every sub-control updates the status (for example, getting the focus, mouse hotspot, and press) and re-draws all the sub-controls, the efficiency will be lower, when gdiplus is used, the efficiency difference is more obvious, and the CPU usage is particularly high.
To solve this problem, I used more caching when writing the "Comet assistant. Update the status of a widget as needed.
Cache-> Save the background of the entire window (updated only when the window size changes)
Cache B-> Draw all child controls based on.
Cache C-> Copy B, copy the background (A) of the area occupied by the current re-painting sub-control (such as the "Regular Expression debugging" sub-control), and then draw the sub-control (Regular Expression debugging) last copied to the window DC (assumedD).
In this way, more GDI objects are saved, and the memory usage is slightly higher, but the CPU usage is greatly reduced, so there will not be a "card" phenomenon due to too many child controls. The more child widgets, the more obvious.
Here, four DCs are used, including the window DC, which may be called Four buffers.
As follows: