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.

186 lines
4.7 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: LgsStateWnd.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of LgsStateWnd.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "Resource.h"
  16. #include "LgsStateWnd.h"
  17. #include "..\LgLib\Version.h"
  18. CLgsStateWnd::CLgsStateWnd()
  19. {
  20. m_bStudyMode = TRUE;
  21. m_bLowPowerMode = FALSE;
  22. m_bLowPowerModeBlink = FALSE;
  23. m_nStep = -1;
  24. memset( m_pIcon, 0, sizeof(m_pIcon) );
  25. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgsStateWnd::CLgsStateWnd") );
  26. }
  27. CLgsStateWnd::~CLgsStateWnd()
  28. {
  29. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgsStateWnd::~CLgsStateWnd") );
  30. }
  31. BOOL CLgsStateWnd::Create( HWND hParentWnd, INT x, INT y, INT cx, INT cy )
  32. {
  33. LPCTSTR lpszClassName = _T("LgsStateWndClass");
  34. HINSTANCE hInstance = (HINSTANCE)::GetWindowLong( hParentWnd, GWL_HINSTANCE );
  35. // create icons
  36. UINT pIconID[ICON_COUNT] =
  37. {
  38. IDI_ICON_01, IDI_ICON_02, IDI_ICON_03, IDI_ICON_04, IDI_ICON_05, IDI_ICON_06, IDI_ICON_07, IDI_ICON_08,
  39. IDI_ICON_DISCONNECTION,
  40. IDI_ICON_STUDY,
  41. IDI_ICON_POWER,
  42. };
  43. for( INT i = 0; i < ICON_COUNT; i++ )
  44. {
  45. m_pIcon[i] = (HICON)LoadImage( hInstance, (LPCTSTR)pIconID[i], IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR );
  46. if( !m_pIcon[i] )
  47. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgsStateWnd::Create"), _T("LoadImage failed for icon ID %d"), pIconID[i] );
  48. }
  49. // register window class
  50. if( !CGenericWnd::RegisterClass( lpszClassName, hInstance ) )
  51. {
  52. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgsStateWnd::Create"), _T("CGenericWnd::RegisterClass failed") );
  53. return FALSE;
  54. }
  55. // create window
  56. if( !CGenericWnd::Create( lpszClassName, NULL, WS_CHILD | WS_VISIBLE, x, y, cx, cy, hParentWnd, NULL, hInstance ) )
  57. {
  58. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgsStateWnd::Create"), _T("CGenericWnd::Create failed") );
  59. return FALSE;
  60. }
  61. // set timer for power blinking
  62. if( !CGenericWnd::SetTimer( 1, 250, NULL ) )
  63. {
  64. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgsStateWnd::Create"), _T("CGenericWnd::SetTimer failed") );
  65. return FALSE;
  66. }
  67. // update window contents
  68. Draw();
  69. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgsStateWnd::Create"), _T("Done successefully") );
  70. return TRUE;
  71. }
  72. void CLgsStateWnd::SetStudyMode( BOOL bStudyMode )
  73. {
  74. m_bStudyMode = bStudyMode;
  75. Draw();
  76. }
  77. void CLgsStateWnd::SetLowPowerMode( BOOL bLowPowerMode )
  78. {
  79. m_bLowPowerMode = bLowPowerMode;
  80. Draw();
  81. }
  82. void CLgsStateWnd::Step( INT nStep )
  83. {
  84. m_nStep = nStep;
  85. Draw();
  86. }
  87. void CLgsStateWnd::Draw()
  88. {
  89. RECT rect;
  90. GetClientRect( &rect );
  91. m_MemoryDC.FillSolidRect( &rect, ::GetSysColor(COLOR_BTNFACE) );
  92. if( m_nStep == -1 )
  93. m_MemoryDC.DrawIcon( 0, 0, m_pIcon[DISCONNECTION] );
  94. else
  95. {
  96. if( m_bStudyMode )
  97. m_MemoryDC.DrawIcon( 0, 0, m_pIcon[STUDY] );
  98. if( m_bLowPowerMode && m_bLowPowerModeBlink )
  99. m_MemoryDC.DrawIcon( 0, 0, m_pIcon[POWER] );
  100. m_MemoryDC.DrawIcon( 0, 0, m_pIcon[m_nStep] );
  101. }
  102. InvalidateRect( NULL, FALSE );
  103. UpdateWindow();
  104. }
  105. LRESULT CLgsStateWnd::OnPaint( WPARAM, LPARAM )
  106. {
  107. PAINTSTRUCT ps;
  108. HDC hDC = BeginPaint( &ps );
  109. RECT rect;
  110. GetClientRect( &rect );
  111. ::BitBlt( hDC, 0, 0, rect.right, rect.bottom, m_MemoryDC.GetSafeHdc(), 0, 0, SRCCOPY );
  112. EndPaint( &ps );
  113. LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CLgsStateWnd::OnSize") );
  114. return TRUE;
  115. }
  116. LRESULT CLgsStateWnd::OnSize( WPARAM wParam, LPARAM lParam )
  117. {
  118. UINT nType = wParam;
  119. INT cx = (INT)LOWORD( lParam );
  120. INT cy = (INT)HIWORD( lParam );
  121. if( !m_MemoryDC.Create( cx, cy ) )
  122. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgsStateWnd::OnSize"), _T("m_MemoryDC.Create failed") );
  123. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CLgsStateWnd::OnSize") );
  124. return TRUE;
  125. }
  126. LRESULT CLgsStateWnd::OnDestroy( WPARAM wParam, LPARAM lParam )
  127. {
  128. // destroy icons
  129. for( INT i = 0; i < ICON_COUNT; i++ )
  130. {
  131. ::DestroyIcon( m_pIcon[i] );
  132. m_pIcon[i] = NULL;
  133. }
  134. // kill timer
  135. KillTimer( 1 );
  136. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgsStateWnd::OnDestroy") );
  137. return CGenericWnd::OnDestroy( wParam, lParam );
  138. }
  139. LRESULT CLgsStateWnd::OnTimer( WPARAM, LPARAM )
  140. {
  141. // flip blinking state
  142. m_bLowPowerModeBlink = !m_bLowPowerModeBlink;
  143. // redraw content
  144. Draw();
  145. LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CLgsStateWnd::OnTimer") );
  146. return TRUE;
  147. }