12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #include "stdafx.h"
- #include "MemoryDC.h"
- CMemoryDC::CMemoryDC( CDC* pDC, CRect rect , BOOL bCopyFirst ): CDC(), m_oldBitmap(NULL), m_pDC(pDC)
- {
- ASSERT(m_pDC != NULL);
- m_bMemDC = !pDC->IsPrinting();
- if (m_bMemDC)
- {
-
- CreateCompatibleDC(pDC);
- if ( rect == CRect(0,0,0,0) )
- {
- pDC->GetClipBox(&m_rect);
- }
- else
- {
- m_rect = rect;
- }
-
- m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());
-
- m_oldBitmap = SelectObject(&m_bitmap);
-
- SetWindowOrg(m_rect.left, m_rect.top);
-
- if(bCopyFirst)
- {
- this->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(),m_pDC, m_rect.left, m_rect.top, SRCCOPY);
- }
- }
- else
- {
-
- m_bPrinting = pDC->m_bPrinting;
- m_hDC = pDC->m_hDC;
- m_hAttribDC = pDC->m_hAttribDC;
- }
- }
- CMemoryDC::~CMemoryDC()
- {
- if (m_bMemDC)
- {
-
- m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(), this, m_rect.left, m_rect.top, SRCCOPY);
-
- SelectObject(m_oldBitmap);
- }
- else
- {
- m_hDC = m_hAttribDC = NULL;
- }
- }
- CMemoryDC* CMemoryDC::operator->()
- {
- return this;
- }
- CMemoryDC::operator CMemoryDC*()
- {
- return this;
- }
|