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.
147 lines
3.8 KiB
147 lines
3.8 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 08/10/2003
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: ImageWnd.cpp
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of ImageWnd.cpp
|
|
//----------------------------------------------------------------------------
|
|
// ImageWnd.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "chicago.h"
|
|
#include "ImageWnd.h"
|
|
#include "..\..\LgLib\Version.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CImageWnd
|
|
|
|
CImageWnd::CImageWnd()
|
|
{
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CImageWnd::CImageWnd") );
|
|
}
|
|
|
|
CImageWnd::~CImageWnd()
|
|
{
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CImageWnd::~CImageWnd") );
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CImageWnd, CWnd)
|
|
//{{AFX_MSG_MAP(CImageWnd)
|
|
ON_WM_PAINT()
|
|
ON_WM_SIZE()
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CImageWnd message handlers
|
|
|
|
BOOL CImageWnd::Create(CWnd *pParentWnd, int x, int y, int cx, int cy)
|
|
{
|
|
CString strClassName = ::AfxRegisterWndClass( CS_HREDRAW | CS_VREDRAW, ::LoadCursor( NULL, IDC_ARROW ), NULL, NULL );
|
|
CRect rect( x, y, x + cx, y + cy );
|
|
if( CWnd::Create( strClassName, NULL, WS_CHILD|WS_VISIBLE, rect, pParentWnd, 0 ) )
|
|
{
|
|
m_MemDC.Create( cx, cy );
|
|
|
|
CClientDC dc( this );
|
|
m_CopyDC.CreateCompatibleDC( &dc );
|
|
|
|
return TRUE;
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
BOOL CImageWnd::Create( CWnd *pParentWnd, CRect *pRect )
|
|
{
|
|
return CImageWnd::Create( pParentWnd, pRect->left, pRect->top, pRect->Width(), pRect->Height() );
|
|
}
|
|
|
|
void CImageWnd::PostNcDestroy()
|
|
{
|
|
m_CopyDC.DeleteDC();
|
|
|
|
CWnd::PostNcDestroy();
|
|
}
|
|
|
|
void CImageWnd::OnPaint()
|
|
{
|
|
CPaintDC dc(this); // device context for painting
|
|
|
|
CRect rect;
|
|
GetClientRect( &rect );
|
|
|
|
dc.BitBlt( 0, 0, rect.Width(), rect.Height(), &m_MemDC, 0, 0, SRCCOPY );
|
|
}
|
|
|
|
void CImageWnd::SetImage( LPBITMAPINFO pBmi, LPBYTE pBuffer )
|
|
{
|
|
if( pBmi && pBuffer )
|
|
{
|
|
// create DDB bitmap indirect
|
|
LPBYTE pBits = NULL;
|
|
HBITMAP hBitmap = ::CreateDIBSection( m_CopyDC.GetSafeHdc(), pBmi, DIB_RGB_COLORS, (void**)&pBits, NULL, 0UL );
|
|
if( pBits )
|
|
{
|
|
// copy data to image bits
|
|
::CopyMemory( pBits, pBuffer, pBmi->bmiHeader.biSizeImage );
|
|
|
|
// create temp CBitmap object and attach it to DDB bitmap
|
|
CBitmap bmp;
|
|
bmp.Attach( hBitmap );
|
|
|
|
// select temp bitmap into m_CopyDC
|
|
CBitmap *pBitmapOld = m_CopyDC.SelectObject( &bmp );
|
|
|
|
// copy from m_CopyDC to m_MemDC
|
|
int nOldStretchMode = m_MemDC.SetStretchBltMode( COLORONCOLOR );
|
|
m_MemDC.StretchBlt( 0, 0, m_MemDC.GetSize().cx, m_MemDC.GetSize().cy, &m_CopyDC,
|
|
0, 0, pBmi->bmiHeader.biWidth, pBmi->bmiHeader.biHeight, SRCCOPY );
|
|
m_MemDC.SetStretchBltMode( nOldStretchMode );
|
|
|
|
// restore selected bitmap in m_CopyDC
|
|
m_CopyDC.SelectObject( pBitmapOld );
|
|
|
|
// detach and delete DDB bitmap
|
|
bmp.Detach();
|
|
::DeleteObject( hBitmap );
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// clear bitmap (filling with black)
|
|
CRect rect( 0, 0, m_MemDC.GetSize().cx, m_MemDC.GetSize().cy );
|
|
m_MemDC.FillSolidRect( &rect, RGB(0,0,0) );
|
|
COLORREF nOldTextColor = m_MemDC.SetTextColor( RGB(0x7F,0x7F,0x7F) );
|
|
m_MemDC.DrawText( CString( _T("No captured image") ), &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
|
|
m_MemDC.SetTextColor( nOldTextColor );
|
|
}
|
|
|
|
if( GetSafeHwnd() )
|
|
{
|
|
InvalidateRect( NULL );
|
|
RedrawWindow();
|
|
}
|
|
}
|
|
|
|
void CImageWnd::OnSize(UINT nType, int cx, int cy)
|
|
{
|
|
CWnd::OnSize(nType, cx, cy);
|
|
|
|
if( cx && cy )
|
|
m_MemDC.Create( cx, cy );
|
|
}
|