www.pudn.com > LayeredBitmapCtrl_demo.zip > LayeredBitmapCtrlDemoDlg.cpp


// LayeredBitmapCtrlDemoDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "LayeredBitmapCtrlDemo.h" 
#include "LayeredBitmapCtrlDemoDlg.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
 
enum 
{ 
	// Layer1 items. 
	HURRICANE_AFTERMATH_LAYER = 100, 
	VALLEY_OF_FIRE_LAYER, 
 
	// Layer2 item. 
	CHAMELEON_BOB_LAYER, 
	CP_BOB_LAYER, 
 
	// Layer3 items. 
	CHAINSAW_LAYER, 
	COWBOY_HAT_LAYER, 
	SUNGLASSES_LAYER, 
 
	// Layer 4 items. 
	GRID_LAYER, 
	TRIANGLE_LAYER, 
	ELLIPSE_LAYER 
}; 
 
 
///////////////////////////////////////////////////////////////////////////// 
// CAboutDlg dialog used for App About 
 
class CAboutDlg : public CDialog 
{ 
public: 
	CAboutDlg(); 
 
// Dialog Data 
	//{{AFX_DATA(CAboutDlg) 
	enum { IDD = IDD_ABOUTBOX }; 
	//}}AFX_DATA 
 
	// ClassWizard generated virtual function overrides 
	//{{AFX_VIRTUAL(CAboutDlg) 
	protected: 
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support 
	//}}AFX_VIRTUAL 
 
// Implementation 
protected: 
	//{{AFX_MSG(CAboutDlg) 
	//}}AFX_MSG 
	DECLARE_MESSAGE_MAP() 
}; 
 
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) 
{ 
	//{{AFX_DATA_INIT(CAboutDlg) 
	//}}AFX_DATA_INIT 
} 
 
void CAboutDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CAboutDlg) 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) 
	//{{AFX_MSG_MAP(CAboutDlg) 
		// No message handlers 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CLayeredBitmapCtrlDemoDlg dialog 
 
CLayeredBitmapCtrlDemoDlg::CLayeredBitmapCtrlDemoDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CLayeredBitmapCtrlDemoDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CLayeredBitmapCtrlDemoDlg) 
	//}}AFX_DATA_INIT 
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 
} 
 
void CLayeredBitmapCtrlDemoDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CLayeredBitmapCtrlDemoDlg) 
	DDX_Control(pDX, IDC_LAYERED_DISPLAY, m_layeredDisplay); 
	DDX_Control(pDX, IDC_LAYER1_COMBO, m_layer1Combo); 
	DDX_Control(pDX, IDC_LAYER2_COMBO, m_layer2Combo); 
	DDX_Control(pDX, IDC_LAYER3_COMBO, m_layer3Combo); 
	DDX_Control(pDX, IDC_LAYER4_COMBO, m_layer4Combo); 
	//}}AFX_DATA_MAP 
} 
 
