/***********************************************************************/ /* Copyright (C) 2002 Definitive Solutions, Inc. All Rights Reserved. */ /* THIS COMPUTER PROGRAM IS PROPRIETARY AND CONFIDENTIAL TO DEFINITIVE */ /* SOLUTIONS, INC. AND ITS LICENSORS AND CONTAINS TRADE SECRETS OF */ /* DEFINITIVE SOLUTIONS, INC. THAT ARE PROVIDED PURSUANT TO A WRITTEN */ /* AGREEMENT CONTAINING RESTRICTIONS ON USE AND DISCLOSURE. ANY USE, */ /* REPRODUCTION, OR TRANSFER EXCEPT AS PROVIDED IN SUCH AGREEMENT */ /* IS STRICTLY PROHIBITED. */ /***********************************************************************/ #include "stdafx.h" #include "MyMemoryDC.h" #include "MyLog.h" #include "MyApp.h" #include "Generic.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // MyMemoryDC class // Constructor. MyMemoryDC::MyMemoryDC(CDC* pDC, const CRect& rcBounds) : m_pOldBitmap(NULL) , m_pDC(pDC) , m_rc(rcBounds) , m_bMemDC(! pDC->IsPrinting()) { _ASSERTE(m_pDC); // If not printing, create a Memory DC. if (m_bMemDC){ if (CreateCompatibleDC(pDC)) { if (m_bitmap.CreateCompatibleBitmap(pDC, m_rc.Width(), m_rc.Height())) { if (NULL != (m_pOldBitmap = SelectObject(&m_bitmap))) { SetWindowOrg(m_rc.left, m_rc.top); } else { DOMYLOGST(API_FAILURE), "::SelectObject", ::GetLastError(), Generic::GetSysErrorString()); } } else { DOMYLOGST(API_FAILURE), "::CreateCompatibleBitmap", ::GetLastError(), Generic::GetSysErrorString()); } } else { DOMYLOGST(API_FAILURE), "::CreateCompatibleDC", ::GetLastError(), Generic::GetSysErrorString()); } } 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; } } // Destructor. /* virtual */ MyMemoryDC::~MyMemoryDC() { // Copy the offscreen bitmap onto the screen. if (m_bMemDC) { if (m_pDC->BitBlt(m_rc.left, m_rc.top, m_rc.Width(), m_rc.Height(), this, m_rc.left, m_rc.top, SRCCOPY)) { // Swap back the original bitmap. if (SelectObject(m_pOldBitmap)) { ; } else { DOMYLOGST(API_FAILURE), "::SelectObject", ::GetLastError(), Generic::GetSysErrorString()); } } else { DOMYLOGST(API_FAILURE), "::BitBlt", ::GetLastError(), Generic::GetSysErrorString()); } } else { m_hDC = m_hAttribDC = NULL; } }