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.
280 lines
6.8 KiB
280 lines
6.8 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 24/03/2000
|
|
// Last modification: 08/10/2003
|
|
// Project Intruder Position Indicator
|
|
// SUBSYSTEM: Video camera showing and captiring window
|
|
// FILE: VideoStaticWnd.cpp
|
|
// AUTHOR: Chizhevskiy Sergey
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file for implementation of class CVideoStaticWnd
|
|
//----------------------------------------------------------------------------
|
|
|
|
#include "stdafx.h"
|
|
#include "..\LgLib\Version.h"
|
|
/*
|
|
#include "VideoStaticWnd.h"
|
|
|
|
CVideoStaticWnd::CVideoStaticWnd( CProfile *pProfile, HWND hParentWnd, LPPOINT pPoint, LPSIZE pSize )
|
|
{
|
|
m_hWnd = NULL;
|
|
m_hMemDC = NULL;
|
|
m_hMemBitmap = NULL;
|
|
m_bEnabled = FALSE;
|
|
|
|
SetProfile( pProfile );
|
|
|
|
Create(hParentWnd, pPoint, pSize);
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CVideoStaticWnd::CVideoStaticWnd(...)" );
|
|
}
|
|
|
|
CVideoStaticWnd::CVideoStaticWnd()
|
|
{
|
|
m_hWnd = NULL;
|
|
m_hMemDC = NULL;
|
|
m_hMemBitmap = NULL;
|
|
m_bEnabled = FALSE;
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CVideoStaticWnd::CVideoStaticWnd" );
|
|
}
|
|
|
|
CVideoStaticWnd::~CVideoStaticWnd()
|
|
{
|
|
if(m_hMemDC)
|
|
::DeleteDC( m_hMemDC );
|
|
|
|
if(m_hMemBitmap)
|
|
::DeleteObject( m_hMemBitmap );
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CVideoStaticWnd::~CVideoStaticWnd" );
|
|
}
|
|
|
|
BOOL CVideoStaticWnd::Create(HWND hParentWnd, LPPOINT pPoint, LPSIZE pSize )
|
|
{
|
|
static POINT point = {0,0};
|
|
static SIZE size = {10,10};
|
|
|
|
if( !pPoint )
|
|
pPoint = &point;
|
|
|
|
if( !pSize )
|
|
pSize = &size;
|
|
|
|
HWND hWnd = ::GetDesktopWindow();
|
|
HDC hDC = ::GetDC( hWnd );
|
|
m_hMemDC = ::CreateCompatibleDC( hDC );
|
|
::ReleaseDC( hWnd, hDC );
|
|
|
|
WNDCLASS wc;
|
|
|
|
wc.cbClsExtra = 0;
|
|
wc.cbWndExtra = 0;
|
|
wc.hbrBackground = NULL;
|
|
wc.hCursor = NULL;
|
|
wc.hIcon = NULL;
|
|
wc.hInstance = (HINSTANCE)::GetWindowLong(hParentWnd, GWL_HINSTANCE);
|
|
wc.lpfnWndProc = (WNDPROC)WndProc_;
|
|
wc.lpszClassName = "VideoStaticWnd";
|
|
wc.lpszMenuName = NULL;
|
|
wc.style = CS_HREDRAW | CS_VREDRAW;
|
|
|
|
if( !::RegisterClass( &wc ) )
|
|
return false;
|
|
|
|
m_hWnd = ::CreateWindowEx( WS_EX_DLGMODALFRAME|WS_EX_CLIENTEDGE, wc.lpszClassName, "", WS_CHILD,
|
|
pPoint->x, pPoint->y, pSize->cx, pSize->cy,
|
|
hParentWnd, NULL, wc.hInstance, this );
|
|
|
|
if(!m_hWnd)
|
|
return false;
|
|
|
|
::ShowWindow( m_hWnd, m_bEnabled ? SW_SHOW : SW_HIDE );
|
|
::UpdateWindow( m_hWnd );
|
|
|
|
if( !VSW_BASE_CLASS::Create( hParentWnd, pPoint, pSize ) )
|
|
return false;
|
|
|
|
::ShowWindow( VSW_BASE_CLASS::GetSafeHwnd(), m_bEnabled ? SW_HIDE : SW_SHOW);
|
|
|
|
Enable( true );
|
|
|
|
return true;
|
|
}
|
|
|
|
LRESULT CVideoStaticWnd::WndProc_( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam )
|
|
{
|
|
LPCREATESTRUCT pCreateStruct;
|
|
CVideoStaticWnd *pThis = NULL;
|
|
|
|
switch( nMsg )
|
|
{
|
|
case WM_CREATE:
|
|
|
|
pCreateStruct = (LPCREATESTRUCT) lParam;
|
|
pThis = (CVideoStaticWnd*)pCreateStruct->lpCreateParams;
|
|
|
|
::SetWindowLong( hWnd, GWL_USERDATA, (LONG)pThis );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pThis = (CVideoStaticWnd*)::GetWindowLong( hWnd, GWL_USERDATA );
|
|
|
|
break;
|
|
}
|
|
|
|
if( pThis )
|
|
return pThis->WndProc( hWnd, nMsg, wParam, lParam );
|
|
|
|
return ::DefWindowProc( hWnd, nMsg, wParam, lParam );
|
|
}
|
|
|
|
LRESULT CVideoStaticWnd::WndProc( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam )
|
|
{
|
|
switch( nMsg )
|
|
{
|
|
case WM_PAINT:
|
|
return OnPaint( wParam, lParam );
|
|
|
|
case WM_SIZE:
|
|
return OnSize( wParam, lParam );
|
|
|
|
case WM_MOVE:
|
|
return OnMove( wParam, lParam );
|
|
}
|
|
|
|
return ::DefWindowProc( hWnd, nMsg, wParam, lParam );
|
|
}
|
|
|
|
void CVideoStaticWnd::Snapshot()
|
|
{
|
|
volatile static BOOL fInside = FALSE;
|
|
HBITMAP fSuccess = NULL;
|
|
|
|
if( !fInside && m_bEnabled )
|
|
{
|
|
fInside = TRUE;
|
|
|
|
if( m_hMemBitmap )
|
|
::DeleteObject( m_hMemBitmap );
|
|
|
|
m_hMemBitmap = (HBITMAP)GetSnapshot();
|
|
|
|
HDC hDC = ::GetDC( m_hWnd );
|
|
|
|
OnDraw( hDC );
|
|
|
|
::ReleaseDC( m_hWnd, hDC );
|
|
|
|
fInside = FALSE;
|
|
}
|
|
}
|
|
|
|
void CVideoStaticWnd::OnDraw( HDC hDC )
|
|
{
|
|
RECT rect;
|
|
|
|
::GetClientRect( m_hWnd, &rect );
|
|
|
|
if( m_hMemBitmap )
|
|
{
|
|
DIBSECTION DibSection;
|
|
if( ::GetObject( m_hMemBitmap, sizeof(DIBSECTION), &DibSection ) )
|
|
{
|
|
HBITMAP hBitmap = (HBITMAP)::SelectObject( m_hMemDC, m_hMemBitmap );
|
|
int nOldMode = ::SetStretchBltMode( hDC, COLORONCOLOR );
|
|
::StretchBlt( hDC, 0, 0, rect.right - rect.left, rect.bottom - rect.top,
|
|
m_hMemDC, 0, 0, DibSection.dsBm.bmWidth, DibSection.dsBm.bmHeight, SRCCOPY );
|
|
::SetStretchBltMode( hDC, nOldMode );
|
|
::SelectObject( m_hMemDC, hBitmap );
|
|
}
|
|
}
|
|
else
|
|
{
|
|
COLORREF nColor = RGB( 0,0,0 );
|
|
COLORREF nBkColor = RGB( 0x7F,0x7F,0x7F );
|
|
|
|
HBRUSH hBrush = ::CreateSolidBrush( nBkColor );
|
|
HPEN hPen = ::CreatePen( PS_SOLID, 1, nBkColor );
|
|
|
|
::FillRect( hDC, &rect, hBrush );
|
|
|
|
HBRUSH hBrushOld = (HBRUSH)::SelectObject( hDC, hBrush );
|
|
HPEN hPenOld = (HPEN)::SelectObject( hDC, hPen );
|
|
|
|
TCHAR pText[] = _T("NO VIDEO");
|
|
INT nText = _tcslen( pText );
|
|
|
|
COLORREF nColorOld = ::SetTextColor( hDC, nColor );
|
|
INT nBkModeOld = ::SetBkMode( hDC, TRANSPARENT );
|
|
|
|
::DrawText( hDC, pText, nText, &rect, DT_SINGLELINE | DT_VCENTER | DT_CENTER );
|
|
|
|
::SetBkMode( hDC, nBkModeOld );
|
|
::SetTextColor( hDC, nColorOld );
|
|
|
|
::SelectObject( hDC, hBrushOld );
|
|
::SelectObject( hDC, hPenOld );
|
|
|
|
::DeleteObject( hBrush );
|
|
::DeleteObject( hPen );
|
|
}
|
|
}
|
|
|
|
LRESULT CVideoStaticWnd::OnSize( WPARAM wParam, LPARAM lParam )
|
|
{
|
|
HWND hParentWnd = (HWND)::GetWindowLong( m_hWnd, GWL_HWNDPARENT );
|
|
|
|
RECT rect;
|
|
::GetClientRect( m_hWnd, &rect );
|
|
|
|
::MapWindowPoints( m_hWnd, hParentWnd, (LPPOINT)&rect, 2 );
|
|
|
|
::MoveWindow( VSW_BASE_CLASS::GetSafeHwnd(), rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, TRUE );
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
LRESULT CVideoStaticWnd::OnPaint( WPARAM wParam, LPARAM lParam )
|
|
{
|
|
PAINTSTRUCT ps;
|
|
|
|
HDC hDC = ::BeginPaint( m_hWnd, &ps );
|
|
|
|
OnDraw( hDC );
|
|
|
|
::EndPaint( m_hWnd, &ps );
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CVideoStaticWnd::Enable(BOOL bEnable)
|
|
{
|
|
m_bEnabled = bEnable;
|
|
|
|
VSW_BASE_CLASS::ShowWindow( m_bEnabled ? SW_HIDE : SW_SHOW );
|
|
// ShowWindow( m_bEnabled ? SW_SHOW : SW_HIDE );
|
|
::BringWindowToTop( m_bEnabled ? GetSafeHwnd() : VSW_BASE_CLASS::GetSafeHwnd() );
|
|
::InvalidateRect( VSW_BASE_CLASS::GetSafeHwnd(), NULL, FALSE );
|
|
::UpdateWindow( VSW_BASE_CLASS::GetSafeHwnd() );
|
|
|
|
// ::ShowWindow( m_hWnd, m_bEnabled ? SW_SHOW : SW_HIDE );
|
|
// ::UpdateWindow( m_hWnd );
|
|
|
|
HWND hParentWnd = (HWND)::GetWindowLong( m_hWnd, GWL_HWNDPARENT );
|
|
::InvalidateRect( hParentWnd, NULL, FALSE );
|
|
::UpdateWindow( hParentWnd );
|
|
}
|
|
|
|
LRESULT CVideoStaticWnd::OnMove(WPARAM wParam, LPARAM lParam)
|
|
{
|
|
int xPos = (int)(short) LOWORD(lParam); // horizontal position
|
|
int yPos = (int)(short) HIWORD(lParam); // vertical position
|
|
|
|
return TRUE;
|
|
}
|
|
*/
|