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.
267 lines
5.1 KiB
267 lines
5.1 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 08/10/2003
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: LgWnd.cpp
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of LgWnd.cpp
|
|
//----------------------------------------------------------------------------
|
|
#include "stdafx.h"
|
|
#include "..\LgLib\Version.h"
|
|
|
|
#include "LgWnd.h"
|
|
|
|
CLgWnd::CLgWnd()
|
|
{
|
|
m_hWnd = NULL;
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgWnd::CLgWnd" );
|
|
}
|
|
|
|
CLgWnd::~CLgWnd()
|
|
{
|
|
DestroyWindow();
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgWnd::~CLgWnd" );
|
|
}
|
|
|
|
BOOL CLgWnd::Create( HWND hParentWnd, INT x, INT y, INT cx, INT cy )
|
|
{
|
|
DestroyWindow();
|
|
|
|
// register wnd class
|
|
WNDCLASS wc;
|
|
wc.cbClsExtra = 0;
|
|
wc.cbWndExtra = 0;
|
|
wc.hbrBackground = NULL;
|
|
wc.hCursor = ::LoadCursor( NULL, IDC_ARROW );
|
|
wc.hIcon = NULL;
|
|
wc.hInstance = (HINSTANCE)::GetWindowLong( hParentWnd, GWL_HINSTANCE );
|
|
wc.lpfnWndProc = WindowProc_;
|
|
wc.lpszClassName = "LgsRadarWndClass";
|
|
wc.lpszMenuName = NULL;
|
|
wc.style = CS_HREDRAW | CS_VREDRAW;
|
|
if( !::RegisterClass( &wc ) )
|
|
return FALSE;
|
|
|
|
// create window
|
|
m_hWnd = ::CreateWindow( wc.lpszClassName, NULL, WS_CHILD, x, y, cx, cy, hParentWnd, NULL, wc.hInstance, this );
|
|
if( !m_hWnd )
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CLgWnd::DestroyWindow()
|
|
{
|
|
if( !m_hWnd )
|
|
return FALSE;
|
|
|
|
return ::DestroyWindow( m_hWnd );
|
|
}
|
|
|
|
LRESULT CLgWnd::WindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
|
|
{
|
|
switch( uMsg )
|
|
{
|
|
case WM_DESTROY:
|
|
OnDestroy();
|
|
break;
|
|
}
|
|
return ::DefWindowProc( hWnd, uMsg, wParam, lParam );
|
|
}
|
|
|
|
LRESULT CLgWnd::WindowProc_( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
|
|
{
|
|
CLgWnd* pLgsRadar = (CLgWnd*)::GetWindowLong( hWnd, GWL_USERDATA );
|
|
|
|
if( pLgsRadar )
|
|
return pLgsRadar->WindowProc( hWnd, uMsg, wParam, lParam );
|
|
|
|
if( uMsg == WM_CREATE )
|
|
{
|
|
CLgWnd *pLgsRadar = (CLgWnd*)((LPCREATESTRUCT)lParam)->lpCreateParams;
|
|
if( pLgsRadar )
|
|
{
|
|
::SetWindowLong( hWnd, GWL_USERDATA, (LONG)pLgsRadar );
|
|
return pLgsRadar->WindowProc( hWnd, uMsg, wParam, lParam );
|
|
}
|
|
}
|
|
|
|
return ::DefWindowProc( hWnd, uMsg, wParam, lParam );
|
|
}
|
|
|
|
void CLgWnd::OnDestroy()
|
|
{
|
|
m_hWnd = NULL;
|
|
}
|
|
|
|
CLgDC* CLgWnd::GetDC()
|
|
{
|
|
if( m_DC.GetSafeHdc() )
|
|
return NULL;
|
|
|
|
HDC hDC = ::GetDC( m_hWnd );
|
|
if( !m_DC.Attach( hDC ) )
|
|
{
|
|
::ReleaseDC( m_hWnd, hDC );
|
|
return FALSE;
|
|
}
|
|
|
|
return &m_DC;
|
|
}
|
|
|
|
BOOL CLgWnd::ReleaseDC( CLgDC* pDC )
|
|
{
|
|
if( pDC != &m_DC )
|
|
return FALSE;
|
|
|
|
HDC hDC = m_DC.Detach();
|
|
if( !hDC )
|
|
return FALSE;
|
|
|
|
return ::ReleaseDC( m_hWnd, hDC );
|
|
}
|
|
|
|
//------------------------------- CDC LITE ------------------------------------
|
|
CLgDC::CLgDC()
|
|
{
|
|
m_hDC = NULL;
|
|
m_nCreationMode = LGDCCM_NONE;
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgDC::CLgDC" );
|
|
}
|
|
|
|
CLgDC::~CLgDC()
|
|
{
|
|
switch( m_nCreationMode )
|
|
{
|
|
case LGDCCM_NONE:
|
|
break;
|
|
|
|
case LGDCCM_ATTACH:
|
|
Detach();
|
|
break;
|
|
|
|
case LGDCCM_CREATECOMPATIBLEDC:
|
|
DeleteDC();
|
|
break;
|
|
}
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgDC::~CLgDC" );
|
|
}
|
|
|
|
BOOL CLgDC::Attach( HDC hDC )
|
|
{
|
|
if( m_hDC )
|
|
return FALSE;
|
|
|
|
m_hDC = hDC;
|
|
m_nCreationMode = LGDCCM_ATTACH;
|
|
return TRUE;
|
|
}
|
|
|
|
HDC CLgDC::Detach()
|
|
{
|
|
if( m_nCreationMode != LGDCCM_ATTACH )
|
|
return NULL;
|
|
|
|
HDC hDC = m_hDC;
|
|
m_hDC = NULL;
|
|
m_nCreationMode = LGDCCM_NONE;
|
|
return hDC;
|
|
}
|
|
|
|
BOOL CLgDC::CreateCompatibleDC( CLgDC* pDC )
|
|
{
|
|
if( m_hDC )
|
|
return FALSE;
|
|
|
|
m_hDC = ::CreateCompatibleDC( pDC->m_hDC );
|
|
if( !m_hDC )
|
|
return FALSE;
|
|
|
|
m_nCreationMode = LGDCCM_CREATECOMPATIBLEDC;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CLgDC::DeleteDC()
|
|
{
|
|
if( m_nCreationMode != LGDCCM_CREATECOMPATIBLEDC )
|
|
return FALSE;
|
|
|
|
::DeleteDC( m_hDC );
|
|
m_hDC = NULL;
|
|
m_nCreationMode = LGDCCM_NONE;
|
|
return TRUE;
|
|
}
|
|
|
|
HDC CLgDC::GetSafeHdc()
|
|
{
|
|
return m_hDC;
|
|
}
|
|
|
|
|
|
CLgClientDC::CLgClientDC( CLgWnd* pWnd )
|
|
{
|
|
HDC hDC = ::GetDC( pWnd->GetSafeHwnd() );
|
|
if( hDC )
|
|
{
|
|
if( Attach( hDC ) )
|
|
m_pWnd = pWnd;
|
|
else
|
|
{
|
|
::ReleaseDC( pWnd->GetSafeHwnd(), hDC );
|
|
m_pWnd = NULL;
|
|
}
|
|
}
|
|
else
|
|
m_pWnd = NULL;
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgClientDC::CLgClientDC" );
|
|
}
|
|
|
|
CLgClientDC::~CLgClientDC()
|
|
{
|
|
if( m_pWnd )
|
|
{
|
|
::ReleaseDC( m_pWnd->GetSafeHwnd(), Detach() );
|
|
}
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgClientDC::~CLgClientDC" );
|
|
}
|
|
|
|
CLgPaintDC::CLgPaintDC( CLgWnd* pWnd )
|
|
{
|
|
HDC hDC = ::BeginPaint( pWnd->GetSafeHwnd(), &m_PaintStruct );
|
|
if( hDC )
|
|
{
|
|
if( Attach( hDC ) )
|
|
m_pWnd = pWnd;
|
|
else
|
|
{
|
|
::EndPaint( pWnd->GetSafeHwnd(), &m_PaintStruct );
|
|
m_pWnd = NULL;
|
|
}
|
|
}
|
|
else
|
|
m_pWnd = NULL;
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgPaintDC::CLgPaintDC" );
|
|
}
|
|
|
|
CLgPaintDC::~CLgPaintDC()
|
|
{
|
|
if( m_pWnd )
|
|
{
|
|
::EndPaint( m_pWnd->GetSafeHwnd(), &m_PaintStruct );
|
|
}
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgPaintDC::~CLgPaintDC" );
|
|
}
|