void CLayeredBitmapCtrlDemoDlg::SetupLayers() 
{ 
	CLayerInfo *pLayerInfo = NULL; 
 
	// Here are the background bitmaps for the Layer1 Selection. 
	// Create a new layer. 
	pLayerInfo								= new CLayerInfo(); 
	pLayerInfo->m_nLayerID					= HURRICANE_AFTERMATH_LAYER; 
	pLayerInfo->m_strLayerDesc				= _T("Hurricane Aftermath"); 
	pLayerInfo->m_bmp.LoadBitmap( IDB_HURRICANE_AFTERMATH_BITMAP ); 
 
	m_layeredDisplay.AddLayer( *pLayerInfo ); 
	delete pLayerInfo; 
 
 
	// Create a new layer. 
	pLayerInfo								= new CLayerInfo(); 
	pLayerInfo->m_nLayerID					= VALLEY_OF_FIRE_LAYER; 
	pLayerInfo->m_strLayerDesc				= _T("Valley of Fire"); 
	pLayerInfo->m_bmp.LoadBitmap( IDB_VALLEY_OF_FIRE_BITMAP ); 
 
	m_layeredDisplay.AddLayer( *pLayerInfo ); 
	delete pLayerInfo; 
 
 
	// Here is the transparent bitmap for the Layer2 Selection. 
	// Create a new layer. 
	pLayerInfo								= new CLayerInfo(); 
	pLayerInfo->m_nLayerID					= CHAMELEON_BOB_LAYER; 
	pLayerInfo->m_strLayerDesc				= _T("Chameleon Bob"); 
	pLayerInfo->m_bTransparent				= true; 
	pLayerInfo->m_ptTransparentPixel.x		= 1; 
	pLayerInfo->m_ptTransparentPixel.y		= 1; 
	pLayerInfo->m_ptLocation.x				= 200; 
	pLayerInfo->m_ptLocation.y				= 210; 
	pLayerInfo->m_bTrackingEnabled			= true; 
	pLayerInfo->m_bFocusRectangleEnabled	= true; 
	pLayerInfo->m_colFocusRectangle			= RGB( 0, 255, 0 ); 
 
	pLayerInfo->m_bmp.LoadBitmap( IDB_CHAMELEON_BOB_BITMAP ); 
 
	m_layeredDisplay.CreateNonTransparentRgn( pLayerInfo ); 
	pLayerInfo->m_rgn.OffsetRgn( pLayerInfo->m_ptLocation.x, pLayerInfo->m_ptLocation.y ); 
 
	m_layeredDisplay.AddLayer( *pLayerInfo ); 
	delete pLayerInfo; 
 
 
	// Create a new layer. 
	pLayerInfo								= new CLayerInfo(); 
	pLayerInfo->m_nLayerID					= CP_BOB_LAYER; 
	pLayerInfo->m_strLayerDesc				= _T("Code Project's Bob"); 
	pLayerInfo->m_bTransparent				= true; 
	pLayerInfo->m_ptTransparentPixel.x		= 1; 
	pLayerInfo->m_ptTransparentPixel.y		= 1; 
	pLayerInfo->m_ptLocation.x				= 200; 
	pLayerInfo->m_ptLocation.y				= 210; 
	pLayerInfo->m_bTrackingEnabled			= true; 
	 
	// This will allow you to move Bob underneath all of the visible layers above. 
	// Just remember that this will be slower because the sections of layers above must be redrawn. 
	pLayerInfo->m_bShowOnTopWhileTracking	= false; 
 
	pLayerInfo->m_bFocusRectangleEnabled	= true; 
	pLayerInfo->m_colFocusRectangle			= RGB( 255, 255, 0 ); 
 
	pLayerInfo->m_bmp.LoadBitmap( IDB_CP_BOB_BITMAP ); 
 
	m_layeredDisplay.CreateNonTransparentRgn( pLayerInfo ); 
	pLayerInfo->m_rgn.OffsetRgn( pLayerInfo->m_ptLocation.x, pLayerInfo->m_ptLocation.y ); 
 
	m_layeredDisplay.AddLayer( *pLayerInfo ); 
	delete pLayerInfo; 
 
 
	// Here are the transparent bitmaps for the Layer3 Selection. 
	// Create a new layer. 
	pLayerInfo								= new CLayerInfo(); 
	pLayerInfo->m_nLayerID					= CHAINSAW_LAYER; 
	pLayerInfo->m_strLayerDesc				= _T("Chainsaw"); 
	pLayerInfo->m_bTransparent				= true; 
	pLayerInfo->m_ptTransparentPixel.x		= 1; 
	pLayerInfo->m_ptTransparentPixel.y		= 1; 
	pLayerInfo->m_ptLocation.x				= 150; 
	pLayerInfo->m_ptLocation.y				= 230; 
	pLayerInfo->m_bTrackingEnabled			= true; 
	pLayerInfo->m_bFocusRectangleEnabled	= true; 
	pLayerInfo->m_bmp.LoadBitmap( IDB_CHAINSAW_BITMAP ); 
 
	m_layeredDisplay.CreateNonTransparentRgn( pLayerInfo ); 
	pLayerInfo->m_rgn.OffsetRgn( pLayerInfo->m_ptLocation.x, pLayerInfo->m_ptLocation.y ); 
 
	m_layeredDisplay.AddLayer( *pLayerInfo ); 
	delete pLayerInfo; 
 
 
	// Create a new layer. 
	pLayerInfo								= new CLayerInfo(); 
	pLayerInfo->m_nLayerID					= SUNGLASSES_LAYER; 
	pLayerInfo->m_strLayerDesc				= _T("Sunglasses"); 
	pLayerInfo->m_bTransparent				= true; 
	pLayerInfo->m_ptTransparentPixel.x		= 1; 
	pLayerInfo->m_ptTransparentPixel.y		= 1; 
	pLayerInfo->m_ptLocation.x				= 210; 
	pLayerInfo->m_ptLocation.y				= 222; 
	pLayerInfo->m_bTrackingEnabled			= true; 
	pLayerInfo->m_bFocusRectangleEnabled	= true; 
	pLayerInfo->m_bmp.LoadBitmap( IDB_SUNGLASSES_BITMAP ); 
 
	m_layeredDisplay.CreateNonTransparentRgn( pLayerInfo ); 
	pLayerInfo->m_rgn.OffsetRgn( pLayerInfo->m_ptLocation.x, pLayerInfo->m_ptLocation.y ); 
 
	m_layeredDisplay.AddLayer( *pLayerInfo ); 
	delete pLayerInfo; 
 
 
	// Create a new layer. 
	pLayerInfo								= new CLayerInfo(); 
	pLayerInfo->m_nLayerID					= COWBOY_HAT_LAYER; 
	pLayerInfo->m_strLayerDesc				= _T("Cowboy Hat"); 
	pLayerInfo->m_bTransparent				= true; 
	pLayerInfo->m_ptTransparentPixel.x		= 1; 
	pLayerInfo->m_ptTransparentPixel.y		= 1; 
	pLayerInfo->m_ptLocation.x				= 207; 
	pLayerInfo->m_ptLocation.y				= 197; 
	pLayerInfo->m_bTrackingEnabled			= true; 
	pLayerInfo->m_bFocusRectangleEnabled	= true; 
	pLayerInfo->m_bmp.LoadBitmap( IDB_COWBOY_HAT_BITMAP ); 
 
	m_layeredDisplay.CreateNonTransparentRgn( pLayerInfo ); 
	pLayerInfo->m_rgn.OffsetRgn( pLayerInfo->m_ptLocation.x, pLayerInfo->m_ptLocation.y ); 
 
	m_layeredDisplay.AddLayer( *pLayerInfo ); 
	delete pLayerInfo; 
 
	 
	// Create the bitmaps for the Layer4 Selection. 
	CreateGridLayer(); 
	CreateTriangleLayer(); 
	CreateEllipseLayer(); 
 
	m_layeredDisplay.ShowVisibleLayers(); 
	return; 
} 
 
