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.

172 lines
5.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: PropertySPRUWnd.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of PropertySPRUWnd.cpp
  13. //----------------------------------------------------------------------------
  14. // PropertySPRUWnd.cpp : implementation file
  15. //
  16. #include "stdafx.h"
  17. #include "chicago.h"
  18. #include "PropertySPRUWnd.h"
  19. #include "..\..\LgLib\Version.h"
  20. #ifdef _DEBUG
  21. #define new DEBUG_NEW
  22. #undef THIS_FILE
  23. static char THIS_FILE[] = __FILE__;
  24. #endif
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CPropertySPRUWnd
  27. CPropertySPRUWnd::CPropertySPRUWnd()
  28. {
  29. m_Overlay.pBitmapOld = NULL;
  30. m_Overlay.pTempBitmapOld = NULL;
  31. m_pSensor = NULL;
  32. m_Rect.bottom = m_Rect.left = m_Rect.right = m_Rect.top = 0;
  33. m_bEraseBackground = FALSE;
  34. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CPropertySPRUWnd::CPropertySPRUWnd") );
  35. }
  36. CPropertySPRUWnd::~CPropertySPRUWnd()
  37. {
  38. if( m_Overlay.pBitmapOld )
  39. {
  40. m_Overlay.DC.SelectObject( m_Overlay.pBitmapOld );
  41. m_Overlay.Bitmap.DeleteObject();
  42. }
  43. m_Overlay.DC.DeleteDC();
  44. if( m_Overlay.pTempBitmapOld )
  45. m_Overlay.TempDC.SelectObject( m_Overlay.pTempBitmapOld );
  46. m_Overlay.TempDC.DeleteDC();
  47. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CPropertySPRUWnd::~CPropertySPRUWnd") );
  48. }
  49. BEGIN_MESSAGE_MAP(CPropertySPRUWnd, CWnd)
  50. //{{AFX_MSG_MAP(CPropertySPRUWnd)
  51. ON_WM_TIMER()
  52. ON_WM_PAINT()
  53. ON_WM_RBUTTONDOWN()
  54. //}}AFX_MSG_MAP
  55. END_MESSAGE_MAP()
  56. /////////////////////////////////////////////////////////////////////////////
  57. // CPropertySPRUWnd message handlers
  58. BOOL CPropertySPRUWnd::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
  59. {
  60. CString strClassName = AfxRegisterWndClass( CS_VREDRAW|CS_HREDRAW|CS_OWNDC, ::LoadCursor( NULL, IDC_CROSS ) );
  61. if( CWnd::Create( strClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext) )
  62. {
  63. CClientDC dc(this);
  64. m_Overlay.DC.CreateCompatibleDC( &dc );
  65. m_Overlay.TempDC.CreateCompatibleDC( &dc );
  66. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CPropertySPRUWnd::Create"), _T("Succeeded") );
  67. return TRUE;
  68. }
  69. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CPropertySPRUWnd::Create"), _T("CWnd::Create failed") );
  70. return FALSE;
  71. }
  72. void CPropertySPRUWnd::SetSensor(CSensorSPRU *pSensor)
  73. {
  74. if( pSensor != m_pSensor )
  75. {
  76. CRect rect;
  77. GetClientRect( &rect );
  78. if( m_Rect != rect )
  79. {
  80. if( m_Overlay.pBitmapOld )
  81. {
  82. m_Overlay.DC.SelectObject( m_Overlay.pBitmapOld );
  83. m_Overlay.Bitmap.DeleteObject();
  84. }
  85. m_Rect = rect;
  86. CClientDC dc(this);
  87. m_Overlay.Bitmap.CreateCompatibleBitmap( &dc, m_Rect.Width(), m_Rect.Height() );
  88. m_Overlay.pBitmapOld = m_Overlay.DC.SelectObject( &m_Overlay.Bitmap );
  89. m_Overlay.DC.FillSolidRect( &m_Rect, 0 );
  90. }
  91. if( pSensor->GetBitmap() )
  92. {
  93. if( !(m_pSensor && m_pSensor->GetBitmap() == pSensor->GetBitmap()) )
  94. {
  95. BITMAPINFO bi;
  96. bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  97. bi.bmiHeader.biCompression = bi.bmiHeader.biPlanes = bi.bmiHeader.biBitCount = 0;
  98. ::GetDIBits( m_Overlay.DC.GetSafeHdc(), (HBITMAP)pSensor->GetBitmap()->GetSafeHandle(), 0, 0, NULL, &bi, DIB_RGB_COLORS );
  99. m_Overlay.pTempBitmapOld = m_Overlay.TempDC.SelectObject( pSensor->GetBitmap() );
  100. m_Overlay.DC.StretchBlt( 0, 0, m_Rect.Width(), m_Rect.Height(), &m_Overlay.TempDC, 0, 0, bi.bmiHeader.biWidth, bi.bmiHeader.biHeight, SRCCOPY );
  101. }
  102. }
  103. else
  104. {
  105. COLORREF OldBkColor = m_Overlay.DC.SetBkColor( 0x00 );
  106. m_Overlay.DC.ExtTextOut( 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL );
  107. m_Overlay.DC.SetBkColor( OldBkColor );
  108. }
  109. m_pSensor = pSensor;
  110. m_bEraseBackground = TRUE;
  111. }
  112. }
  113. void CPropertySPRUWnd::OnTimer( UINT nIDEvent )
  114. {
  115. CClientDC dc(this);
  116. if( m_bEraseBackground )
  117. {
  118. dc.BitBlt( 0, 0, m_Rect.Width(), m_Rect.Height(), &m_Overlay.DC, 0, 0, SRCCOPY );
  119. m_bEraseBackground = FALSE;
  120. }
  121. if( m_pSensor )
  122. m_pSensor->PaintBits( &dc, m_Rect, nIDEvent );
  123. m_bInverse = nIDEvent;
  124. CWnd::OnTimer(nIDEvent);
  125. }
  126. void CPropertySPRUWnd::OnPaint()
  127. {
  128. CPaintDC dc(this); // device context for painting
  129. dc.BitBlt( 0, 0, m_Rect.Width(), m_Rect.Height(), &m_Overlay.DC, 0, 0, SRCCOPY );
  130. if( m_pSensor )
  131. m_pSensor->PaintBits( &dc, m_Rect, m_bInverse );
  132. }
  133. void CPropertySPRUWnd::OnRButtonDown( UINT nFlags, CPoint point )
  134. {
  135. SDPOINT dp;
  136. CRect rect;
  137. GetClientRect( &rect );
  138. dp.x = ((double)point.x) / (double)rect.Width();
  139. dp.y = ((double)point.y) / (double)rect.Height();
  140. GetParent()->GetParent()->SendMessage( WM_ENABLE_DTRBIT, (WPARAM)m_pSensor, m_pSensor->GetBitIndex( &dp ) );
  141. CWnd::OnRButtonDown(nFlags, point);
  142. }