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);