void CLayeredBitmapCtrlDemoDlg::CreateGridLayer() 
{ 
	CLayerInfo *pLayerInfo					= new CLayerInfo(); 
    pLayerInfo->m_nLayerID					= GRID_LAYER; 
    pLayerInfo->m_strLayerDesc				= _T("Grid"); 
    pLayerInfo->m_bTransparent				= true; 
    pLayerInfo->m_ptLocation.x				= 0; 
    pLayerInfo->m_ptLocation.y				= 0; 
 
	// Create a dynamic grid. 
	CDC *pDC = m_layeredDisplay.GetDC(); 
	CDC tmpDC; 
	CBitmap *pOldBmp = NULL; 
	COLORREF colTrans = RGB( 255, 255, 255 ); 
	COLORREF colGrid = RGB( 192, 192, 192 ); 
	COLORREF colGridDark = RGB( 0, 0, 0 ); 
	COLORREF colBG = RGB( 255, 255, 255 ); 
	CPen *pOldPen = NULL; 
	CPen penGrid, penGridDark; 
	CRect rect; 
 
	m_layeredDisplay.GetClientRect( &rect ); 
 
	int nMaxVLine = rect.Width() / 30; 
	int nMaxHLine = rect.Height() / 30; 
 
	pLayerInfo->m_colTransparent = colTrans; 
 
	tmpDC.CreateCompatibleDC( pDC ); 
	pLayerInfo->m_bmp.CreateCompatibleBitmap( pDC, rect.Width(), rect.Height() ); 
 
	pOldBmp = tmpDC.SelectObject( &pLayerInfo->m_bmp ); 
 
	tmpDC.FillSolidRect( 0, 0, rect.Width(), rect.Height(), colTrans ); 
 
	penGrid.CreatePen( PS_SOLID, 2, colGrid ); 
	penGridDark.CreatePen( PS_SOLID, 1, colGridDark ); 
 
	pOldPen = tmpDC.SelectObject( &penGrid ); 
 
	int i = 0; 
	int nCurrentColumn = 30; 
	for (i = 0; i < nMaxVLine; i++) 
	{ 
		tmpDC.MoveTo( nCurrentColumn, 0 ); 
		tmpDC.LineTo( nCurrentColumn, rect.Height() ); 
		 
		tmpDC.SelectObject( &penGridDark ); 
 
		tmpDC.MoveTo( nCurrentColumn + 1, 0 ); 
		tmpDC.LineTo( nCurrentColumn + 1, rect.Height() ); 
 
		tmpDC.SelectObject( &penGrid ); 
 
		nCurrentColumn += 30; 
	} 
 
	int nCurrentRow = 30; 
	for (i = 0; i < nMaxHLine; i++) 
	{ 
		tmpDC.MoveTo( 0, nCurrentRow ); 
		tmpDC.LineTo( rect.Width(), nCurrentRow ); 
 
		tmpDC.SelectObject( &penGridDark ); 
 
		tmpDC.MoveTo( 0, nCurrentRow + 1 ); 
		tmpDC.LineTo( rect.Width(), nCurrentRow + 1 ); 
 
		tmpDC.SelectObject( &penGrid ); 
 
		nCurrentRow += 30; 
	} 
 
	// Cleanup. 
	tmpDC.SelectObject( pOldPen ); 
	tmpDC.SelectObject( pOldBmp ); 
 
	penGrid.DeleteObject(); 
	penGridDark.DeleteObject(); 
 
	pLayerInfo->m_colTransparent = colTrans; 
 
    m_layeredDisplay.AddLayer( *pLayerInfo ); 
    delete pLayerInfo; 
 
	m_layeredDisplay.ReleaseDC( pDC ); 
 
	return; 
} 
 
