XTMemDC.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:3k
- // XTMemDC.cpp : implementation of the CXTMemDC class.
- //
- // This file is a part of the XTREME CONTROLS MFC class library.
- // (c)1998-2008 Codejock Software, All Rights Reserved.
- //
- // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
- // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
- // CONSENT OF CODEJOCK SOFTWARE.
- //
- // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
- // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
- // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
- // SINGLE COMPUTER.
- //
- // CONTACT INFORMATION:
- // support@codejock.com
- // http://www.codejock.com
- //
- /////////////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "XTMemDC.h"
- #include "Common/XTPDrawHelpers.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #define new DEBUG_NEW
- #endif
- IMPLEMENT_DYNAMIC(CXTMemDC, CDC)
- //===========================================================================
- // CXTMemDC class
- //===========================================================================
- CXTMemDC::CXTMemDC(CDC* pDC, const CRect& rect, CXTPPaintManagerColorGradient crBack/*=GetXtremeColor(COLOR_3DFACE)*/, BOOL bHorz/*=FALSE*/)
- {
- ASSERT(pDC != NULL);
- m_pDC = pDC;
- if (!m_pDC)
- return;
- // If rect is NULL, use the device context's clip box.
- if (rect.IsRectEmpty())
- m_pDC->GetClipBox(&m_rc);
- else
- m_rc.CopyRect(&rect);
- // Create the memory DC, set Map Mode
- if (CreateCompatibleDC(m_pDC))
- {
- SetMapMode(m_pDC->GetMapMode());
- // Create a bitmap big enough to hold the window's image
- m_bitmap.CreateCompatibleBitmap(m_pDC, m_rc.Width(), m_rc.Height());
- // Select the bitmap into the memory DC
- m_hOldBitmap = (HBITMAP)SelectObject(&m_bitmap)->GetSafeHandle();
- if (crBack != COLORREF_NULL)
- {
- // fill background
- XTPDrawHelpers()->GradientFill(this, CRect(0, 0, m_rc.Width(), m_rc.Height()), crBack, bHorz);
- }
- m_bValid = TRUE;
- }
- // Something bad happened, could be GDI leak, didn't create device context.
- else
- {
- m_bValid = FALSE;
- m_hOldBitmap = NULL;
- }
- }
- CXTMemDC::~CXTMemDC()
- {
- if (IsValid())
- {
- // Blt it
- m_pDC->BitBlt(m_rc.left, m_rc.top, m_rc.Width(), m_rc.Height(),
- this, 0, 0, SRCCOPY);
- }
- // Select the original bitmap back in
- if (m_hOldBitmap != NULL)
- {
- SelectObject(m_hOldBitmap);
- m_bitmap.DeleteObject();
- }
- DeleteDC();
- }
- CBitmap& CXTMemDC::GetBitmap()
- {
- return m_bitmap;
- }
- void CXTMemDC::Discard()
- {
- m_bValid = FALSE;
- }
- BOOL CXTMemDC::IsValid() const
- {
- return m_bValid;
- }
- void CXTMemDC::FromDC()
- {
- BitBlt(0, 0, m_rc.Width(), m_rc.Height(), m_pDC,
- m_rc.left, m_rc.top, SRCCOPY);
- }