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: 08/10/2003
  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 "..\LgLib\Version.h"
  20. /*
  21. #ifdef _DEBUG
  22. #undef THIS_FILE
  23. static char THIS_FILE[]=__FILE__;
  24. #define new DEBUG_NEW
  25. #endif
  26. */
  27. //////////////////////////////////////////////////////////////////////
  28. // Construction/Destruction
  29. //////////////////////////////////////////////////////////////////////
  30. CMemoryDC::CMemoryDC()
  31. {
  32. m_pBitmap = NULL;
  33. m_Size.cx = m_Size.cy = NULL;
  34. }
  35. CMemoryDC::~CMemoryDC()
  36. {
  37. if( GetSafeHdc() )
  38. DeleteDC();
  39. }
  40. BOOL CMemoryDC::Create( HBITMAP hBitmap, BOOL bCopy )
  41. {
  42. DIBSECTION DibSection;
  43. if( !::GetObject( hBitmap, sizeof( DibSection ), &DibSection ) )
  44. return FALSE;
  45. int cx = DibSection.dsBm.bmWidth;
  46. int cy = DibSection.dsBm.bmHeight;
  47. if( m_Size.cx != cx && m_Size.cy != cy )
  48. {
  49. if( GetSafeHdc() )
  50. DeleteDC();
  51. m_Size.cx = cx;
  52. m_Size.cy = cy;
  53. CDC *pDC = CWnd::GetDesktopWindow()->GetDC();
  54. if( pDC )
  55. {
  56. CreateCompatibleDC( pDC );
  57. if( bCopy )
  58. m_Bitmap.CreateCompatibleBitmap( pDC, m_Size.cx, m_Size.cy );
  59. else
  60. m_Bitmap.Attach( hBitmap );
  61. m_pBitmap = SelectObject( &m_Bitmap );
  62. CWnd::GetDesktopWindow()->ReleaseDC( pDC );
  63. }
  64. if( bCopy )
  65. {
  66. CDC *pDC = CWnd::GetDesktopWindow()->GetDC();
  67. if( pDC )
  68. {
  69. CDC dc;
  70. dc.CreateCompatibleDC( pDC );
  71. CBitmap bmp;
  72. bmp.Attach( hBitmap );
  73. CBitmap *pOldBmp = dc.SelectObject( &bmp );
  74. BitBlt( 0, 0, m_Size.cx, m_Size.cy, &dc, 0, 0, SRCCOPY );
  75. dc.SelectObject( pOldBmp );
  76. bmp.Detach();
  77. CWnd::GetDesktopWindow()->ReleaseDC( pDC );
  78. }
  79. }
  80. }
  81. return TRUE;
  82. }
  83. BOOL CMemoryDC::Create( int cx, int cy, COLORREF color )
  84. {
  85. if( m_Size.cx != cx || m_Size.cy != cy )
  86. {
  87. if( GetSafeHdc() )
  88. DeleteDC();
  89. m_Size.cx = cx;
  90. m_Size.cy = cy;
  91. CDC *pDC = CWnd::GetDesktopWindow()->GetDC();
  92. if( pDC )
  93. {
  94. CreateCompatibleDC( pDC );
  95. m_Bitmap.CreateCompatibleBitmap( pDC, m_Size.cx, m_Size.cy );
  96. m_pBitmap = SelectObject( &m_Bitmap );
  97. CWnd::GetDesktopWindow()->ReleaseDC( pDC );
  98. }
  99. }
  100. if( GetSafeHdc() )
  101. {
  102. CBrush brush( color );
  103. CRect rect( 0, 0, m_Size.cx, m_Size.cy );
  104. FillRect( &rect, &brush );
  105. }
  106. return TRUE;
  107. }
  108. BOOL CMemoryDC::DeleteDC()
  109. {
  110. if( m_pBitmap )
  111. {
  112. SelectObject( m_pBitmap );
  113. m_pBitmap = NULL;
  114. }
  115. if( m_Bitmap.GetSafeHandle() )
  116. m_Bitmap.DeleteObject();
  117. return CDC::DeleteDC();
  118. }