Old fashion design for PC-104
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
3.0 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 05/08/2001
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: MemoryDC.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of MemoryDC.cpp
  13. //----------------------------------------------------------------------------
  14. // MemDC.cpp: implementation of the CMemDC class.
  15. //
  16. //////////////////////////////////////////////////////////////////////
  17. #include "stdafx.h"
  18. #include "MemoryDC.h"
  19. #include "Version.h"
  20. #ifdef _DEBUG
  21. #undef THIS_FILE
  22. static char THIS_FILE[]=__FILE__;
  23. #define new DEBUG_NEW
  24. #endif
  25. //////////////////////////////////////////////////////////////////////
  26. // Construction/Destruction
  27. //////////////////////////////////////////////////////////////////////
  28. CMemoryDC::CMemoryDC()
  29. {
  30. m_pBitmap = NULL;
  31. m_Size.cx = m_Size.cy = NULL;
  32. }
  33. CMemoryDC::~CMemoryDC()
  34. {
  35. if( GetSafeHdc() )
  36. DeleteDC();
  37. }
  38. BOOL CMemoryDC::Create( HBITMAP hBitmap, BOOL bCopy )
  39. {
  40. DIBSECTION DibSection;
  41. if( !::GetObject( hBitmap, sizeof( DibSection ), &DibSection ) )
  42. return FALSE;
  43. int cx = DibSection.dsBm.bmWidth;
  44. int cy = DibSection.dsBm.bmHeight;
  45. if( m_Size.cx != cx && m_Size.cy != cy )
  46. {
  47. if( GetSafeHdc() )
  48. DeleteDC();
  49. m_Size.cx = cx;
  50. m_Size.cy = cy;
  51. CDC *pDC = CWnd::GetDesktopWindow()->GetDC();
  52. if( pDC )
  53. {
  54. CreateCompatibleDC( pDC );
  55. if( bCopy )
  56. m_Bitmap.CreateCompatibleBitmap( pDC, m_Size.cx, m_Size.cy );
  57. else
  58. m_Bitmap.Attach( hBitmap );
  59. m_pBitmap = SelectObject( &m_Bitmap );
  60. CWnd::GetDesktopWindow()->ReleaseDC( pDC );
  61. }
  62. if( bCopy )
  63. {
  64. CDC *pDC = CWnd::GetDesktopWindow()->GetDC();
  65. if( pDC )
  66. {
  67. CDC dc;
  68. dc.CreateCompatibleDC( pDC );
  69. CBitmap bmp;
  70. bmp.Attach( hBitmap );
  71. CBitmap *pOldBmp = dc.SelectObject( &bmp );
  72. BitBlt( 0, 0, m_Size.cx, m_Size.cy, &dc, 0, 0, SRCCOPY );
  73. dc.SelectObject( pOldBmp );
  74. bmp.Detach();
  75. CWnd::GetDesktopWindow()->ReleaseDC( pDC );
  76. }
  77. }
  78. }
  79. return TRUE;
  80. }
  81. BOOL CMemoryDC::Create( int cx, int cy, COLORREF color )
  82. {
  83. if( m_Size.cx != cx || m_Size.cy != cy )
  84. {
  85. if( GetSafeHdc() )
  86. DeleteDC();
  87. m_Size.cx = cx;
  88. m_Size.cy = cy;
  89. CDC *pDC = CWnd::GetDesktopWindow()->GetDC();
  90. if( pDC )
  91. {
  92. CreateCompatibleDC( pDC );
  93. m_Bitmap.CreateCompatibleBitmap( pDC, m_Size.cx, m_Size.cy );
  94. m_pBitmap = SelectObject( &m_Bitmap );
  95. CWnd::GetDesktopWindow()->ReleaseDC( pDC );
  96. }
  97. }
  98. if( GetSafeHdc() )
  99. {
  100. CBrush brush( color );
  101. CRect rect( 0, 0, m_Size.cx, m_Size.cy );
  102. FillRect( &rect, &brush );
  103. }
  104. return TRUE;
  105. }
  106. BOOL CMemoryDC::DeleteDC()
  107. {
  108. if( m_pBitmap )
  109. {
  110. SelectObject( m_pBitmap );
  111. m_pBitmap = NULL;
  112. }
  113. if( m_Bitmap.GetSafeHandle() )
  114. m_Bitmap.DeleteObject();
  115. return CDC::DeleteDC();
  116. }