GDI + double buffering under VC6

Source: Internet
Author: User

I. Overview

This time in the study of GDI + double buffering implementation method, spent a lot of time online did not find a suitable example, especially for VC6. Later, through the analysis of the online data, and the study of SDK/MFC, realize the VC6 under GDI + double buffer, write it out to share with you, hope to find a better way to achieve.

One of the advantages of GDI + is that you can use the JPG image directly, in this example, I did not put the image file in the resource, but dynamic reading, because of the project requirements, the number of images is unknown, and the second is because the dynamic reading of the file efficiency, the use of double buffering can reflect the

Second, analysis

In the process of implementation, made a mistake, read the image of the method placed in the OnDraw, and later found that dragging the scroll bar flashing very serious, because scrollbar drag will produce message activation OnDraw, in this case, every drag scroll read a file, redraw once, the efficiency of course low!

My implementation is: Replace the image after the call UpdateAllViews, memory DC drawing is placed in the onupdate operation, after the memory is drawn and then in the screen map.

// 贴上画布
m_pOldBitmap = m_memDC.SelectObject(&m_memBitmap);
m_memDC.FillSolidRect(0,0,2000,2000,RGB(100,100,100));
// 贴图
CString pStrFullPath = pDoc->m_pStrMapPath + pDoc->m_pStrMapName;
USES_CONVERSION;
LPWSTR wStr = A2W(pStrFullPath);
Image img(wStr);
pDoc->m_nMapWidth = img.GetWidth();
pDoc->m_nMapHeight = img.GetHeight();
Graphics g(m_memDC.GetSafeHdc());
g.DrawImage(&img,0,0,img.GetWidth(),img.GetHeight());
// 恢复
m_memDC.SelectObject(m_pOldBitmap);

Related Article

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.