Description of Double Buffering

Source: Internet
Author: User


The principle of double buffering can be understood as follows: the computer screen is regarded as a blackboard. First, we will create a "virtual" blackboard in the memory environment, and then draw complex graphics on this blackboard.
When the preparation is complete, copy the image drawn in the memory to another blackboard (screen) at one time. This method can increase the drawing speed and greatly improve the drawing effect. Can understand this layer, work
It is easy to do. You can do it in just four steps. See the following code:
For example, the ondraw () function can implement dual buffering as described below. The main steps are as follows:
Rong:
Cpen pen;
Pen. createpen (ps_insideframe, 1, RGB (225,225, 0 ));
Cbrush
Brush; brush. createsolidbrush (RGB (225,225, 0 ));
CDC dcmem;
Cbitmap
BM;
Crect RC;
Getclientrect (& rc );
// Step 1: Create a compatible memory DC for the screen DC:
Createcompatibledc () dcmem. createcompatibledc (PDC );
//
Step 2
Create a bitmap:
Createcompatiblebitmap () BM. createcompatiblebitmap (PDC, RC. Width (), RC. Height ());
//
Step 3: select the bitmap to the device environment:
SelectObject (),
It can be understood as selecting a canvas
Dcmem. SelectObject (& BM );
Dcmem. SelectObject (PEN );
Dcmem. SelectObject (Brush );
Dcmem. ellipse (0, 0, 50, 50 );//
Draw an ellipse
// Step 4: copy the drawn image to the screen: bitblt ()
PDC-> bitblt (0, 0, RC. Width (), RC. Height (), & dcmem, 0, srccopy );
Dcmem. deletedc ();
BM. deleteobject ();

In this way, dual buffering is implemented. This method can be used to prevent screen flickering when drawing in VC.

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.