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
186 lines
4.7 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 08/10/2003
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: LgsStateWnd.cpp
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of LgsStateWnd.cpp
|
|
//----------------------------------------------------------------------------
|
|
#include "stdafx.h"
|
|
#include "Resource.h"
|
|
#include "LgsStateWnd.h"
|
|
#include "..\LgLib\Version.h"
|
|
|
|
CLgsStateWnd::CLgsStateWnd()
|
|
{
|
|
m_bStudyMode = TRUE;
|
|
m_bLowPowerMode = FALSE;
|
|
m_bLowPowerModeBlink = FALSE;
|
|
m_nStep = -1;
|
|
memset( m_pIcon, 0, sizeof(m_pIcon) );
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgsStateWnd::CLgsStateWnd") );
|
|
}
|
|
|
|
CLgsStateWnd::~CLgsStateWnd()
|
|
{
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgsStateWnd::~CLgsStateWnd") );
|
|
}
|
|
|
|
BOOL CLgsStateWnd::Create( HWND hParentWnd, INT x, INT y, INT cx, INT cy )
|
|
{
|
|
LPCTSTR lpszClassName = _T("LgsStateWndClass");
|
|
|
|
HINSTANCE hInstance = (HINSTANCE)::GetWindowLong( hParentWnd, GWL_HINSTANCE );
|
|
|
|
// create icons
|
|
UINT pIconID[ICON_COUNT] =
|
|
{
|
|
IDI_ICON_01, IDI_ICON_02, IDI_ICON_03, IDI_ICON_04, IDI_ICON_05, IDI_ICON_06, IDI_ICON_07, IDI_ICON_08,
|
|
IDI_ICON_DISCONNECTION,
|
|
IDI_ICON_STUDY,
|
|
IDI_ICON_POWER,
|
|
};
|
|
for( INT i = 0; i < ICON_COUNT; i++ )
|
|
{
|
|
m_pIcon[i] = (HICON)LoadImage( hInstance, (LPCTSTR)pIconID[i], IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR );
|
|
if( !m_pIcon[i] )
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgsStateWnd::Create"), _T("LoadImage failed for icon ID %d"), pIconID[i] );
|
|
}
|
|
|
|
// register window class
|
|
if( !CGenericWnd::RegisterClass( lpszClassName, hInstance ) )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgsStateWnd::Create"), _T("CGenericWnd::RegisterClass failed") );
|
|
return FALSE;
|
|
}
|
|
|
|
// create window
|
|
if( !CGenericWnd::Create( lpszClassName, NULL, WS_CHILD | WS_VISIBLE, x, y, cx, cy, hParentWnd, NULL, hInstance ) )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgsStateWnd::Create"), _T("CGenericWnd::Create failed") );
|
|
return FALSE;
|
|
}
|
|
|
|
// set timer for power blinking
|
|
if( !CGenericWnd::SetTimer( 1, 250, NULL ) )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgsStateWnd::Create"), _T("CGenericWnd::SetTimer failed") );
|
|
return FALSE;
|
|
}
|
|
|
|
// update window contents
|
|
Draw();
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgsStateWnd::Create"), _T("Done successefully") );
|
|
return TRUE;
|
|
}
|
|
|
|
void CLgsStateWnd::SetStudyMode( BOOL bStudyMode )
|
|
{
|
|
m_bStudyMode = bStudyMode;
|
|
|
|
Draw();
|
|
}
|
|
|
|
void CLgsStateWnd::SetLowPowerMode( BOOL bLowPowerMode )
|
|
{
|
|
m_bLowPowerMode = bLowPowerMode;
|
|
|
|
Draw();
|
|
}
|
|
|
|
void CLgsStateWnd::Step( INT nStep )
|
|
{
|
|
m_nStep = nStep;
|
|
|
|
Draw();
|
|
}
|
|
|
|
void CLgsStateWnd::Draw()
|
|
{
|
|
RECT rect;
|
|
GetClientRect( &rect );
|
|
|
|
m_MemoryDC.FillSolidRect( &rect, ::GetSysColor(COLOR_BTNFACE) );
|
|
|
|
if( m_nStep == -1 )
|
|
m_MemoryDC.DrawIcon( 0, 0, m_pIcon[DISCONNECTION] );
|
|
else
|
|
{
|
|
if( m_bStudyMode )
|
|
m_MemoryDC.DrawIcon( 0, 0, m_pIcon[STUDY] );
|
|
|
|
if( m_bLowPowerMode && m_bLowPowerModeBlink )
|
|
m_MemoryDC.DrawIcon( 0, 0, m_pIcon[POWER] );
|
|
|
|
m_MemoryDC.DrawIcon( 0, 0, m_pIcon[m_nStep] );
|
|
}
|
|
|
|
InvalidateRect( NULL, FALSE );
|
|
UpdateWindow();
|
|
}
|
|
|
|
LRESULT CLgsStateWnd::OnPaint( WPARAM, LPARAM )
|
|
{
|
|
PAINTSTRUCT ps;
|
|
|
|
HDC hDC = BeginPaint( &ps );
|
|
|
|
RECT rect;
|
|
GetClientRect( &rect );
|
|
|
|
::BitBlt( hDC, 0, 0, rect.right, rect.bottom, m_MemoryDC.GetSafeHdc(), 0, 0, SRCCOPY );
|
|
|
|
EndPaint( &ps );
|
|
|
|
LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CLgsStateWnd::OnSize") );
|
|
return TRUE;
|
|
}
|
|
|
|
LRESULT CLgsStateWnd::OnSize( WPARAM wParam, LPARAM lParam )
|
|
{
|
|
UINT nType = wParam;
|
|
INT cx = (INT)LOWORD( lParam );
|
|
INT cy = (INT)HIWORD( lParam );
|
|
|
|
if( !m_MemoryDC.Create( cx, cy ) )
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgsStateWnd::OnSize"), _T("m_MemoryDC.Create failed") );
|
|
|
|
LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CLgsStateWnd::OnSize") );
|
|
return TRUE;
|
|
}
|
|
|
|
LRESULT CLgsStateWnd::OnDestroy( WPARAM wParam, LPARAM lParam )
|
|
{
|
|
// destroy icons
|
|
for( INT i = 0; i < ICON_COUNT; i++ )
|
|
{
|
|
::DestroyIcon( m_pIcon[i] );
|
|
m_pIcon[i] = NULL;
|
|
}
|
|
|
|
// kill timer
|
|
KillTimer( 1 );
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgsStateWnd::OnDestroy") );
|
|
return CGenericWnd::OnDestroy( wParam, lParam );
|
|
}
|
|
|
|
LRESULT CLgsStateWnd::OnTimer( WPARAM, LPARAM )
|
|
{
|
|
// flip blinking state
|
|
m_bLowPowerModeBlink = !m_bLowPowerModeBlink;
|
|
|
|
// redraw content
|
|
Draw();
|
|
|
|
LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CLgsStateWnd::OnTimer") );
|
|
return TRUE;
|
|
}
|
|
|