void CLayeredBitmapCtrlDemoDlg::CreateTriangleLayer() 
{ 
	CLayerInfo *pLayerInfo					= new CLayerInfo(); 
    pLayerInfo->m_nLayerID					= TRIANGLE_LAYER; 
    pLayerInfo->m_strLayerDesc				= _T("Triangle"); 
    pLayerInfo->m_bTransparent				= true; 
	pLayerInfo->m_colTransparent			= RGB( 255, 0, 255 ); 
    pLayerInfo->m_ptLocation.x				= 0; 
    pLayerInfo->m_ptLocation.y				= 0; 
 
	// Create a dynamic triangle. 
	CDC *pDC = m_layeredDisplay.GetDC(); 
	CDC tmpDC; 
	CBitmap *pOldBmp = NULL; 
	CRect rect; 
 
	COLORREF colBG = RGB( 0, 0, 0 );  //::GetSysColor( COLOR_BTNFACE ); 
	COLORREF colTrans = RGB( 255, 0, 255 ); 
 
	m_layeredDisplay.GetClientRect( &rect ); 
 
	tmpDC.CreateCompatibleDC( pDC ); 
	pLayerInfo->m_bmp.CreateCompatibleBitmap( pDC, rect.Width(), rect.Height() ); 
 
	pOldBmp = tmpDC.SelectObject( &pLayerInfo->m_bmp ); 
 
	tmpDC.FillSolidRect( 0, 0, rect.Width(), rect.Height(), colBG ); 
 
	CPen pen; 
	CPen *pOldPen = NULL; 
	CBrush brush; 
	CBrush *pOldBrush = NULL; 
 
	pen.CreatePen( PS_SOLID, 1, colTrans ); 
	pOldPen = tmpDC.SelectObject( &pen ); 
 
	brush.CreateSolidBrush( colTrans ); 
	pOldBrush = tmpDC.SelectObject( &brush ); 
	 
	CPoint *ptArray = new CPoint[4]; 
 
	ptArray[0].x = rect.Width() / 2; 
	ptArray[0].y = 0; 
 
	ptArray[1].x = 0; 
	ptArray[1].y = rect.Height(); 
 
	ptArray[2].x = rect.Width(); 
	ptArray[2].y = rect.Height(); 
 
	ptArray[3].x = rect.Width() / 2; 
	ptArray[3].y = 0; 
 
	tmpDC.Polygon( ptArray, 4 ); 
 
	// Create a poly rgn to use for the mouse hit test. 
	pLayerInfo->m_rgn.CreatePolygonRgn( ptArray, 4, ALTERNATE ); 
 
	m_layeredDisplay.CalculateCenterOffset( pLayerInfo ); 
 
	pLayerInfo->m_rgn.OffsetRgn( pLayerInfo->m_ptLocation.x, pLayerInfo->m_ptLocation.y ); 
	 
	delete [] ptArray; 
 
	// Cleanup. 
	tmpDC.SelectObject( pOldBrush ); 
	tmpDC.SelectObject( pOldPen ); 
	tmpDC.SelectObject( pOldBmp ); 
 
	pen.DeleteObject(); 
	brush.DeleteObject(); 
 
	m_layeredDisplay.AddLayer( *pLayerInfo ); 
 
	delete pLayerInfo; 
 
	m_layeredDisplay.ReleaseDC( pDC ); 
	return; 
} 
 
