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
450 lines
11 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 13/04/2001
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: EventsDlg.cpp
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of EventsDlg.cpp
|
|
//----------------------------------------------------------------------------
|
|
// EventsDlg.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "chicago.h"
|
|
#include "Sensor.h"
|
|
#include "SensorSPRU.h"
|
|
#include "EventsDlg.h"
|
|
#include "ShellApi.h"
|
|
#include "SensorArray.h"
|
|
#include "SocketRS232.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CEventsDlg dialog
|
|
|
|
CEventsDlg::CEventsDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CEventsDlg::IDD, pParent)
|
|
{
|
|
//{{AFX_DATA_INIT(CEventsDlg)
|
|
// NOTE: the ClassWizard will add member initialization here
|
|
//}}AFX_DATA_INIT
|
|
WNDCLASS wc;
|
|
wc.cbClsExtra = 0;
|
|
wc.cbWndExtra = 0;
|
|
wc.hbrBackground = (HBRUSH)COLOR_BTNFACE;
|
|
wc.hCursor = (HCURSOR)LoadCursor( NULL, IDC_ARROW );
|
|
wc.hIcon = NULL;
|
|
wc.hInstance = ::AfxGetInstanceHandle();
|
|
wc.lpszClassName = "EventViewClass";
|
|
wc.lpszMenuName = NULL;
|
|
wc.style = CS_HREDRAW | CS_VREDRAW;
|
|
wc.lpfnWndProc = ::WndProcEvent;
|
|
::RegisterClass( &wc );
|
|
m_pOverlayBitmapOld = NULL;
|
|
m_bPrint = FALSE;
|
|
m_nPrintCount = 0;
|
|
m_pSensorArray = NULL;
|
|
m_bChanged = FALSE;
|
|
}
|
|
|
|
|
|
void CEventsDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(CEventsDlg)
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CEventsDlg, CDialog)
|
|
//{{AFX_MSG_MAP(CEventsDlg)
|
|
ON_WM_MOVING()
|
|
ON_WM_DESTROY()
|
|
ON_WM_SIZE()
|
|
ON_WM_SIZING()
|
|
ON_MESSAGE( WM_SENSOR_EVENT, OnWMSensorEvent )
|
|
ON_MESSAGE( WM_SOCKET_EVENT, OnWMSocketEvent )
|
|
ON_WM_TIMER()
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CEventsDlg message handlers
|
|
/*
|
|
void CEventsDlg::OnCheckPrint()
|
|
{
|
|
static CDC dstDC;
|
|
if( m_btnPrint.GetCheck() )
|
|
{
|
|
CPrintDialog prnDlg( TRUE );
|
|
prnDlg.DoModal();
|
|
m_PrintDC.CreateDC( prnDlg.GetDriverName(), prnDlg.GetDeviceName(), NULL, NULL );
|
|
DOCINFO di;
|
|
di.cbSize = sizeof( DOCINFO );
|
|
di.fwType = 0;
|
|
di.lpszDatatype = "raw";
|
|
di.lpszDocName = "text";
|
|
di.lpszOutput = NULL;
|
|
m_PrintDC.StartDoc( &di );
|
|
m_PrintDC.StartPage();
|
|
m_bPrint = TRUE;
|
|
}
|
|
else
|
|
{
|
|
m_bPrint = FALSE;
|
|
m_PrintDC.EndPage();
|
|
m_PrintDC.EndDoc();
|
|
m_PrintDC.DeleteDC();
|
|
}
|
|
|
|
CFileDialog fd( TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_EXPLORER );
|
|
fd.DoModal();
|
|
|
|
CHAR pBuffer[MAX_PATH];
|
|
BROWSEINFO bi;
|
|
bi.hwndOwner = GetSafeHwnd();
|
|
bi.pidlRoot = NULL;
|
|
bi.pszDisplayName = pBuffer;
|
|
bi.lpszTitle = "BROWSER";
|
|
bi.lpfn = NULL;
|
|
bi.lParam = 0;
|
|
bi.ulFlags = 0;
|
|
bi.iImage = 0;
|
|
SHBrowseForFolder( &bi );
|
|
}
|
|
*/
|
|
LRESULT CEventsDlg::OnWMSensorEvent(WPARAM wParam, LPARAM lParam)
|
|
{
|
|
/* CWnd *pWnd = GetDlgItem( IDC_CUSTOM_EVENTS );
|
|
if( pWnd && pWnd->GetSafeHwnd() )
|
|
{
|
|
CRect rect;
|
|
pWnd->GetClientRect( rect );
|
|
|
|
m_OverlayDC.ScrollDC( 0, m_nFontHeight + 2, &rect, NULL, NULL, NULL );
|
|
|
|
CString str;
|
|
CSensor *pSensor = m_pSensorArray->GetSensor( wParam );
|
|
pSensor->GetEventString( str, lParam );
|
|
COLORREF color = pSensor->GetEventColor( lParam );
|
|
CFont *pOldFont = (CFont*)m_OverlayDC.SelectObject( m_pFont );
|
|
COLORREF oldColor = m_OverlayDC.SetTextColor( color );
|
|
COLORREF oldBkColor = m_OverlayDC.SetBkColor( 0 );
|
|
CRect fillRect( 0, 0, rect.Width(), m_nFontHeight + 2 );
|
|
m_OverlayDC.FillSolidRect( &fillRect, 0x000000 );
|
|
m_OverlayDC.TextOut( 1, 1, str );
|
|
m_OverlayDC.SetBkColor( oldBkColor );
|
|
m_OverlayDC.SetTextColor( oldColor );
|
|
m_OverlayDC.SelectObject( pOldFont );
|
|
|
|
m_bChanged = TRUE;
|
|
}
|
|
*/
|
|
return 0;
|
|
}
|
|
|
|
LRESULT CEventsDlg::OnWMSocketEvent(WPARAM wParam, LPARAM lParam)
|
|
{
|
|
/* CWnd *pWnd = GetDlgItem( IDC_CUSTOM_EVENTS );
|
|
if( pWnd && pWnd->GetSafeHwnd() )
|
|
{
|
|
CRect rect;
|
|
pWnd->GetClientRect( rect );
|
|
|
|
m_OverlayDC.ScrollDC( 0, m_nFontHeight + 2, &rect, NULL, NULL, NULL );
|
|
|
|
CString str;
|
|
COLORREF color;
|
|
switch( LOWORD( lParam ) )
|
|
{
|
|
case SOCKET_EVENT_PERFORMANCE:
|
|
str.Format( "%d line %d - %d R/W per second", ::GetMessageTime(), wParam, HIWORD(lParam) );
|
|
color = RGB( 0xFF, 0xFF, 0xFF );
|
|
break;
|
|
case SOCKET_EVENT_CRITICAL_ERROR:
|
|
str.Format( "%d line %d internal error (%d)", ::GetMessageTime(), wParam, HIWORD(lParam) );
|
|
color = RGB( 0xFF, 0xFF, 0xFF );
|
|
break;
|
|
}
|
|
|
|
CFont *pOldFont = (CFont*)m_OverlayDC.SelectObject( m_pFont );
|
|
COLORREF oldColor = m_OverlayDC.SetTextColor( color );
|
|
COLORREF oldBkColor = m_OverlayDC.SetBkColor( 0 );
|
|
CRect fillRect( 0, 0, rect.Width(), m_nFontHeight + 2 );
|
|
m_OverlayDC.FillSolidRect( &fillRect, 0x000000 );
|
|
m_OverlayDC.TextOut( 1, 1, str );
|
|
m_OverlayDC.SetBkColor( oldBkColor );
|
|
m_OverlayDC.SetTextColor( oldColor );
|
|
m_OverlayDC.SelectObject( pOldFont );
|
|
|
|
m_bChanged = TRUE;
|
|
}
|
|
*/
|
|
return 0;
|
|
}
|
|
|
|
void CEventsDlg::OnTimer(UINT nIDEvent)
|
|
{
|
|
/* EVENT event;
|
|
|
|
CWnd *pWnd = GetDlgItem( IDC_CUSTOM_EVENTS );
|
|
|
|
CRect rect;
|
|
pWnd->GetClientRect( rect );
|
|
|
|
while( m_pEventQueue->GetEvent( event ) )
|
|
{
|
|
CString str("");
|
|
COLORREF color;
|
|
BOOL bNeedPaint = TRUE;
|
|
switch( event.dwID )
|
|
{
|
|
case EVENT_SOCKET:
|
|
switch( LOWORD( event.dwData2 ) )
|
|
{
|
|
case SOCKET_EVENT_PERFORMANCE:
|
|
str.Format( "%02d:%02d:%02d line %d - %d R/W per second", st.wHour, st.wMinute, st.wSecond, event.dwData1, HIWORD(event.dwData2) );
|
|
color = RGB( 0xFF, 0xFF, 0xFF );
|
|
break;
|
|
case SOCKET_EVENT_CRITICAL_ERROR:
|
|
str.Format( "%02d:%02d:%02d line %d internal error (%d)", st.wHour, st.wMinute, st.wSecond, event.dwData1, HIWORD(event.dwData2) );
|
|
color = RGB( 0xFF, 0xFF, 0xFF );
|
|
break;
|
|
}
|
|
break;
|
|
case EVENT_SENSOR:
|
|
{
|
|
CString tmp;
|
|
CSensor *pSensor = m_pSensorArray->GetSensor( event.dwData1 );
|
|
switch( pSensor->GetType() )
|
|
{
|
|
case CSensor::DTR:
|
|
if( LOWORD(event.dwData2)==DTR_EVENT_NORMAL )
|
|
bNeedPaint = FALSE;
|
|
break;
|
|
}
|
|
if( bNeedPaint )
|
|
{
|
|
pSensor->GetEventString( tmp, event.dwData2 );
|
|
color = pSensor->GetEventColor( event.dwData2 );
|
|
str.Format( "%02d:%02d:%02d %s", st.wHour, st.wMinute, st.wSecond, tmp );
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
if( bNeedPaint )
|
|
{
|
|
m_OverlayDC.ScrollDC( 0, m_nFontHeight + 2, &rect, NULL, NULL, NULL );
|
|
|
|
CFont *pOldFont = (CFont*)m_OverlayDC.SelectObject( m_pFont );
|
|
COLORREF oldColor = m_OverlayDC.SetTextColor( color );
|
|
COLORREF oldBkColor = m_OverlayDC.SetBkColor( 0 );
|
|
CRect fillRect( 0, 0, rect.Width(), m_nFontHeight + 2 );
|
|
m_OverlayDC.FillSolidRect( &fillRect, 0x000000 );
|
|
m_OverlayDC.TextOut( 1, 1, str );
|
|
m_OverlayDC.SetBkColor( oldBkColor );
|
|
m_OverlayDC.SetTextColor( oldColor );
|
|
m_OverlayDC.SelectObject( pOldFont );
|
|
|
|
m_bChanged = TRUE;
|
|
}
|
|
}
|
|
|
|
if( m_bChanged && pWnd && pWnd->GetSafeHwnd() )
|
|
{
|
|
CRect rect;
|
|
pWnd->GetClientRect( rect );
|
|
|
|
CDC *pDC = pWnd->GetDC();
|
|
pDC->BitBlt( rect.left, rect.top, rect.Width(), rect.Height(), &m_OverlayDC, rect.left, rect.top, SRCCOPY );
|
|
pWnd->ReleaseDC( pDC );
|
|
|
|
m_bChanged = FALSE;
|
|
}
|
|
*/
|
|
CDialog::OnTimer(nIDEvent);
|
|
}
|
|
|
|
LRESULT CEventsDlg::WndProcEvent(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
switch( uMsg )
|
|
{
|
|
case WM_PAINT:
|
|
{
|
|
CWnd wnd;
|
|
wnd.Attach( hWnd );
|
|
CRect rect;
|
|
wnd.GetClientRect( rect );
|
|
CPaintDC dc( &wnd );
|
|
dc.BitBlt( rect.left, rect.top, rect.Width(), rect.Height(), &m_OverlayDC, rect.left, rect.top, SRCCOPY );
|
|
wnd.Detach();
|
|
}
|
|
break;
|
|
}
|
|
return ::DefWindowProc( hWnd, uMsg, wParam, lParam );
|
|
}
|
|
|
|
BOOL CEventsDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
|
|
::SetWindowLong( GetDlgItem( IDC_CUSTOM_EVENTS )->GetSafeHwnd(), GWL_USERDATA, (LONG)this );
|
|
|
|
m_pFont = GetParent()->GetFont();
|
|
|
|
PrepareOverlay();
|
|
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
|
// EXCEPTION: OCX Property Pages should return FALSE
|
|
}
|
|
|
|
void CEventsDlg::PrepareOverlay()
|
|
{
|
|
CWnd *pWnd = GetDlgItem( IDC_CUSTOM_EVENTS );
|
|
if( pWnd )
|
|
{
|
|
if( m_pOverlayBitmapOld )
|
|
{
|
|
m_OverlayDC.SelectObject( m_pOverlayBitmapOld );
|
|
m_OverlayDC.DeleteDC();
|
|
m_OverlayBitmap.DeleteObject();
|
|
}
|
|
|
|
CRect rect;
|
|
pWnd->GetClientRect( rect );
|
|
|
|
CDC *pDC = pWnd->GetDC();
|
|
m_OverlayDC.CreateCompatibleDC( pDC );
|
|
m_OverlayBitmap.CreateCompatibleBitmap( pDC, rect.Width(), rect.Height() );
|
|
pWnd->ReleaseDC( pDC );
|
|
|
|
m_pOverlayBitmapOld = m_OverlayDC.SelectObject( &m_OverlayBitmap );
|
|
m_OverlayDC.FillSolidRect( &rect, 0x000000 );
|
|
|
|
LOGFONT lf;
|
|
m_pFont->GetLogFont( &lf );
|
|
|
|
m_nFontHeight = -lf.lfHeight;
|
|
|
|
m_bChanged = TRUE;
|
|
}
|
|
}
|
|
|
|
void CEventsDlg::OnDestroy()
|
|
{
|
|
KillTimer( 0 );
|
|
|
|
CDialog::OnDestroy();
|
|
|
|
if( m_pOverlayBitmapOld )
|
|
{
|
|
m_OverlayDC.SelectObject( m_pOverlayBitmapOld );
|
|
m_OverlayDC.DeleteDC();
|
|
m_OverlayBitmap.DeleteObject();
|
|
}
|
|
}
|
|
|
|
void CEventsDlg::OnSize(UINT nType, int cx, int cy)
|
|
{
|
|
CDialog::OnSize(nType, cx, cy);
|
|
CWnd *pWnd = GetDlgItem( IDC_CUSTOM_EVENTS );
|
|
if( pWnd && pWnd->GetSafeHwnd() )
|
|
{
|
|
CRect rect;
|
|
GetClientRect( rect );
|
|
// rect.top += 30;
|
|
pWnd->MoveWindow( rect );
|
|
PrepareOverlay();
|
|
}
|
|
}
|
|
|
|
void CEventsDlg::PrintLine(CString &line)
|
|
{
|
|
if( m_bPrint )
|
|
{
|
|
if( m_nPrintCount==0 )
|
|
{
|
|
m_PrintDC.SetTextColor( 0x00 );
|
|
m_PrintDC.SetBkColor( 0xFFFFFF );
|
|
DOCINFO di;
|
|
di.cbSize = sizeof( DOCINFO );
|
|
di.fwType = 0;
|
|
di.lpszDatatype = "raw";
|
|
di.lpszDocName = "text";
|
|
di.lpszOutput = NULL;
|
|
m_PrintDC.StartDoc( &di );
|
|
m_PrintDC.StartPage();
|
|
}
|
|
m_PrintDC.TextOut( 0, (m_nFontHeight + 2) * 4 * m_nPrintCount ++ , line );
|
|
if( m_nPrintCount >= 60 )
|
|
{
|
|
m_PrintDC.EndPage();
|
|
m_PrintDC.EndDoc();
|
|
m_nPrintCount = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
void CEventsDlg::OnMoving(UINT fwSide, LPRECT pRect)
|
|
{
|
|
CRect rect;
|
|
GetParent()->GetClientRect( &rect );
|
|
GetParent()->ClientToScreen( &rect );
|
|
|
|
if( pRect->left < rect.left )
|
|
{
|
|
pRect->right += rect.left - pRect->left;
|
|
pRect->left = rect.left;
|
|
}
|
|
if( pRect->top < rect.top )
|
|
{
|
|
pRect->bottom += rect.top - pRect->top;
|
|
pRect->top = rect.top;
|
|
}
|
|
if( pRect->right > rect.right )
|
|
{
|
|
pRect->left -= pRect->right - rect.right;
|
|
pRect->right = rect.right;
|
|
}
|
|
if( pRect->bottom > rect.bottom )
|
|
{
|
|
pRect->top -= pRect->bottom - rect.bottom;
|
|
pRect->bottom = rect.bottom;
|
|
}
|
|
|
|
CDialog::OnMoving( fwSide, pRect );
|
|
}
|
|
|
|
void CEventsDlg::OnSizing(UINT fwSide, LPRECT pRect)
|
|
{
|
|
CRect rect;
|
|
GetParent()->GetClientRect( &rect );
|
|
GetParent()->ClientToScreen( &rect );
|
|
|
|
if( pRect->left < rect.left ) pRect->left = rect.left;
|
|
if( pRect->right > rect.right ) pRect->right = rect.right;
|
|
if( pRect->top < rect.top ) pRect->top = rect.top;
|
|
if( pRect->bottom > rect.bottom ) pRect->bottom = rect.bottom;
|
|
|
|
CDialog::OnSizing( fwSide, pRect );
|
|
}
|
|
|
|
void CEventsDlg::SetSensorArray(CSensorArray *pSensorArray)
|
|
{
|
|
m_pSensorArray = pSensorArray;
|
|
}
|
|
|
|
void CEventsDlg::SetEventQueue(CEventQueue *pEventQueue)
|
|
{
|
|
m_pEventQueue = pEventQueue;
|
|
}
|