/使用方法/参考 http://blog.csdn.net/mplus/article/details/6131526 ,创建CMemDC对象 //时传一个已有的DC的指针进去(大小可选)如: /*void CDemoView::OnDraw(CDC* pDC) { CFont font; font.CreateFontIndirect(&m_lf); CMemDC pMemDC(pDC); CFont* oldfont = pMemDC->SelectObject(&font); //..Draw something here. pMemDC->SelectObject(oldfont); } */ //以及百度知道问题 //MemDC.H #ifndef _MEMDC_H_ #define _MEMDC_H_ ////////////////////////////////////////////////// // CMemDC - memory DC // // Author: Keith Rule // Email: keithr@europa.com // Copyright 1996-1997, Keith Rule // // You may freely use or modify this code provided this // Copyright is included in all derived versions. // // This class implements a memory Device Context class CMemDC : public CDC { private: CBitmap* m_bitmap; CBitmap* m_oldBitmap; CDC* m_pDC; CRect m_rcBounds; bool m_bMemDC; public: void Construct(CDC* pDC) { ASSERT(pDC != NULL); // Some initialization m_pDC = pDC; m_oldBitmap = NULL; m_bMemDC = !pDC->IsPrinting(); if (m_bMemDC) { // Create a Memory DC CreateCompatibleDC(pDC); pDC->LPtoDP(&m_rcBounds); m_bitmap = new CBitmap; m_bitmap->CreateCompatibleBitmap(pDC, m_rcBounds.Width(), m_rcBounds.Height()); m_oldBitmap = SelectObject(m_bitmap); SetMapMode(pDC->GetMapMode()); pDC->DPtoLP(&m_rcBounds); SetWindowOrg(m_rcBounds.left, m_rcBounds.top); } else { // Make a copy of the relevent parts of the current DC for printing m_bPrinting = pDC->m_bPrinting; m_hDC = pDC->m_hDC; m_hAttribDC = pDC->m_hAttribDC; } // Fill background FillSolidRect(m_rcBounds, pDC->GetBkColor()); } CMemDC(CDC* pDC ) : CDC() { pDC->GetClipBox(&m_rcBounds); Construct(pDC); } CMemDC(CDC* pDC, const CRect& rcBounds) : CDC() { CreateCompatibleDC(pDC); m_bitmap = new CBitmap; m_bitmap->CreateCompatibleBitmap(pDC, rcBounds.Width(), rcBounds.Height()); m_oldBitmap = SelectObject(m_bitmap); m_pDC = pDC; m_rcBounds = rcBounds; } ~CMemDC() { m_pDC->BitBlt(m_rcBounds.left, m_rcBounds.top, m_rcBounds.Width(), m_rcBounds.Height(), this, m_rcBounds.left, m_rcBounds.top, SRCCOPY); SelectObject(m_oldBitmap); if (m_bitmap != NULL) delete m_bitmap; } CMemDC* operator->() { return this; } }; #endif |
|