void CLayeredBitmapCtrlDemoDlg::CreateEllipseLayer() 
{ 
	CLayerInfo *pLayerInfo					= new CLayerInfo(); 
    pLayerInfo->m_nLayerID					= ELLIPSE_LAYER; 
    pLayerInfo->m_strLayerDesc				= _T("Ellipse"); 
    pLayerInfo->m_bTransparent				= true; 
	pLayerInfo->m_colTransparent			= RGB( 255, 0, 255 ); 
    pLayerInfo->m_ptLocation.x				= 0; 
    pLayerInfo->m_ptLocation.y				= 0; 
 
	// Create a dynamic ellipse. 
	CDC *pDC = m_layeredDisplay.GetDC(); 
	CDC tmpDC; 
	CBitmap *pOldBmp = NULL; 
	CRect rect; 
 
	COLORREF colBG = RGB( 0, 0, 0 );  //::GetSysColor( COLOR_BTNFACE ); 
	COLORREF colTrans = RGB( 255, 0, 255 ); 
 
	m_layeredDisplay.GetClientRect( &rect ); 
 
	tmpDC.CreateCompatibleDC( pDC ); 
	pLayerInfo->m_bmp.CreateCompatibleBitmap( pDC, rect.Width(), rect.Height() ); 
 
	pOldBmp = tmpDC.SelectObject( &pLayerInfo->m_bmp ); 
 
	tmpDC.FillSolidRect( 0, 0, rect.Width(), rect.Height(), colBG ); 
 
	CPen pen; 
	CPen *pOldPen = NULL; 
	CBrush brush; 
	CBrush *pOldBrush = NULL; 
 
	pen.CreatePen( PS_SOLID, 1, colTrans ); 
	pOldPen = tmpDC.SelectObject( &pen ); 
 
	brush.CreateSolidBrush( colTrans ); 
	pOldBrush = tmpDC.SelectObject( &brush ); 
	 
	rect.DeflateRect( 2, 2 ); 
	tmpDC.Ellipse( &rect ); 
 
	// Create an ellipse rgn to use for the mouse hit test. 
	pLayerInfo->m_rgn.CreateEllipticRgn( rect.left, rect.top, rect.right, rect.bottom ); 
 
	m_layeredDisplay.CalculateCenterOffset( pLayerInfo ); 
 
	pLayerInfo->m_rgn.OffsetRgn( pLayerInfo->m_ptLocation.x, pLayerInfo->m_ptLocation.y ); 
	 
	// Cleanup. 
	tmpDC.SelectObject( pOldBrush ); 
	tmpDC.SelectObject( pOldPen ); 
	tmpDC.SelectObject( pOldBmp ); 
	 
	pen.DeleteObject(); 
	brush.DeleteObject(); 
 
	m_layeredDisplay.AddLayer( *pLayerInfo ); 
 
	delete pLayerInfo; 
 
	m_layeredDisplay.ReleaseDC( pDC ); 
	return; 
} 
 
