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.

450 lines
11 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: 13/04/2001
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: EventsDlg.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of EventsDlg.cpp
  13. //----------------------------------------------------------------------------
  14. // EventsDlg.cpp : implementation file
  15. //
  16. #include "stdafx.h"
  17. #include "chicago.h"
  18. #include "Sensor.h"
  19. #include "SensorSPRU.h"
  20. #include "EventsDlg.h"
  21. #include "ShellApi.h"
  22. #include "SensorArray.h"
  23. #include "SocketRS232.h"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CEventsDlg dialog
  31. CEventsDlg::CEventsDlg(CWnd* pParent /*=NULL*/)
  32. : CDialog(CEventsDlg::IDD, pParent)
  33. {
  34. //{{AFX_DATA_INIT(CEventsDlg)
  35. // NOTE: the ClassWizard will add member initialization here
  36. //}}AFX_DATA_INIT
  37. WNDCLASS wc;
  38. wc.cbClsExtra = 0;
  39. wc.cbWndExtra = 0;
  40. wc.hbrBackground = (HBRUSH)COLOR_BTNFACE;
  41. wc.hCursor = (HCURSOR)LoadCursor( NULL, IDC_ARROW );
  42. wc.hIcon = NULL;
  43. wc.hInstance = ::AfxGetInstanceHandle();
  44. wc.lpszClassName = "EventViewClass";
  45. wc.lpszMenuName = NULL;
  46. wc.style = CS_HREDRAW | CS_VREDRAW;
  47. wc.lpfnWndProc = ::WndProcEvent;
  48. ::RegisterClass( &wc );
  49. m_pOverlayBitmapOld = NULL;
  50. m_bPrint = FALSE;
  51. m_nPrintCount = 0;
  52. m_pSensorArray = NULL;
  53. m_bChanged = FALSE;
  54. }
  55. void CEventsDlg::DoDataExchange(CDataExchange* pDX)
  56. {
  57. CDialog::DoDataExchange(pDX);
  58. //{{AFX_DATA_MAP(CEventsDlg)
  59. //}}AFX_DATA_MAP
  60. }
  61. BEGIN_MESSAGE_MAP(CEventsDlg, CDialog)
  62. //{{AFX_MSG_MAP(CEventsDlg)
  63. ON_WM_MOVING()
  64. ON_WM_DESTROY()
  65. ON_WM_SIZE()
  66. ON_WM_SIZING()
  67. ON_MESSAGE( WM_SENSOR_EVENT, OnWMSensorEvent )
  68. ON_MESSAGE( WM_SOCKET_EVENT, OnWMSocketEvent )
  69. ON_WM_TIMER()
  70. //}}AFX_MSG_MAP
  71. END_MESSAGE_MAP()
  72. /////////////////////////////////////////////////////////////////////////////
  73. // CEventsDlg message handlers
  74. /*
  75. void CEventsDlg::OnCheckPrint()
  76. {
  77. static CDC dstDC;
  78. if( m_btnPrint.GetCheck() )
  79. {
  80. CPrintDialog prnDlg( TRUE );
  81. prnDlg.DoModal();
  82. m_PrintDC.CreateDC( prnDlg.GetDriverName(), prnDlg.GetDeviceName(), NULL, NULL );
  83. DOCINFO di;
  84. di.cbSize = sizeof( DOCINFO );
  85. di.fwType = 0;
  86. di.lpszDatatype = "raw";
  87. di.lpszDocName = "text";
  88. di.lpszOutput = NULL;
  89. m_PrintDC.StartDoc( &di );
  90. m_PrintDC.StartPage();
  91. m_bPrint = TRUE;
  92. }
  93. else
  94. {
  95. m_bPrint = FALSE;
  96. m_PrintDC.EndPage();
  97. m_PrintDC.EndDoc();
  98. m_PrintDC.DeleteDC();
  99. }
  100. CFileDialog fd( TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_EXPLORER );
  101. fd.DoModal();
  102. CHAR pBuffer[MAX_PATH];
  103. BROWSEINFO bi;
  104. bi.hwndOwner = GetSafeHwnd();
  105. bi.pidlRoot = NULL;
  106. bi.pszDisplayName = pBuffer;
  107. bi.lpszTitle = "BROWSER";
  108. bi.lpfn = NULL;
  109. bi.lParam = 0;
  110. bi.ulFlags = 0;
  111. bi.iImage = 0;
  112. SHBrowseForFolder( &bi );
  113. }
  114. */
  115. LRESULT CEventsDlg::OnWMSensorEvent(WPARAM wParam, LPARAM lParam)
  116. {
  117. /* CWnd *pWnd = GetDlgItem( IDC_CUSTOM_EVENTS );
  118. if( pWnd && pWnd->GetSafeHwnd() )
  119. {
  120. CRect rect;
  121. pWnd->GetClientRect( rect );
  122. m_OverlayDC.ScrollDC( 0, m_nFontHeight + 2, &rect, NULL, NULL, NULL );
  123. CString str;
  124. CSensor *pSensor = m_pSensorArray->GetSensor( wParam );
  125. pSensor->GetEventString( str, lParam );
  126. COLORREF color = pSensor->GetEventColor( lParam );
  127. CFont *pOldFont = (CFont*)m_OverlayDC.SelectObject( m_pFont );
  128. COLORREF oldColor = m_OverlayDC.SetTextColor( color );
  129. COLORREF oldBkColor = m_OverlayDC.SetBkColor( 0 );
  130. CRect fillRect( 0, 0, rect.Width(), m_nFontHeight + 2 );
  131. m_OverlayDC.FillSolidRect( &fillRect, 0x000000 );
  132. m_OverlayDC.TextOut( 1, 1, str );
  133. m_OverlayDC.SetBkColor( oldBkColor );
  134. m_OverlayDC.SetTextColor( oldColor );
  135. m_OverlayDC.SelectObject( pOldFont );
  136. m_bChanged = TRUE;
  137. }
  138. */
  139. return 0;
  140. }
  141. LRESULT CEventsDlg::OnWMSocketEvent(WPARAM wParam, LPARAM lParam)
  142. {
  143. /* CWnd *pWnd = GetDlgItem( IDC_CUSTOM_EVENTS );
  144. if( pWnd && pWnd->GetSafeHwnd() )
  145. {
  146. CRect rect;
  147. pWnd->GetClientRect( rect );
  148. m_OverlayDC.ScrollDC( 0, m_nFontHeight + 2, &rect, NULL, NULL, NULL );
  149. CString str;
  150. COLORREF color;
  151. switch( LOWORD( lParam ) )
  152. {
  153. case SOCKET_EVENT_PERFORMANCE:
  154. str.Format( "%d line %d - %d R/W per second", ::GetMessageTime(), wParam, HIWORD(lParam) );
  155. color = RGB( 0xFF, 0xFF, 0xFF );
  156. break;
  157. case SOCKET_EVENT_CRITICAL_ERROR:
  158. str.Format( "%d line %d internal error (%d)", ::GetMessageTime(), wParam, HIWORD(lParam) );
  159. color = RGB( 0xFF, 0xFF, 0xFF );
  160. break;
  161. }
  162. CFont *pOldFont = (CFont*)m_OverlayDC.SelectObject( m_pFont );
  163. COLORREF oldColor = m_OverlayDC.SetTextColor( color );
  164. COLORREF oldBkColor = m_OverlayDC.SetBkColor( 0 );
  165. CRect fillRect( 0, 0, rect.Width(), m_nFontHeight + 2 );
  166. m_OverlayDC.FillSolidRect( &fillRect, 0x000000 );
  167. m_OverlayDC.TextOut( 1, 1, str );
  168. m_OverlayDC.SetBkColor( oldBkColor );
  169. m_OverlayDC.SetTextColor( oldColor );
  170. m_OverlayDC.SelectObject( pOldFont );
  171. m_bChanged = TRUE;
  172. }
  173. */
  174. return 0;
  175. }
  176. void CEventsDlg::OnTimer(UINT nIDEvent)
  177. {
  178. /* EVENT event;
  179. CWnd *pWnd = GetDlgItem( IDC_CUSTOM_EVENTS );
  180. CRect rect;
  181. pWnd->GetClientRect( rect );
  182. while( m_pEventQueue->GetEvent( event ) )
  183. {
  184. CString str("");
  185. COLORREF color;
  186. BOOL bNeedPaint = TRUE;
  187. switch( event.dwID )
  188. {
  189. case EVENT_SOCKET:
  190. switch( LOWORD( event.dwData2 ) )
  191. {
  192. case SOCKET_EVENT_PERFORMANCE:
  193. str.Format( "%02d:%02d:%02d line %d - %d R/W per second", st.wHour, st.wMinute, st.wSecond, event.dwData1, HIWORD(event.dwData2) );
  194. color = RGB( 0xFF, 0xFF, 0xFF );
  195. break;
  196. case SOCKET_EVENT_CRITICAL_ERROR:
  197. str.Format( "%02d:%02d:%02d line %d internal error (%d)", st.wHour, st.wMinute, st.wSecond, event.dwData1, HIWORD(event.dwData2) );
  198. color = RGB( 0xFF, 0xFF, 0xFF );
  199. break;
  200. }
  201. break;
  202. case EVENT_SENSOR:
  203. {
  204. CString tmp;
  205. CSensor *pSensor = m_pSensorArray->GetSensor( event.dwData1 );
  206. switch( pSensor->GetType() )
  207. {
  208. case CSensor::DTR:
  209. if( LOWORD(event.dwData2)==DTR_EVENT_NORMAL )
  210. bNeedPaint = FALSE;
  211. break;
  212. }
  213. if( bNeedPaint )
  214. {
  215. pSensor->GetEventString( tmp, event.dwData2 );
  216. color = pSensor->GetEventColor( event.dwData2 );
  217. str.Format( "%02d:%02d:%02d %s", st.wHour, st.wMinute, st.wSecond, tmp );
  218. }
  219. }
  220. break;
  221. }
  222. if( bNeedPaint )
  223. {
  224. m_OverlayDC.ScrollDC( 0, m_nFontHeight + 2, &rect, NULL, NULL, NULL );
  225. CFont *pOldFont = (CFont*)m_OverlayDC.SelectObject( m_pFont );
  226. COLORREF oldColor = m_OverlayDC.SetTextColor( color );
  227. COLORREF oldBkColor = m_OverlayDC.SetBkColor( 0 );
  228. CRect fillRect( 0, 0, rect.Width(), m_nFontHeight + 2 );
  229. m_OverlayDC.FillSolidRect( &fillRect, 0x000000 );
  230. m_OverlayDC.TextOut( 1, 1, str );
  231. m_OverlayDC.SetBkColor( oldBkColor );
  232. m_OverlayDC.SetTextColor( oldColor );
  233. m_OverlayDC.SelectObject( pOldFont );
  234. m_bChanged = TRUE;
  235. }
  236. }
  237. if( m_bChanged && pWnd && pWnd->GetSafeHwnd() )
  238. {
  239. CRect rect;
  240. pWnd->GetClientRect( rect );
  241. CDC *pDC = pWnd->GetDC();
  242. pDC->BitBlt( rect.left, rect.top, rect.Width(), rect.Height(), &m_OverlayDC, rect.left, rect.top, SRCCOPY );
  243. pWnd->ReleaseDC( pDC );
  244. m_bChanged = FALSE;
  245. }
  246. */
  247. CDialog::OnTimer(nIDEvent);
  248. }
  249. LRESULT CEventsDlg::WndProcEvent(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  250. {
  251. switch( uMsg )
  252. {
  253. case WM_PAINT:
  254. {
  255. CWnd wnd;
  256. wnd.Attach( hWnd );
  257. CRect rect;
  258. wnd.GetClientRect( rect );
  259. CPaintDC dc( &wnd );
  260. dc.BitBlt( rect.left, rect.top, rect.Width(), rect.Height(), &m_OverlayDC, rect.left, rect.top, SRCCOPY );
  261. wnd.Detach();
  262. }
  263. break;
  264. }
  265. return ::DefWindowProc( hWnd, uMsg, wParam, lParam );
  266. }
  267. BOOL CEventsDlg::OnInitDialog()
  268. {
  269. CDialog::OnInitDialog();
  270. ::SetWindowLong( GetDlgItem( IDC_CUSTOM_EVENTS )->GetSafeHwnd(), GWL_USERDATA, (LONG)this );
  271. m_pFont = GetParent()->GetFont();
  272. PrepareOverlay();
  273. return TRUE; // return TRUE unless you set the focus to a control
  274. // EXCEPTION: OCX Property Pages should return FALSE
  275. }
  276. void CEventsDlg::PrepareOverlay()
  277. {
  278. CWnd *pWnd = GetDlgItem( IDC_CUSTOM_EVENTS );
  279. if( pWnd )
  280. {
  281. if( m_pOverlayBitmapOld )
  282. {
  283. m_OverlayDC.SelectObject( m_pOverlayBitmapOld );
  284. m_OverlayDC.DeleteDC();
  285. m_OverlayBitmap.DeleteObject();
  286. }
  287. CRect rect;
  288. pWnd->GetClientRect( rect );
  289. CDC *pDC = pWnd->GetDC();
  290. m_OverlayDC.CreateCompatibleDC( pDC );
  291. m_OverlayBitmap.CreateCompatibleBitmap( pDC, rect.Width(), rect.Height() );
  292. pWnd->ReleaseDC( pDC );
  293. m_pOverlayBitmapOld = m_OverlayDC.SelectObject( &m_OverlayBitmap );
  294. m_OverlayDC.FillSolidRect( &rect, 0x000000 );
  295. LOGFONT lf;
  296. m_pFont->GetLogFont( &lf );
  297. m_nFontHeight = -lf.lfHeight;
  298. m_bChanged = TRUE;
  299. }
  300. }
  301. void CEventsDlg::OnDestroy()
  302. {
  303. KillTimer( 0 );
  304. CDialog::OnDestroy();
  305. if( m_pOverlayBitmapOld )
  306. {
  307. m_OverlayDC.SelectObject( m_pOverlayBitmapOld );
  308. m_OverlayDC.DeleteDC();
  309. m_OverlayBitmap.DeleteObject();
  310. }
  311. }
  312. void CEventsDlg::OnSize(UINT nType, int cx, int cy)
  313. {
  314. CDialog::OnSize(nType, cx, cy);
  315. CWnd *pWnd = GetDlgItem( IDC_CUSTOM_EVENTS );
  316. if( pWnd && pWnd->GetSafeHwnd() )
  317. {
  318. CRect rect;
  319. GetClientRect( rect );
  320. // rect.top += 30;
  321. pWnd->MoveWindow( rect );
  322. PrepareOverlay();
  323. }
  324. }
  325. void CEventsDlg::PrintLine(CString &line)
  326. {
  327. if( m_bPrint )
  328. {
  329. if( m_nPrintCount==0 )
  330. {
  331. m_PrintDC.SetTextColor( 0x00 );
  332. m_PrintDC.SetBkColor( 0xFFFFFF );
  333. DOCINFO di;
  334. di.cbSize = sizeof( DOCINFO );
  335. di.fwType = 0;
  336. di.lpszDatatype = "raw";
  337. di.lpszDocName = "text";
  338. di.lpszOutput = NULL;
  339. m_PrintDC.StartDoc( &di );
  340. m_PrintDC.StartPage();
  341. }
  342. m_PrintDC.TextOut( 0, (m_nFontHeight + 2) * 4 * m_nPrintCount ++ , line );
  343. if( m_nPrintCount >= 60 )
  344. {
  345. m_PrintDC.EndPage();
  346. m_PrintDC.EndDoc();
  347. m_nPrintCount = 0;
  348. }
  349. }
  350. }
  351. void CEventsDlg::OnMoving(UINT fwSide, LPRECT pRect)
  352. {
  353. CRect rect;
  354. GetParent()->GetClientRect( &rect );
  355. GetParent()->ClientToScreen( &rect );
  356. if( pRect->left < rect.left )
  357. {
  358. pRect->right += rect.left - pRect->left;
  359. pRect->left = rect.left;
  360. }
  361. if( pRect->top < rect.top )
  362. {
  363. pRect->bottom += rect.top - pRect->top;
  364. pRect->top = rect.top;
  365. }
  366. if( pRect->right > rect.right )
  367. {
  368. pRect->left -= pRect->right - rect.right;
  369. pRect->right = rect.right;
  370. }
  371. if( pRect->bottom > rect.bottom )
  372. {
  373. pRect->top -= pRect->bottom - rect.bottom;
  374. pRect->bottom = rect.bottom;
  375. }
  376. CDialog::OnMoving( fwSide, pRect );
  377. }
  378. void CEventsDlg::OnSizing(UINT fwSide, LPRECT pRect)
  379. {
  380. CRect rect;
  381. GetParent()->GetClientRect( &rect );
  382. GetParent()->ClientToScreen( &rect );
  383. if( pRect->left < rect.left ) pRect->left = rect.left;
  384. if( pRect->right > rect.right ) pRect->right = rect.right;
  385. if( pRect->top < rect.top ) pRect->top = rect.top;
  386. if( pRect->bottom > rect.bottom ) pRect->bottom = rect.bottom;
  387. CDialog::OnSizing( fwSide, pRect );
  388. }
  389. void CEventsDlg::SetSensorArray(CSensorArray *pSensorArray)
  390. {
  391. m_pSensorArray = pSensorArray;
  392. }
  393. void CEventsDlg::SetEventQueue(CEventQueue *pEventQueue)
  394. {
  395. m_pEventQueue = pEventQueue;
  396. }