Use four buffers to improve the efficiency of the Self-painted Interface

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.