void CLayeredBitmapCtrlDemoDlg::SetupComboBoxes() 
{ 
	// Setup the Layer1 Combo. 
	m_layer1Combo.AddString( _T("(None)") ); 
	m_layer1Combo.AddString( _T("Hurricane Aftermath") ); 
	m_layer1Combo.AddString( _T("Valley of Fire") ); 
 
	// Setup the Layer2 Combo. 
	m_layer2Combo.AddString( _T("(None)") ); 
	m_layer2Combo.AddString( _T("Chameleon Bob") ); 
	m_layer2Combo.AddString( _T("Code Project's Bob") ); 
	m_layer2Combo.AddString( _T("Show All") ); 
 
	// Setup the Layer3 Combo. 
	m_layer3Combo.AddString( _T("(None)") ); 
	m_layer3Combo.AddString( _T("Chainsaw") ); 
	m_layer3Combo.AddString( _T("Sunglasses") ); 
	m_layer3Combo.AddString( _T("Cowboy Hat") ); 
	m_layer3Combo.AddString( _T("Show All") ); 
 
	// Setup the Layer4 Combo. 
	m_layer4Combo.AddString( _T("(None)") ); 
	m_layer4Combo.AddString( _T("Grid") ); 
	m_layer4Combo.AddString( _T("Triangle") ); 
	m_layer4Combo.AddString( _T("Ellipse") ); 
	m_layer4Combo.AddString( _T("Cone") ); 
	m_layer4Combo.AddString( _T("Show All") ); 
 
	m_layer1Combo.SetCurSel( 0 ); 
	m_layer2Combo.SetCurSel( 0 ); 
	m_layer3Combo.SetCurSel( 0 ); 
	m_layer4Combo.SetCurSel( 0 ); 
 
	return; 
} 
 
 
BEGIN_MESSAGE_MAP(CLayeredBitmapCtrlDemoDlg, CDialog) 
	//{{AFX_MSG_MAP(CLayeredBitmapCtrlDemoDlg) 
	ON_WM_SYSCOMMAND() 
	ON_WM_PAINT() 
	ON_WM_QUERYDRAGICON() 
	ON_CBN_SELCHANGE(IDC_LAYER1_COMBO, OnSelchangeLayer1Combo) 
	ON_CBN_SELCHANGE(IDC_LAYER2_COMBO, OnSelchangeLayer2Combo) 
	ON_CBN_SELCHANGE(IDC_LAYER3_COMBO, OnSelchangeLayer3Combo) 
	ON_CBN_SELCHANGE(IDC_LAYER4_COMBO, OnSelchangeLayer4Combo) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CLayeredBitmapCtrlDemoDlg message handlers 
 
BOOL CLayeredBitmapCtrlDemoDlg::OnInitDialog() 
{ 
	CDialog::OnInitDialog(); 
 
	// Add "About..." menu item to system menu. 
 
	// IDM_ABOUTBOX must be in the system command range. 
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); 
	ASSERT(IDM_ABOUTBOX < 0xF000); 
 
	CMenu* pSysMenu = GetSystemMenu(FALSE); 
	if (pSysMenu != NULL) 
	{ 
		CString strAboutMenu; 
		strAboutMenu.LoadString(IDS_ABOUTBOX); 
		if (!strAboutMenu.IsEmpty()) 
		{ 
			pSysMenu->AppendMenu(MF_SEPARATOR); 
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); 
		} 
	} 
 
	SetIcon(m_hIcon, TRUE);			// Set big icon 
	SetIcon(m_hIcon, FALSE);		// Set small icon 
	 
	// Create all of the layers that will be used for the demo. 
	m_layeredDisplay.UseSysColor( true ); 
	SetupLayers(); 
	SetupComboBoxes(); 
 
	// Indicate that we want the tool tips to be displayed. 
	m_layeredDisplay.ShowToolTips( true ); 
 
	return TRUE;  // return TRUE  unless you set the focus to a control 
} 
 
