Win32 double buffering Drawing principle

Source: Internet
Author: User

There are many articles on the web about how to use Visual C + + programs to achieve double buffering, are written in C + + object-oriented language, it may be difficult for many C-language beginners who have not touched the object-oriented language, and some kind of people just paste the source code up, do not comment, This makes the reader more laborious to read.
Here, I will explain each statement. One of the places is more interesting and worth discussing (see below). Well, let's start by looking at the basic principle of double buffering:

First, double buffering principle and diagram



(1) Defines the device description table and the bitmap handle
    hdc HMEMDC;
    hbitmap Hbitmap;
(2) Create a memory Display device Description table compatible with the window rectangle display, 1 steps
    HMEMDC = CreateCompatibleDC (HDC);
(3) Create a bitmap with HDC that is compatible with the window rectangle display, 2 steps
    hbitmap = CreateCompatibleBitmap (hdc, Rt.right-rt.left, Rt.bottom-rt.top);//rt is a rect variable, the value is the window rectangle
(4) to select the bitmap hbitmap into the memory display device Hdcmem, only the memory display device with the bitmap selected has a local drawing, draws to the specified bitmap, 3 steps
    selectobject (HMEMDC, HBITMAP);
(5) Clear the bitmap with the HDC background color, 4 steps
     fillrect (Hdcmem, &rt, Hbrush)
(6) Drawing, 5 steps
    drawcircle (&hdcmem, RT, RADIUS)

    ( This step is actually to draw all the pictures you need to draw on the HMEMDC device, and then copy it to HDC)
(7) copies the in-Memory diagram to the window rectangle for display, 6 steps
     bitblt (hdc, 0, 0, Rt.right-rt.left, rt.bottom-rt.top, Hdcmem, 0, 0, SRCCOPY) /span>

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.