Click here to Skip to main content
12,758,462 members (29,680 online)
Click here to Skip to main content

Stats

306.5K views
5K downloads
130 bookmarked
Posted 12 Sep 2003

WTL for MFC Programmers, Part VIII - Property Sheets and Wizards

, 13 Jan 2006
A guide to creating property sheets and wizards in WTL
// 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), &gt, 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();
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Michael Dunn
Software Developer (Senior) VMware
United States United States
Michael lives in sunny Mountain View, California. He started programming with an Apple //e in 4th grade, graduated from UCLA with a math degree in 1994, and immediately landed a job as a QA engineer at Symantec, working on the Norton AntiVirus team. He pretty much taught himself Windows and MFC programming, and in 1999 he designed and coded a new interface for Norton AntiVirus 2000.
Mike has been a a developer at Napster and at his own lil' startup, Zabersoft, a development company he co-founded with offices in Los Angeles and Odense, Denmark. Mike is now a senior engineer at VMware.

He also enjoys his hobbies of playing pinball, bike riding, photography, and Domion on Friday nights (current favorite combo: Village + double Pirate Ship). He would get his own snooker table too if they weren't so darn big! He is also sad that he's forgotten the languages he's studied: French, Mandarin Chinese, and Japanese.

Mike was a VC MVP from 2005 to 2009.

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170217.1 | Last Updated 13 Jan 2006
Article Copyright 2003 by Michael Dunn
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid