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.

280 lines
6.8 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 24/03/2000
  5. // Last modification: 08/10/2003
  6. // Project Intruder Position Indicator
  7. // SUBSYSTEM: Video camera showing and captiring window
  8. // FILE: VideoStaticWnd.cpp
  9. // AUTHOR: Chizhevskiy Sergey
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file for implementation of class CVideoStaticWnd
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "..\LgLib\Version.h"
  16. /*
  17. #include "VideoStaticWnd.h"
  18. CVideoStaticWnd::CVideoStaticWnd( CProfile *pProfile, HWND hParentWnd, LPPOINT pPoint, LPSIZE pSize )
  19. {
  20. m_hWnd = NULL;
  21. m_hMemDC = NULL;
  22. m_hMemBitmap = NULL;
  23. m_bEnabled = FALSE;
  24. SetProfile( pProfile );
  25. Create(hParentWnd, pPoint, pSize);
  26. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CVideoStaticWnd::CVideoStaticWnd(...)" );
  27. }
  28. CVideoStaticWnd::CVideoStaticWnd()
  29. {
  30. m_hWnd = NULL;
  31. m_hMemDC = NULL;
  32. m_hMemBitmap = NULL;
  33. m_bEnabled = FALSE;
  34. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CVideoStaticWnd::CVideoStaticWnd" );
  35. }
  36. CVideoStaticWnd::~CVideoStaticWnd()
  37. {
  38. if(m_hMemDC)
  39. ::DeleteDC( m_hMemDC );
  40. if(m_hMemBitmap)
  41. ::DeleteObject( m_hMemBitmap );
  42. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CVideoStaticWnd::~CVideoStaticWnd" );
  43. }
  44. BOOL CVideoStaticWnd::Create(HWND hParentWnd, LPPOINT pPoint, LPSIZE pSize )
  45. {
  46. static POINT point = {0,0};
  47. static SIZE size = {10,10};
  48. if( !pPoint )
  49. pPoint = &point;
  50. if( !pSize )
  51. pSize = &size;
  52. HWND hWnd = ::GetDesktopWindow();
  53. HDC hDC = ::GetDC( hWnd );
  54. m_hMemDC = ::CreateCompatibleDC( hDC );
  55. ::ReleaseDC( hWnd, hDC );
  56. WNDCLASS wc;
  57. wc.cbClsExtra = 0;
  58. wc.cbWndExtra = 0;
  59. wc.hbrBackground = NULL;
  60. wc.hCursor = NULL;
  61. wc.hIcon = NULL;
  62. wc.hInstance = (HINSTANCE)::GetWindowLong(hParentWnd, GWL_HINSTANCE);
  63. wc.lpfnWndProc = (WNDPROC)WndProc_;
  64. wc.lpszClassName = "VideoStaticWnd";
  65. wc.lpszMenuName = NULL;
  66. wc.style = CS_HREDRAW | CS_VREDRAW;
  67. if( !::RegisterClass( &wc ) )
  68. return false;
  69. m_hWnd = ::CreateWindowEx( WS_EX_DLGMODALFRAME|WS_EX_CLIENTEDGE, wc.lpszClassName, "", WS_CHILD,
  70. pPoint->x, pPoint->y, pSize->cx, pSize->cy,
  71. hParentWnd, NULL, wc.hInstance, this );
  72. if(!m_hWnd)
  73. return false;
  74. ::ShowWindow( m_hWnd, m_bEnabled ? SW_SHOW : SW_HIDE );
  75. ::UpdateWindow( m_hWnd );
  76. if( !VSW_BASE_CLASS::Create( hParentWnd, pPoint, pSize ) )
  77. return false;
  78. ::ShowWindow( VSW_BASE_CLASS::GetSafeHwnd(), m_bEnabled ? SW_HIDE : SW_SHOW);
  79. Enable( true );
  80. return true;
  81. }
  82. LRESULT CVideoStaticWnd::WndProc_( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam )
  83. {
  84. LPCREATESTRUCT pCreateStruct;
  85. CVideoStaticWnd *pThis = NULL;
  86. switch( nMsg )
  87. {
  88. case WM_CREATE:
  89. pCreateStruct = (LPCREATESTRUCT) lParam;
  90. pThis = (CVideoStaticWnd*)pCreateStruct->lpCreateParams;
  91. ::SetWindowLong( hWnd, GWL_USERDATA, (LONG)pThis );
  92. break;
  93. default:
  94. pThis = (CVideoStaticWnd*)::GetWindowLong( hWnd, GWL_USERDATA );
  95. break;
  96. }
  97. if( pThis )
  98. return pThis->WndProc( hWnd, nMsg, wParam, lParam );
  99. return ::DefWindowProc( hWnd, nMsg, wParam, lParam );
  100. }
  101. LRESULT CVideoStaticWnd::WndProc( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam )
  102. {
  103. switch( nMsg )
  104. {
  105. case WM_PAINT:
  106. return OnPaint( wParam, lParam );
  107. case WM_SIZE:
  108. return OnSize( wParam, lParam );
  109. case WM_MOVE:
  110. return OnMove( wParam, lParam );
  111. }
  112. return ::DefWindowProc( hWnd, nMsg, wParam, lParam );
  113. }
  114. void CVideoStaticWnd::Snapshot()
  115. {
  116. volatile static BOOL fInside = FALSE;
  117. HBITMAP fSuccess = NULL;
  118. if( !fInside && m_bEnabled )
  119. {
  120. fInside = TRUE;
  121. if( m_hMemBitmap )
  122. ::DeleteObject( m_hMemBitmap );
  123. m_hMemBitmap = (HBITMAP)GetSnapshot();
  124. HDC hDC = ::GetDC( m_hWnd );
  125. OnDraw( hDC );
  126. ::ReleaseDC( m_hWnd, hDC );
  127. fInside = FALSE;
  128. }
  129. }
  130. void CVideoStaticWnd::OnDraw( HDC hDC )
  131. {
  132. RECT rect;
  133. ::GetClientRect( m_hWnd, &rect );
  134. if( m_hMemBitmap )
  135. {
  136. DIBSECTION DibSection;
  137. if( ::GetObject( m_hMemBitmap, sizeof(DIBSECTION), &DibSection ) )
  138. {
  139. HBITMAP hBitmap = (HBITMAP)::SelectObject( m_hMemDC, m_hMemBitmap );
  140. int nOldMode = ::SetStretchBltMode( hDC, COLORONCOLOR );
  141. ::StretchBlt( hDC, 0, 0, rect.right - rect.left, rect.bottom - rect.top,
  142. m_hMemDC, 0, 0, DibSection.dsBm.bmWidth, DibSection.dsBm.bmHeight, SRCCOPY );
  143. ::SetStretchBltMode( hDC, nOldMode );
  144. ::SelectObject( m_hMemDC, hBitmap );
  145. }
  146. }
  147. else
  148. {
  149. COLORREF nColor = RGB( 0,0,0 );
  150. COLORREF nBkColor = RGB( 0x7F,0x7F,0x7F );
  151. HBRUSH hBrush = ::CreateSolidBrush( nBkColor );
  152. HPEN hPen = ::CreatePen( PS_SOLID, 1, nBkColor );
  153. ::FillRect( hDC, &rect, hBrush );
  154. HBRUSH hBrushOld = (HBRUSH)::SelectObject( hDC, hBrush );
  155. HPEN hPenOld = (HPEN)::SelectObject( hDC, hPen );
  156. TCHAR pText[] = _T("NO VIDEO");
  157. INT nText = _tcslen( pText );
  158. COLORREF nColorOld = ::SetTextColor( hDC, nColor );
  159. INT nBkModeOld = ::SetBkMode( hDC, TRANSPARENT );
  160. ::DrawText( hDC, pText, nText, &rect, DT_SINGLELINE | DT_VCENTER | DT_CENTER );
  161. ::SetBkMode( hDC, nBkModeOld );
  162. ::SetTextColor( hDC, nColorOld );
  163. ::SelectObject( hDC, hBrushOld );
  164. ::SelectObject( hDC, hPenOld );
  165. ::DeleteObject( hBrush );
  166. ::DeleteObject( hPen );
  167. }
  168. }
  169. LRESULT CVideoStaticWnd::OnSize( WPARAM wParam, LPARAM lParam )
  170. {
  171. HWND hParentWnd = (HWND)::GetWindowLong( m_hWnd, GWL_HWNDPARENT );
  172. RECT rect;
  173. ::GetClientRect( m_hWnd, &rect );
  174. ::MapWindowPoints( m_hWnd, hParentWnd, (LPPOINT)&rect, 2 );
  175. ::MoveWindow( VSW_BASE_CLASS::GetSafeHwnd(), rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, TRUE );
  176. return TRUE;
  177. }
  178. LRESULT CVideoStaticWnd::OnPaint( WPARAM wParam, LPARAM lParam )
  179. {
  180. PAINTSTRUCT ps;
  181. HDC hDC = ::BeginPaint( m_hWnd, &ps );
  182. OnDraw( hDC );
  183. ::EndPaint( m_hWnd, &ps );
  184. return TRUE;
  185. }
  186. void CVideoStaticWnd::Enable(BOOL bEnable)
  187. {
  188. m_bEnabled = bEnable;
  189. VSW_BASE_CLASS::ShowWindow( m_bEnabled ? SW_HIDE : SW_SHOW );
  190. // ShowWindow( m_bEnabled ? SW_SHOW : SW_HIDE );
  191. ::BringWindowToTop( m_bEnabled ? GetSafeHwnd() : VSW_BASE_CLASS::GetSafeHwnd() );
  192. ::InvalidateRect( VSW_BASE_CLASS::GetSafeHwnd(), NULL, FALSE );
  193. ::UpdateWindow( VSW_BASE_CLASS::GetSafeHwnd() );
  194. // ::ShowWindow( m_hWnd, m_bEnabled ? SW_SHOW : SW_HIDE );
  195. // ::UpdateWindow( m_hWnd );
  196. HWND hParentWnd = (HWND)::GetWindowLong( m_hWnd, GWL_HWNDPARENT );
  197. ::InvalidateRect( hParentWnd, NULL, FALSE );
  198. ::UpdateWindow( hParentWnd );
  199. }
  200. LRESULT CVideoStaticWnd::OnMove(WPARAM wParam, LPARAM lParam)
  201. {
  202. int xPos = (int)(short) LOWORD(lParam); // horizontal position
  203. int yPos = (int)(short) HIWORD(lParam); // vertical position
  204. return TRUE;
  205. }
  206. */