// PSheetsView.cpp : implementation of the CPSheetsView class
//
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "resource.h"
#include "PSheetsView.h"
#include "OptionsSheet.h"
#include "OptionsWizard.h"
//////////////////////////////////////////////////////////////////////
// Construction
CPSheetsView::CPSheetsView() : m_nColor(0), m_nPicture(0)
{
}
//////////////////////////////////////////////////////////////////////
// Message handlers
BOOL CPSheetsView::PreTranslateMessage(MSG* pMsg)
{
pMsg;
return FALSE;
}
BOOL CPSheetsView::OnEraseBkgnd ( HDC hdc )
{
CDCHandle dc = hdc;
CDC dcMem;
CBitmap bmpMem;
CRect rcClient;
CBitmapHandle bmpOld, bmpOld2;
// If we haven't loaded the bitmap yet, do so now.
if ( m_bmpBkgnd.IsNull() )
{
switch ( m_nPicture )
{
case 0: m_bmpBkgnd.LoadBitmap ( IDB_ALYSON ); break;
case 1: m_bmpBkgnd.LoadBitmap ( IDB_THECHEAT ); break;
case 2: m_bmpBkgnd.LoadBitmap ( IDB_STRONGBAD ); break;
}
if ( m_bmpBkgnd )
m_bmpBkgnd.GetSize ( m_szBkgndBitmap );
}
// Make a memory DC that we can draw to.
GetClientRect ( rcClient );
dcMem.CreateCompatibleDC ( dc );
bmpMem.CreateCompatibleBitmap ( dc, rcClient.Width(), rcClient.Height() );
// Fill the client area & draw the bitmap.
bmpOld = dcMem.SelectBitmap ( bmpMem );
switch ( m_nColor )
{
case 0: dcMem.FillSolidRect ( rcClient, RGB(0,0,128) ); break;
case 1: dcMem.FillSolidRect ( rcClient, RGB(255,153,0) ); break;
case 2:
{
TRIVERTEX atv[] = {
{ rcClient.left, rcClient.top, 0xff00, 0, 0 }, // 0 top left (red)
{ rcClient.right, rcClient.bottom, 0, 0, 0xff00 } // 1 bottom right (blue)
};
GRADIENT_RECT gt = { 0, 1 };
dcMem.GradientFill ( atv, countof(atv), >, 1, GRADIENT_FILL_RECT_H );
}
break;
}
if ( m_bmpBkgnd )
{
CDC dcPicture;
int x, y, cx, cy;
dcPicture.CreateCompatibleDC ( dc );
bmpOld2 = dcPicture.SelectBitmap ( m_bmpBkgnd );
cx = m_szBkgndBitmap.cx;
cy = m_szBkgndBitmap.cy;
x = rcClient.Width() - cx;
y = rcClient.Height() - cy;
dcMem.BitBlt ( x, y, cx, cy, dcPicture, 0, 0, SRCCOPY );
dcPicture.SelectBitmap ( bmpOld2 );
}
// Blit to the screen.
dc.BitBlt ( 0, 0, rcClient.Width(), rcClient.Height(), dcMem, 0, 0, SRCCOPY );
dc.SelectBitmap ( bmpOld );
return TRUE;
}
//////////////////////////////////////////////////////////////////////
// Command handlers
void CPSheetsView::OnOptions ( UINT uCode, int nID, HWND hwndCtrl )
{
COptionsSheet sheet ( _T("PSheets Options"), 0 );
sheet.m_pgBackground.m_nColor = m_nColor;
sheet.m_pgBackground.m_nPicture = m_nPicture;
if ( IDOK == sheet.DoModal ( GetTopLevelParent() ))
SetBackgroundOptions ( sheet.m_pgBackground.m_nColor,
sheet.m_pgBackground.m_nPicture );
}
void CPSheetsView::OnOptionsWizard ( UINT uCode, int nID, HWND hwndCtrl )
{
COptionsWizard wizard;
wizard.m_pgBkcolor.m_nColor = m_nColor;
wizard.m_pgBkpicture.m_nPicture = m_nPicture;
if ( IDOK == wizard.DoModal ( GetTopLevelParent() ))
SetBackgroundOptions ( wizard.m_pgBkcolor.m_nColor,
wizard.m_pgBkpicture.m_nPicture );
}
//////////////////////////////////////////////////////////////////////
// Other methods
void CPSheetsView::SetBackgroundOptions ( int nColor, int nPicture )
{
if ( m_nColor != nColor )
m_nColor = nColor;
if ( m_nPicture != nPicture )
{
m_nPicture = nPicture;
if ( m_bmpBkgnd )
m_bmpBkgnd.DeleteObject();
}
RedrawWindow();
}