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.

396 lines
9.4 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
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: EventWnd.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of EventWnd.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "EventWnd.h"
  16. #include "..\LgLib\Version.h"
  17. CEventWnd::CEventWnd()
  18. {
  19. m_hWnd = NULL;
  20. m_hMemDC = NULL;
  21. m_hMemBitmap = NULL;
  22. m_hMemFont = NULL;
  23. m_bEnable = TRUE;
  24. m_bDebug = FALSE;
  25. m_pProfile = NULL;
  26. }
  27. CEventWnd::~CEventWnd()
  28. {
  29. Destroy();
  30. }
  31. BOOL CEventWnd::Create( BOOL bDebug, HWND hParent, INT x, INT y, INT cx, INT cy, CProfile *pProfile )
  32. {
  33. m_pProfile = pProfile;
  34. WNDCLASSEX wc;
  35. wc.cbSize = sizeof(WNDCLASSEX);
  36. wc.style = CS_HREDRAW | CS_VREDRAW;
  37. wc.lpfnWndProc = WindowProc_;
  38. wc.cbClsExtra = 0;
  39. wc.cbWndExtra = 0;
  40. wc.hInstance = (HINSTANCE)::GetWindowLong( hParent, GWL_HINSTANCE );
  41. wc.hIcon = NULL;
  42. wc.hCursor = NULL;
  43. wc.hbrBackground = NULL;
  44. wc.lpszMenuName = NULL;
  45. wc.lpszClassName = "SINGLE_IPI_EVENT_WINDOW";
  46. wc.hIconSm = NULL;
  47. if( !::RegisterClassEx( &wc ) )
  48. return FALSE;
  49. m_hWnd = ::CreateWindowEx( /*WS_EX_DLGMODALFRAME|*/WS_EX_CLIENTEDGE, wc.lpszClassName, NULL, WS_CHILD, x, y, cx, cy, hParent, NULL, wc.hInstance, this );
  50. if( !m_hWnd )
  51. return FALSE;
  52. ::ShowWindow( m_hWnd, SW_SHOW );
  53. ::UpdateWindow( m_hWnd );
  54. // create icons
  55. HDC hDC = ::GetDC( m_hWnd );
  56. m_hIconsDC = ::CreateCompatibleDC( hDC );
  57. m_hIconsBitmap = ::LoadBitmap( wc.hInstance, MAKEINTRESOURCE(IDB_BITMAP_TARGET) );
  58. ::ReleaseDC( m_hWnd, hDC );
  59. // create font
  60. LOGFONT lf = {0};
  61. lf.lfHeight = 15;
  62. lf.lfWidth = 0;
  63. lf.lfEscapement = 0;
  64. lf.lfOrientation = 0;
  65. lf.lfWeight = 0;
  66. lf.lfItalic = FALSE;
  67. lf.lfUnderline = FALSE;
  68. lf.lfStrikeOut = FALSE;
  69. lf.lfCharSet = ANSI_CHARSET;
  70. lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
  71. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  72. lf.lfQuality = DEFAULT_QUALITY;
  73. lf.lfPitchAndFamily = FIXED_PITCH | FF_MODERN;
  74. _tcscpy(lf.lfFaceName, "Courier");
  75. m_hMemFont = ::CreateFontIndirect( &lf );
  76. m_bDebug = bDebug;
  77. return TRUE;
  78. }
  79. void CEventWnd::Destroy()
  80. {
  81. if( m_hWnd )
  82. ::DestroyWindow( m_hWnd );
  83. }
  84. LRESULT CALLBACK CEventWnd::WindowProc_( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  85. {
  86. LPCREATESTRUCT pCreateStruct;
  87. switch( uMsg )
  88. {
  89. case WM_CREATE:
  90. pCreateStruct = (LPCREATESTRUCT) lParam;
  91. ::SetWindowLong( hWnd, GWL_USERDATA, (LONG)pCreateStruct->lpCreateParams );
  92. break;
  93. }
  94. CEventWnd *pThis = (CEventWnd*)::GetWindowLong( hWnd, GWL_USERDATA );
  95. if( pThis )
  96. return pThis->WindowProc( uMsg, wParam, lParam );
  97. return ::DefWindowProc( hWnd, uMsg, wParam, lParam );
  98. }
  99. LRESULT CEventWnd::WindowProc( UINT uMsg, WPARAM wParam, LPARAM lParam )
  100. {
  101. switch( uMsg )
  102. {
  103. case WM_DESTROY:
  104. return OnDestroy( wParam, lParam );
  105. case WM_PAINT:
  106. return OnPaint( wParam, lParam );
  107. case WM_SIZE:
  108. return OnSize( wParam, lParam );
  109. }
  110. return ::DefWindowProc( m_hWnd, uMsg, wParam, lParam );
  111. }
  112. LRESULT CEventWnd::OnDestroy( WPARAM wParam, LPARAM lParam )
  113. {
  114. if( m_hIconsDC )
  115. {
  116. ::DeleteDC( m_hIconsDC );
  117. m_hIconsDC = NULL;
  118. }
  119. if( m_hIconsBitmap )
  120. {
  121. ::DeleteObject( m_hIconsBitmap );
  122. m_hIconsBitmap = NULL;
  123. }
  124. if( m_hMemDC )
  125. {
  126. ::DeleteDC( m_hMemDC );
  127. m_hMemDC = NULL;
  128. }
  129. if( m_hMemBitmap )
  130. {
  131. ::DeleteObject( m_hMemBitmap );
  132. m_hMemBitmap = NULL;
  133. }
  134. if( m_hMemFont )
  135. {
  136. ::DeleteObject( m_hMemFont );
  137. m_hMemFont = NULL;
  138. }
  139. HWND hWnd = m_hWnd;
  140. m_hWnd = NULL;
  141. return ::DefWindowProc( hWnd, WM_DESTROY, wParam, lParam );
  142. }
  143. LRESULT CEventWnd::OnSize( WPARAM wParam, LPARAM lParam )
  144. {
  145. UINT fwSizeType = wParam;
  146. INT nWidth = LOWORD(lParam);
  147. INT nHeight = HIWORD(lParam);
  148. // check old bitmap
  149. BOOL bBitmapCreated = FALSE;
  150. if( m_hMemBitmap )
  151. {
  152. DIBSECTION DibSection;
  153. if( ::GetObject( m_hMemBitmap, sizeof(DibSection), &DibSection ) )
  154. {
  155. if( DibSection.dsBm.bmWidth == nWidth &&
  156. DibSection.dsBm.bmHeight == nHeight )
  157. {
  158. bBitmapCreated = TRUE;
  159. }
  160. }
  161. }
  162. // create new bitmap
  163. if( !m_hMemDC || !bBitmapCreated )
  164. {
  165. HDC hDC = ::GetDC( m_hWnd );
  166. if( hDC )
  167. {
  168. if( !m_hMemDC )
  169. m_hMemDC = ::CreateCompatibleDC( hDC );
  170. if( !bBitmapCreated )
  171. {
  172. if( m_hMemBitmap )
  173. ::DeleteObject( m_hMemBitmap );
  174. m_hMemBitmap = ::CreateCompatibleBitmap( hDC, nWidth, nHeight );
  175. }
  176. ::ReleaseDC( m_hWnd, hDC );
  177. }
  178. }
  179. // paint bitmap
  180. if( m_hMemDC && m_hMemBitmap )
  181. {
  182. HBITMAP hBitmap = (HBITMAP)::SelectObject( m_hMemDC, m_hMemBitmap );
  183. HBRUSH hBrush = ::CreateSolidBrush( RGB(255,255,255) );
  184. if( hBrush )
  185. {
  186. RECT rect = { 0, 0, nWidth, nHeight };
  187. ::FillRect( m_hMemDC, &rect, hBrush );
  188. ::DeleteObject( hBrush );
  189. }
  190. ::SelectObject( m_hMemDC, hBitmap );
  191. }
  192. return 0;
  193. }
  194. LRESULT CEventWnd::OnPaint( WPARAM wParam, LPARAM lParam )
  195. {
  196. PAINTSTRUCT ps;
  197. HDC hDC = ::BeginPaint( m_hWnd, &ps );
  198. if( hDC )
  199. OnDraw( hDC );
  200. ::EndPaint( m_hWnd, &ps );
  201. return 0;
  202. }
  203. void CEventWnd::OnDraw( HDC hDC )
  204. {
  205. if( !m_hMemDC || !m_hMemBitmap )
  206. return;
  207. DIBSECTION DibSection;
  208. if( !::GetObject( m_hMemBitmap, sizeof(DibSection), &DibSection ) )
  209. return;
  210. HBITMAP hBitmap = (HBITMAP)::SelectObject( m_hMemDC, m_hMemBitmap );
  211. ::BitBlt( hDC, 0, 0, DibSection.dsBm.bmWidth, DibSection.dsBm.bmHeight, m_hMemDC, 0, 0, SRCCOPY );
  212. ::SelectObject( m_hMemDC, hBitmap );
  213. }
  214. void CEventWnd::Reset()
  215. {
  216. RECT rect;
  217. ::GetClientRect( m_hWnd, &rect );
  218. HBITMAP hOldBitmap = (HBITMAP)::SelectObject(m_hMemDC, m_hMemBitmap);
  219. ::FillRect(m_hMemDC, &rect, (HBRUSH)::GetStockObject(WHITE_BRUSH));
  220. ::SelectObject(m_hMemDC, hOldBitmap);
  221. ::InvalidateRect( m_hWnd, &rect, FALSE );
  222. ::UpdateWindow( m_hWnd );
  223. }
  224. void CEventWnd::AddTarget(TARGET_DESCRIPTION& td)
  225. {
  226. if( !m_bEnable )
  227. return;
  228. RECT rect;
  229. ::GetClientRect( m_hWnd, &rect );
  230. TCHAR pText[0x500];
  231. HFONT hFont = (HFONT)::SelectObject( m_hMemDC, m_hMemFont );
  232. HBITMAP hOldBitmap = (HBITMAP)::SelectObject(m_hMemDC, m_hMemBitmap);
  233. ::ScrollDC(m_hMemDC, 0, 20, &rect, &rect, NULL, NULL);
  234. HBRUSH hBrush = ::CreateSolidBrush( RGB(255,255,255) );
  235. if( hBrush )
  236. {
  237. RECT fRect = rect;
  238. fRect.bottom = rect.top + 20;
  239. ::FillRect(m_hMemDC, &fRect, hBrush );
  240. ::DeleteObject( hBrush );
  241. }
  242. if( m_bDebug )
  243. {
  244. HBITMAP hIconsBitmap = (HBITMAP)::SelectObject( m_hIconsDC, m_hIconsBitmap );
  245. switch(td.master)
  246. {
  247. case 'a':
  248. ::BitBlt( m_hMemDC, 2, 2, 16, 16, m_hIconsDC, 0, 0, SRCCOPY );
  249. break;
  250. case 'b':
  251. ::BitBlt( m_hMemDC, 2, 2, 16, 16, m_hIconsDC, 0, 16, SRCCOPY );
  252. break;
  253. case 'f':
  254. ::BitBlt( m_hMemDC, 2, 2, 16, 16, m_hIconsDC, 0, 32, SRCCOPY );
  255. break;
  256. case 'w':
  257. ::BitBlt( m_hMemDC, 2, 2, 16, 16, m_hIconsDC, 0, 48, SRCCOPY );
  258. break;
  259. case 'q':
  260. ::BitBlt( m_hMemDC, 2, 2, 16, 16, m_hIconsDC, 0, 64, SRCCOPY );
  261. break;
  262. }
  263. ::SelectObject( m_hIconsDC, hIconsBitmap );
  264. }
  265. // convert angle into user coordinate system
  266. double dAngle = m_pProfile->ConvertToUserCoordinate( td.angle );
  267. if( td.master == 'f' )
  268. _stprintf(pText, _T("%02d/%02d/%02d %02d:%02d:%02d DRD "),
  269. td.time.wDay, td.time.wMonth, td.time.wYear,
  270. td.time.wHour, td.time.wMinute, td.time.wSecond);
  271. else
  272. if( td.master == 'q' )
  273. {
  274. _stprintf( pText, _T("%02d/%02d/%02d %02d:%02d:%02d %3.0f� (dopler)\r\n"),
  275. td.time.wDay, td.time.wMonth, td.time.wYear,
  276. td.time.wHour, td.time.wMinute, td.time.wSecond,
  277. dAngle );
  278. }
  279. else
  280. #ifdef DRAW_TARGET_WIDTH
  281. _stprintf(pText, _T("%02d/%02d/%02d %02d:%02d:%02d %3.0f� %5.1fm. (W %ld)"),
  282. td.time.wDay, td.time.wMonth, td.time.wYear,
  283. td.time.wHour, td.time.wMinute, td.time.wSecond,
  284. dAngle, td.range, td.width );
  285. #else
  286. _stprintf(pText, _T("%02d/%02d/%02d %02d:%02d:%02d %3.0f� %5.1fm."),
  287. td.time.wDay, td.time.wMonth, td.time.wYear,
  288. td.time.wHour, td.time.wMinute, td.time.wSecond,
  289. dAngle, td.range );
  290. #endif
  291. ::TextOut(m_hMemDC, 20, 0, pText, _tcslen(pText));
  292. ::SelectObject(m_hMemDC, hOldBitmap);
  293. ::SelectObject( m_hMemDC, hFont );
  294. ::InvalidateRect( m_hWnd, &rect, FALSE);
  295. ::UpdateWindow( m_hWnd );
  296. }
  297. void CEventWnd::AddText(LPCTSTR pText)
  298. {
  299. if( !m_bEnable )
  300. return;
  301. RECT rect;
  302. ::GetClientRect( m_hWnd, &rect );
  303. HBITMAP hOldBitmap = (HBITMAP)::SelectObject(m_hMemDC, m_hMemBitmap);
  304. HFONT hFont = (HFONT)::SelectObject( m_hMemDC, m_hMemFont );
  305. ::ScrollDC(m_hMemDC, 0, 20, &rect, &rect, NULL, NULL);
  306. HBRUSH hBrush = ::CreateSolidBrush( RGB(255,255,255) );
  307. if( hBrush )
  308. {
  309. RECT fRect = rect;
  310. fRect.bottom = rect.top + 20;
  311. ::FillRect(m_hMemDC, &fRect, hBrush );
  312. ::DeleteObject( hBrush );
  313. }
  314. SYSTEMTIME time;
  315. ::GetLocalTime( &time );
  316. TCHAR pBuffer[MAX_PATH];
  317. INT nBuffer = _sntprintf( pBuffer, MAX_PATH, _T("%02d/%02d/%02d %02d:%02d:%02d %s"),
  318. time.wDay, time.wMonth, time.wYear,
  319. time.wHour, time.wMinute, time.wSecond, pText );
  320. if( nBuffer < 0 )
  321. nBuffer = MAX_PATH;
  322. ::TextOut(m_hMemDC, 20, 0, pBuffer, nBuffer );
  323. ::SelectObject( m_hMemDC, hFont );
  324. ::SelectObject(m_hMemDC, hOldBitmap);
  325. ::InvalidateRect( m_hWnd, &rect, FALSE);
  326. ::UpdateWindow( m_hWnd );
  327. }