Old fashion design for PC-104
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.
 
 
 
 
 

166 lines
4.3 KiB

//----------------------------------------------------------------------------
// Laser Guard Ltd.
// Copyright © 2000-2002. All Rights Reserved.
// Version 1.0 15/04/2000
// Last modification: 08/10/2003
// Project Intruder Position Indicator
// SUBSYSTEM: Preview
// FILE: Preview.cpp
// AUTHOR: Chizhevskiy Sergey
// OVERVIEW
// ~~~~~~~~
// Source file for implemenation of class CPreview
//----------------------------------------------------------------------------
#include "stdafx.h"
#include "..\LgLib\Version.h"
#include "Preview.h"
CPreview::CPreview()
{
m_Index = 0;
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CPreview::CPreview" );
}
CPreview::~CPreview()
{
if(m_hBitmap)
{
::SendMessage(m_hWnd, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)NULL);
::DeleteDC(m_hMemDC);
::DeleteDC(m_hMemCopyDC);
::DeleteObject(m_hBitmap);
}
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CPreview::~CPreview" );
}
BOOL CPreview::Create(HWND hWnd, LPPOINT pPoint, LPSIZE pSize)
{
static const POINT p = { 0, 0 };
static const POINT s = { 192 * 3, 144 * 5 };
if(!pPoint)
pPoint = (LPPOINT)&p;
if(!pSize)
pSize = (LPSIZE)&s;
m_hWnd = ::CreateWindow("STATIC", NULL, WS_CHILD | SS_BITMAP, pPoint->x, pPoint->y,
pSize->cx, pSize->cy, hWnd, NULL,
(HINSTANCE)::GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
m_Size = *pSize;
HDC hDC = ::GetDC(m_hWnd);
m_hMemDC = ::CreateCompatibleDC(hDC);
m_hMemCopyDC = ::CreateCompatibleDC(hDC);
m_hBitmap = ::CreateCompatibleBitmap(hDC, m_Size.cx, m_Size.cy);
::ReleaseDC(m_hWnd, hDC);
::SendMessage(m_hWnd, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)m_hBitmap);
Reset();
return TRUE;
}
BOOL CPreview::AddPreview(HBITMAP hBitmap)
{
BITMAPINFO bmi;
ZeroMemory(&bmi, sizeof(bmi));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
if( !::GetDIBits( m_hMemCopyDC, hBitmap, 0, 0, NULL, &bmi, DIB_RGB_COLORS ) )
{
bmi.bmiHeader.biWidth = 384;
bmi.bmiHeader.biHeight = 288;
}
HBITMAP hOldBitmap1 = (HBITMAP)::SelectObject(m_hMemDC, m_hBitmap);
HBITMAP hOldBitmap2 = (HBITMAP)::SelectObject(m_hMemCopyDC, hBitmap);
RECT rect = { (m_Index % 3) * m_Size.cx / 3, (m_Index / 3) * m_Size.cy / 5,
((m_Index % 3) + 1 ) * m_Size.cx / 3, ((m_Index / 3) + 1) * m_Size.cy / 5 };
INT nStretchMode = ::SetStretchBltMode( m_hMemDC, COLORONCOLOR );
::StretchBlt(m_hMemDC, rect.left, rect.top, m_Size.cx / 3 + 1, m_Size.cy / 5 + 1, m_hMemCopyDC, 0, 0, bmi.bmiHeader.biWidth, bmi.bmiHeader.biHeight, SRCCOPY);
::SetStretchBltMode( m_hMemDC, nStretchMode );
::SelectObject(m_hMemCopyDC, hOldBitmap2);
::SelectObject(m_hMemDC, hOldBitmap1);
::InvalidateRect(m_hWnd, &rect, FALSE);
::UpdateWindow(m_hWnd);
m_Index = (m_Index + 1) % 15;
return TRUE;
}
void CPreview::Reset()
{
RECT rect = { 0, 0, m_Size.cx, m_Size.cy };
HBITMAP hOldBitmap = (HBITMAP)::SelectObject(m_hMemDC, m_hBitmap);
::FillRect(m_hMemDC, &rect, (HBRUSH)::GetStockObject(BLACK_BRUSH));
::SelectObject(m_hMemDC, hOldBitmap);
::InvalidateRect(m_hWnd, NULL, FALSE);
::UpdateWindow(m_hWnd );
m_Index = 0;
}
BOOL CPreview::Show(BOOL bShow)
{
::ShowWindow(m_hWnd, bShow ? SW_SHOW : SW_HIDE);
::InvalidateRect(m_hWnd, NULL, FALSE);
::UpdateWindow(m_hWnd);
return TRUE;
}
BOOL CPreview::StoreImage1(HANDLE hFile)
{
BITMAPFILEHEADER bfh;
BITMAPINFO bmi;
DWORD dwWrite;
ZeroMemory(&bmi, sizeof(bmi));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
::GetDIBits(m_hMemDC, m_hBitmap, 0, 0, NULL, &bmi, DIB_RGB_COLORS);
bmi.bmiHeader.biCompression = 0;
LPBYTE pByte = new BYTE[bmi.bmiHeader.biSizeImage];
::GetDIBits(m_hMemDC, m_hBitmap, 0, bmi.bmiHeader.biHeight, pByte, &bmi, DIB_RGB_COLORS);
bfh.bfType = (((WORD)'M') << 8) + 'B';
bfh.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + bmi.bmiHeader.biSizeImage;
bfh.bfReserved1 = 0;
bfh.bfReserved2 = 0;
bfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
::WriteFile(hFile, &bfh, sizeof(BITMAPFILEHEADER), &dwWrite, NULL);
::WriteFile(hFile, &bmi, sizeof(BITMAPINFOHEADER), &dwWrite, NULL);
::WriteFile(hFile, pByte, bmi.bmiHeader.biSizeImage, &dwWrite, NULL);
delete[] pByte;
return TRUE;
}