|
|
//----------------------------------------------------------------------------
// Laser Guard Ltd.
// Copyright � 2000-2002. All Rights Reserved.
// Version 1.0 01/01/2000
// Last modification: 08/10/2003
// PROJECT:
// SUBSYSTEM:
// FILE: Background.cpp
// AUTHOR: Sergey Chizhevskiy
// OVERVIEW
// ~~~~~~~~
// Source file of Background.cpp
//----------------------------------------------------------------------------
// Background.cpp: implementation of the CBackground class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Background.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CBackground::CBackground(){ m_Type = ET_GENERIC; m_Size = CSize( 1000, 1000 ); m_VersionInfo.dwOSVersionInfoSize = sizeof( m_VersionInfo ); ::GetVersionEx( &m_VersionInfo ); ::InitializeCriticalSection( &m_CritSection );}
CBackground::~CBackground(){ ::DeleteCriticalSection( &m_CritSection );}
BOOL CBackground::Load( LPCTSTR pFileName, CLgFileGroup *pFileGroup ){ m_Type = ET_GENERIC;
HBITMAP hBitmap = NULL;
if( pFileGroup ) hBitmap = (HBITMAP)pFileGroup->LoadImage( pFileName, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE ); else hBitmap = (HBITMAP)::LoadImage( NULL, pFileName, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE );
if( hBitmap ) { if( m_MemoryDC.Create( hBitmap, FALSE ) ) { m_Size = m_MemoryDC.GetSize(); m_Type = ET_BITMAP; return TRUE; } }
TCHAR pBuffer[MAX_PATH]; BOOL bFromFileGroup = ( bFromFileGroup = pFileGroup && pFileGroup->GetTemp( pFileName, pBuffer, MAX_PATH ) );
if( m_MetaFile.Load( bFromFileGroup ? pBuffer : pFileName ) ) { m_Size = m_MetaFile.GetSize(); m_Type = ET_METAFILE;
if( bFromFileGroup ) DeleteFile( pBuffer );
return TRUE; }
if( bFromFileGroup ) DeleteFile( pBuffer );
return FALSE;}
BOOL CBackground::Draw( CDC *pDC, CRect *pRect ){ ::EnterCriticalSection( &m_CritSection );
int smode; bool bNT = ( m_VersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT ); BOOL bSuccess;
switch( m_Type ) { case ET_BITMAP: smode = pDC->SetStretchBltMode( bNT ? HALFTONE : COLORONCOLOR ); pDC->StretchBlt( pRect->left, pRect->top, pRect->Width(), pRect->Height(), &m_MemoryDC, 0, 0, m_Size.cx, m_Size.cy, SRCCOPY ); pDC->SetStretchBltMode( smode ); bSuccess = TRUE; break;
case ET_METAFILE: pDC->PlayMetaFile( m_MetaFile, pRect ); bSuccess = TRUE; break;
default: pDC->FillSolidRect( pRect, RGB(0x7F,0,0) ); bSuccess = FALSE; break; } ::LeaveCriticalSection( &m_CritSection );
return bSuccess;}
|