void CLayeredBitmapCtrlDemoDlg::OnSysCommand(UINT nID, LPARAM lParam) 
{ 
	if ((nID & 0xFFF0) == IDM_ABOUTBOX) 
	{ 
		CAboutDlg dlgAbout; 
		dlgAbout.DoModal(); 
	} 
	else 
	{ 
		CDialog::OnSysCommand(nID, lParam); 
	} 
} 
 
// If you add a minimize button to your dialog, you will need the code below 
//  to draw the icon.  For MFC applications using the document/view model, 
//  this is automatically done for you by the framework. 
 
void CLayeredBitmapCtrlDemoDlg::OnPaint()  
{ 
	if (IsIconic()) 
	{ 
		CPaintDC dc(this); // device context for painting 
 
		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); 
 
		// Center icon in client rectangle 
		int cxIcon = GetSystemMetrics(SM_CXICON); 
		int cyIcon = GetSystemMetrics(SM_CYICON); 
		CRect rect; 
		GetClientRect(&rect); 
		int x = (rect.Width() - cxIcon + 1) / 2; 
		int y = (rect.Height() - cyIcon + 1) / 2; 
 
		// Draw the icon 
		dc.DrawIcon(x, y, m_hIcon); 
	} 
	else 
	{ 
		CDialog::OnPaint(); 
	} 
} 
 
HCURSOR CLayeredBitmapCtrlDemoDlg::OnQueryDragIcon() 
{ 
	return (HCURSOR) m_hIcon; 
} 
 
void CLayeredBitmapCtrlDemoDlg::OnSelchangeLayer1Combo()  
{ 
	int nSel = m_layer1Combo.GetCurSel(); 
 
	switch ( nSel ) 
	{ 
	case -1: 
	case 0: 
		// Hide all of the layer 1 bitmaps. 
		m_layeredDisplay.SetLayerVisibility( HURRICANE_AFTERMATH_LAYER, false ); 
		m_layeredDisplay.SetLayerVisibility( VALLEY_OF_FIRE_LAYER, false ); 
		break; 
 
	case 1: 
		m_layeredDisplay.SetLayerVisibility( HURRICANE_AFTERMATH_LAYER, true ); 
		m_layeredDisplay.SetLayerVisibility( VALLEY_OF_FIRE_LAYER, false ); 
		break; 
 
	case 2: 
		m_layeredDisplay.SetLayerVisibility( HURRICANE_AFTERMATH_LAYER, false ); 
		m_layeredDisplay.SetLayerVisibility( VALLEY_OF_FIRE_LAYER, true ); 
		break; 
	} 
 
	m_layeredDisplay.ShowVisibleLayers(); 
 
	return; 
} 
 
void CLayeredBitmapCtrlDemoDlg::OnSelchangeLayer2Combo()  
{ 
	int nSel = m_layer2Combo.GetCurSel(); 
 
	switch ( nSel ) 
	{ 
	case -1: 
	case 0: 
		// Hide all of the layer 2 bitmaps. 
		m_layeredDisplay.SetLayerVisibility( CHAMELEON_BOB_LAYER, false ); 
		m_layeredDisplay.SetLayerVisibility( CP_BOB_LAYER, false ); 
		break; 
 
	case 1: 
		m_layeredDisplay.SetLayerVisibility( CHAMELEON_BOB_LAYER, true ); 
		m_layeredDisplay.SetLayerVisibility( CP_BOB_LAYER, false ); 
		break; 
 
	case 2: 
		m_layeredDisplay.SetLayerVisibility( CHAMELEON_BOB_LAYER, false ); 
		m_layeredDisplay.SetLayerVisibility( CP_BOB_LAYER, true ); 
		break; 
 
	case 3: 
		m_layeredDisplay.SetLayerVisibility( CHAMELEON_BOB_LAYER, true ); 
		m_layeredDisplay.SetLayerVisibility( CP_BOB_LAYER, true ); 
		break; 
	} 
 
	m_layeredDisplay.ShowVisibleLayers(); 
 
	return; 
} 
 
