Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. #if !defined(AFX_MEMDC_H__CA1D3541_7235_11D1_ABBA_00A0243D1382__INCLUDED_)
  2. #define AFX_MEMDC_H__CA1D3541_7235_11D1_ABBA_00A0243D1382__INCLUDED_
  3. #pragma once
  4. // MemDC.h : header file
  5. class CMemDC : public CDC
  6. {
  7. public:
  8. CMemDC(CDC* pDC);
  9. ~CMemDC();
  10. CMemDC* operator->() {return this;}
  11. operator CMemDC*() {return this;}
  12.  
  13. private:
  14. CBitmap m_bitmap;
  15. CBitmap* m_pOldBitmap;
  16. CDC* m_pDC;
  17. CRect m_rect;
  18. BOOL m_bMemDC;
  19. };
  20. #endif
  21.  
  22.  
  23. // MemDC.cpp : implementation of MemDC class
  24. // This class implements a memory Device Context
  25. #include "stdafx.h"
  26. #include "MemDC.h"
  27.  
  28. CMemDC::CMemDC(CDC* pDC) : CDC()
  29. {
  30. ASSERT(pDC != NULL);
  31.  
  32. m_pDC = pDC;
  33. m_pOldBitmap = NULL;
  34. #ifndef WCE_NO_PRINTING
  35. m_bMemDC = !pDC->IsPrinting();
  36. #else
  37. m_bMemDC = FALSE;
  38. #endif
  39.  
  40. if (m_bMemDC) // Create a Memory DC
  41. {
  42. pDC->GetClipBox(&m_rect);
  43. CreateCompatibleDC(pDC);
  44. m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());
  45. m_pOldBitmap = SelectObject(&m_bitmap);
  46. #ifndef _WIN32_WCE
  47. SetWindowOrg(m_rect.left, m_rect.top);
  48. #endif
  49. }
  50. else // Make a copy of the relevent parts of the current DC for printing
  51. {
  52. #ifndef WCE_NO_PRINTING
  53. m_bPrinting = pDC->m_bPrinting;
  54. #endif
  55. m_hDC = pDC->m_hDC;
  56. m_hAttribDC = pDC->m_hAttribDC;
  57. }
  58. }
  59.  
  60. // Destructor copies the contents of the mem DC to the original DC
  61. CMemDC::~CMemDC()
  62. {
  63. if (m_bMemDC)
  64. {
  65. // Copy the offscreen bitmap onto the screen.
  66. m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(),
  67. this, m_rect.left, m_rect.top, SRCCOPY);
  68.  
  69. //Swap back the original bitmap.
  70. SelectObject(m_pOldBitmap);
  71. }
  72. else {
  73. // All we need to do is replace the DC with an illegal value,
  74. // this keeps us from accidently deleting the handles associated with
  75. // the CDC that was passed to the constructor.
  76. m_hDC = m_hAttribDC = NULL;
  77. }
  78. }
  79.  
  80. LNK2005 "public: virtual __thiscall CMemDC::~CMemDC(void)" (??1CMemDC@@UAE@XZ) already defined in MemDC.obj myProj C:devmyprojnafxcwd.lib(afxglobals.obj)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement