MFC refreshes the drawing with double buffering

Source: Internet
Author: User

When processing the drawing process in VC, if the graphics refresh quickly, the phenomenon of graphics flicker often occurs. Using the method of first drawing in memory and then copying to the screen can eliminate the flicker of the screen by first creating a device-compatible memory device context in memory, i.e. opening up a fast memory area as the display area and then drawing the graphics in this memory area. Use the BitBlt function to copy the graphics of the memory directly onto the screen after the drawing is complete.

What you want to do is to draw a few dynamic points in a picture control (IDC_MAP) in the dialog client area, which flashes when the screen refreshes without a double-buffering technique.

CRect rect; cwnd* pWnd = GetDlgItem (Idc_map);    Pwnd->getwindowrect (&rect);   Gets the control screen coordinates pwnd->screentoclient (&rect); Convert to the corresponding control coordinate cdc* PDC = PWND->GETDC ();            cdc* Pmem =new CDC; Defines the device context for a memory drawing cbitmap* pBmp = new CBitmap; cbitmap* poldbmp;//cdc* dc=getdc ();p Mem->createcompatibledc (PDC);p Bmp->createcompatiblebitmap (pDC,rect. Width (), Rect.         Height ());p oldbmp = Pmem->selectobject (PBMP); Drawing in Pmem ...//The location of the drawing in memory is copied to display in the control Pdc->bitblt (Rect.left,rect.top,rect. Width (), Rect. Height (), pmem,0,0,srccopy);p mem->selectobject (poldbmp);p bmp->deleteobject ();p Mem->deletedc ();

The effect of the implementation is as follows:

In the OnTimer to achieve the target point of movement, click the button matching point to complete the line, start the timer again, re-draw the location information, to achieve dynamic real-time display information.




MFC refreshes the drawing with double buffering

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.