void CLayeredBitmapCtrlDemoDlg::OnSelchangeLayer3Combo()  
{ 
	int nSel = m_layer3Combo.GetCurSel(); 
 
	switch ( nSel ) 
	{ 
	case -1: 
	case 0: 
		// Hide all of the layer 3 bitmaps. 
		m_layeredDisplay.SetLayerVisibility( CHAINSAW_LAYER, false ); 
		m_layeredDisplay.SetLayerVisibility( COWBOY_HAT_LAYER, false ); 
		m_layeredDisplay.SetLayerVisibility( SUNGLASSES_LAYER, false ); 
		break; 
 
	case 1: 
		m_layeredDisplay.SetLayerVisibility( CHAINSAW_LAYER, true ); 
		m_layeredDisplay.SetLayerVisibility( COWBOY_HAT_LAYER, false ); 
		m_layeredDisplay.SetLayerVisibility( SUNGLASSES_LAYER, false ); 
		break; 
 
	case 2: 
		m_layeredDisplay.SetLayerVisibility( CHAINSAW_LAYER, false ); 
		m_layeredDisplay.SetLayerVisibility( COWBOY_HAT_LAYER, false ); 
		m_layeredDisplay.SetLayerVisibility( SUNGLASSES_LAYER, true ); 
		break; 
 
	case 3: 
		m_layeredDisplay.SetLayerVisibility( CHAINSAW_LAYER, false ); 
		m_layeredDisplay.SetLayerVisibility( COWBOY_HAT_LAYER, true ); 
		m_layeredDisplay.SetLayerVisibility( SUNGLASSES_LAYER, false ); 
		break; 
 
	case 4: 
		m_layeredDisplay.SetLayerVisibility( CHAINSAW_LAYER, true ); 
		m_layeredDisplay.SetLayerVisibility( COWBOY_HAT_LAYER, true ); 
		m_layeredDisplay.SetLayerVisibility( SUNGLASSES_LAYER, true ); 
		break; 
	} 
 
	m_layeredDisplay.ShowVisibleLayers(); 
 
	return; 
} 
 
void CLayeredBitmapCtrlDemoDlg::OnSelchangeLayer4Combo()  
{ 
	int nSel = m_layer4Combo.GetCurSel(); 
 
	switch ( nSel ) 
	{ 
	case -1: 
	case 0: 
		// Hide all of the layer 4 bitmaps. 
		m_layeredDisplay.SetLayerVisibility( GRID_LAYER, false ); 
		m_layeredDisplay.SetLayerVisibility( TRIANGLE_LAYER, false ); 
		m_layeredDisplay.SetLayerVisibility( ELLIPSE_LAYER, false ); 
		break; 
 
	case 1: 
		m_layeredDisplay.SetLayerVisibility( GRID_LAYER, true ); 
		m_layeredDisplay.SetLayerVisibility( TRIANGLE_LAYER, false ); 
		m_layeredDisplay.SetLayerVisibility( ELLIPSE_LAYER, false ); 
		break; 
 
	case 2: 
		m_layeredDisplay.SetLayerVisibility( GRID_LAYER, false ); 
		m_layeredDisplay.SetLayerVisibility( TRIANGLE_LAYER, true ); 
		m_layeredDisplay.SetLayerVisibility( ELLIPSE_LAYER, false ); 
		break; 
 
	case 3: 
		m_layeredDisplay.SetLayerVisibility( GRID_LAYER, false ); 
		m_layeredDisplay.SetLayerVisibility( TRIANGLE_LAYER, false ); 
		m_layeredDisplay.SetLayerVisibility( ELLIPSE_LAYER, true ); 
		break; 
 
	case 4: 
		m_layeredDisplay.SetLayerVisibility( GRID_LAYER, false ); 
		m_layeredDisplay.SetLayerVisibility( TRIANGLE_LAYER, true ); 
		m_layeredDisplay.SetLayerVisibility( ELLIPSE_LAYER, true ); 
		break; 
 
	case 5: 
		m_layeredDisplay.SetLayerVisibility( GRID_LAYER, true ); 
		m_layeredDisplay.SetLayerVisibility( TRIANGLE_LAYER, true ); 
		m_layeredDisplay.SetLayerVisibility( ELLIPSE_LAYER, true ); 
		break; 
	} 
 
	m_layeredDisplay.ShowVisibleLayers(); 
 
	return; 
} 
 
 
void CLayeredBitmapCtrlDemoDlg::OnOK()  
{ 
	CDialog::OnOK(); 
	return; 
}