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.
255 lines
6.8 KiB
255 lines
6.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 "ImageWnd.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CImageWnd
|
|
|
|
CImageWnd::CImageWnd()
|
|
{
|
|
}
|
|
|
|
CImageWnd::~CImageWnd()
|
|
{
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CImageWnd, CWnd)
|
|
//{{AFX_MSG_MAP(CImageWnd)
|
|
ON_WM_PAINT()
|
|
ON_WM_SIZE()
|
|
ON_WM_LBUTTONDOWN()
|
|
ON_WM_LBUTTONUP()
|
|
ON_WM_MOUSEMOVE()
|
|
//}}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 );
|
|
|
|
CSize size = m_MemDC.GetSize();
|
|
|
|
CLgMemoryDC memDC;
|
|
memDC.Create( size.cx, size.cy );
|
|
memDC.BitBlt( 0, 0, size.cx, size.cy, &m_MemDC, 0, 0, SRCCOPY );
|
|
|
|
POSITION pos = m_List.GetHeadPosition();
|
|
while( pos )
|
|
{
|
|
COFTemplateDCBit *pBit = m_List.GetNext( pos );
|
|
CLgDPoint dp = pBit->GetPos();
|
|
CPoint p( (int)(dp.x*size.cx), (int)(dp.y*size.cy) );
|
|
|
|
CRect r( p.x - 10, p.y - 10, p.x + 10, p.y + 10 );
|
|
|
|
memDC.FillSolidRect( &r, RGB( 0x3F,0x3F,0x3F ) );
|
|
memDC.Draw3dRect( &r, RGB( 0xFF,0xFF,0xFF), RGB( 0x7F,0x7F,0x7F) );
|
|
|
|
COLORREF oldColor = memDC.SetTextColor( RGB(0xFF,0xFF,0xFF) );
|
|
int oldBkMode = memDC.SetBkMode( TRANSPARENT );
|
|
memDC.DrawText( pBit->GetName(), &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
|
|
memDC.SetBkMode( oldBkMode );
|
|
memDC.SetTextColor( oldColor );
|
|
}
|
|
|
|
dc.BitBlt( 0, 0, rect.Width(), rect.Height(), &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 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 );
|
|
}
|
|
|
|
void CImageWnd::SetImage( CString &file )
|
|
{
|
|
HINSTANCE hInst = (HINSTANCE)::GetWindowLong( GetSafeHwnd(), GWL_HINSTANCE );
|
|
// load bitmap from file
|
|
HBITMAP hBitmap = (HBITMAP)::LoadImage( hInst, file, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE|LR_LOADFROMFILE );
|
|
|
|
SetImage( hBitmap );
|
|
|
|
if( hBitmap )
|
|
::DeleteObject( hBitmap );
|
|
}
|
|
|
|
void CImageWnd::SetImage( CBitmap *pBitmap )
|
|
{
|
|
if( pBitmap )
|
|
SetImage( (HBITMAP)pBitmap->GetSafeHandle() );
|
|
else
|
|
SetImage( (HBITMAP)NULL );
|
|
}
|
|
|
|
void CImageWnd::SetImage( HBITMAP hBitmap )
|
|
{
|
|
if( hBitmap )
|
|
{
|
|
// create temp CBitmap object and attach it to bitmap
|
|
CBitmap bmp;
|
|
bmp.Attach( hBitmap );
|
|
|
|
// retrieve bitmap parameters
|
|
BITMAPINFO bmi;
|
|
::ZeroMemory( &bmi, sizeof( bmi ) );
|
|
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
|
::GetDIBits( m_CopyDC.GetSafeHdc(), hBitmap, 0, 0, NULL, &bmi, DIB_RGB_COLORS );
|
|
|
|
// 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, bmi.bmiHeader.biWidth, bmi.bmiHeader.biHeight, SRCCOPY );
|
|
m_MemDC.SetStretchBltMode( nOldStretchMode );
|
|
|
|
// restore selected bitmap in m_CopyDC
|
|
m_CopyDC.SelectObject( pBitmapOld );
|
|
|
|
// detach bitmap
|
|
bmp.Detach();
|
|
}
|
|
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 image") ), &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
|
|
m_MemDC.SetTextColor( nOldTextColor );
|
|
}
|
|
|
|
if( GetSafeHwnd() )
|
|
{
|
|
InvalidateRect( NULL );
|
|
RedrawWindow();
|
|
}
|
|
}
|
|
|
|
void CImageWnd::OnLButtonDown(UINT nFlags, CPoint point)
|
|
{
|
|
GetParent()->SendMessage( WM_IMAGE_LBUTTONDOWN, nFlags, (LPARAM)&point );
|
|
CWnd::OnLButtonDown(nFlags, point);
|
|
}
|
|
|
|
void CImageWnd::OnLButtonUp(UINT nFlags, CPoint point)
|
|
{
|
|
GetParent()->SendMessage( WM_IMAGE_LBUTTONUP, nFlags, (LPARAM)&point );
|
|
CWnd::OnLButtonUp(nFlags, point);
|
|
}
|
|
|
|
void CImageWnd::OnMouseMove(UINT nFlags, CPoint point)
|
|
{
|
|
GetParent()->SendMessage( WM_IMAGE_MOUSEMOVE, nFlags, (LPARAM)&point );
|
|
CWnd::OnMouseMove(nFlags, point);
|
|
}
|