XTMemDC.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // XTMemDC.cpp : implementation of the CXTMemDC class.
  2. //
  3. // This file is a part of the Xtreme Toolkit for MFC.
  4. // ?998-2002 Codejock Software, All Rights Reserved.
  5. //
  6. // This source code can only be used under the terms and conditions
  7. // outlined in the accompanying license agreement.
  8. //
  9. // support@codejock.com
  10. // http://www.codejock.com
  11. //
  12. //////////////////////////////////////////////////////////////////////
  13. #include "StdAfx.h"
  14. //#include "XTGlobal.h"
  15. #include "XTMemDC.h"
  16. #ifdef _DEBUG
  17. #undef THIS_FILE
  18. static char THIS_FILE[]=__FILE__;
  19. #define new DEBUG_NEW
  20. #endif
  21. IMPLEMENT_DYNAMIC(CXTMemDC, CDC);
  22. //////////////////////////////////////////////////////////////////////
  23. // CXTMemDC - implementation
  24. CXTMemDC::CXTMemDC(CDC* pDC, const CRect& rect, COLORREF clrColor/*=xtAfxData.clr3DFace*/)
  25. {
  26. ASSERT(pDC != NULL);
  27. m_pDC = pDC;
  28. // If rect is NULL, use the device context's clip box.
  29. if (rect.IsRectEmpty())
  30. m_pDC->GetClipBox(&m_rc);
  31. else
  32. m_rc.CopyRect(&rect);
  33. // Create the memory DC, set Map Mode
  34. if (CreateCompatibleDC(m_pDC))
  35. {
  36. SetMapMode(m_pDC->GetMapMode());
  37. // Create a bitmap big enough to hold the window's image
  38. m_bitmap.CreateCompatibleBitmap(m_pDC, m_rc.Width(), m_rc.Height());
  39. // Select the bitmap into the memory DC
  40. m_pOldBitmap = SelectObject(&m_bitmap);
  41. // Repaint the background, this takes the place of WM_ERASEBKGND.
  42. if (clrColor != -1)
  43. FillSolidRect(m_rc, clrColor);
  44. m_bValid = TRUE;
  45. }
  46. // Something bad happened, could be GDI leak, didn't create device context.
  47. else
  48. {
  49. m_bValid = FALSE;
  50. m_pOldBitmap = NULL;
  51. }
  52. }
  53. CXTMemDC::~CXTMemDC()
  54. {
  55. if (m_bValid)
  56. {
  57. // Blt it
  58. m_pDC->BitBlt(m_rc.left, m_rc.top, m_rc.Width(), m_rc.Height(),
  59. this, 0, 0, SRCCOPY);
  60. }
  61. // Select the original bitmap back in
  62. if (m_pOldBitmap != NULL)
  63. SelectObject(m_pOldBitmap);
  64. DeleteDC();
  65. }