1.打开资源视图(ResourceView)的对话框目录(Dialog),在“Dialog”上右键、选择insert,在弹出的对话框中选择Dialog下的IDD_PROPPAGE_LARGE、点击new,这样我们就创建了一个新的属性页。按照此方法我们再创建两个属性页。
2.为属性页添加相应的类,添加类,继承CPropertyPage,名称分别为MyPage1,MyPage2,MyPage3
3.添加一个类,继承CPropertySheet,名称为MyProSheet
4.为MyProSheet类添加三个成员:
MyPage1 m_page1;
MyPage2 m_page2;
MyPage3 m_page3
然后在MyProSheet的构造函数中 添加三个页:MyProSheet::MyProSheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(pszCaption, pParentWnd, iSelectPage)
{
this->AddPage(&m_prop1);this->AddPage(&m_prop2);this->AddPage(&m_prop3);
}
然后重写每个Page的OnSetActive函数: virtual BOOL ProPage1::OnSetActive();
BOOL ProPage1::OnSetActive(){
((CPropertySheet*)this->GetParent())->SetWizardButtons(PSWIZB_NEXT);
return true;
}
完毕。 相关代码:
Page1:
#pragma once
// ProPage1 dialog
class ProPage1 : public CPropertyPage
{
DECLARE_DYNAMIC(ProPage1)
public:
ProPage1();
virtual ~ProPage1();
virtual BOOL ProPage1::OnSetActive();
// Dialog Data
enum { IDD = IDD_PROPPAGE_LARGE };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
DECLARE_MESSAGE_MAP()
};
#include "stdafx.h"
#include "MfcPropTest.h"
#include "ProPage1.h"
// ProPage1 dialog
IMPLEMENT_DYNAMIC(ProPage1, CPropertyPage)
ProPage1::ProPage1()
: CPropertyPage(ProPage1::IDD)
{
}
BOOL ProPage1::OnSetActive(){
((CPropertySheet*)this->GetParent())->SetWizardButtons(PSWIZB_NEXT);
return true;
}
ProPage1::~ProPage1()
{
}
void ProPage1::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(ProPage1, CPropertyPage)
END_MESSAGE_MAP()
// ProPage1 message handlers
Page2#pragma once
// ProPage2 dialog
class ProPage2 : public CPropertyPage
{
DECLARE_DYNAMIC(ProPage2)
public:
ProPage2();
virtual ~ProPage2();
virtual BOOL ProPage2::OnSetActive();
// Dialog Data
enum { IDD = IDD_PROPPAGE_LARGE1 };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
DECLARE_MESSAGE_MAP()
};
#include "stdafx.h"
#include "MfcPropTest.h"
#include "ProPage2.h"
// ProPage2 dialog
IMPLEMENT_DYNAMIC(ProPage2, CPropertyPage)
ProPage2::ProPage2()
: CPropertyPage(ProPage2::IDD)
{
}
BOOL ProPage2::OnSetActive(){
((CPropertySheet*)this->GetParent())->SetWizardButtons(PSWIZB_NEXT|PSWIZB_BACK);
return true;
}
ProPage2::~ProPage2()
{
}
void ProPage2::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(ProPage2, CPropertyPage)
END_MESSAGE_MAP()
// ProPage2 message handlers
Page3: #pragma once
// ProPage3 dialog
class ProPage3 : public CPropertyPage
{
DECLARE_DYNAMIC(ProPage3)
public:
ProPage3();
virtual ~ProPage3();
virtual BOOL ProPage3::OnSetActive();
// Dialog Data
enum { IDD = IDD_PROPPAGE_LARGE2 };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
DECLARE_MESSAGE_MAP()
};
#include "stdafx.h"
#include "MfcPropTest.h"
#include "ProPage3.h"
// ProPage3 dialog
IMPLEMENT_DYNAMIC(ProPage3, CPropertyPage)
ProPage3::ProPage3()
: CPropertyPage(ProPage3::IDD)
{
}
ProPage3::~ProPage3()
{
}
BOOL ProPage3::OnSetActive(){
((CPropertySheet*)this->GetParent())->SetWizardButtons(PSWIZB_BACK);
return true;
}
void ProPage3::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(ProPage3, CPropertyPage)
END_MESSAGE_MAP()
// ProPage3 message handlers
ProSheet: #pragma once
#include "ProPage1.h"
#include "ProPage2.h"
#include "ProPage3.h"
// MyProSheet
class MyProSheet : public CPropertySheet
{
DECLARE_DYNAMIC(MyProSheet)
public:
MyProSheet(UINT nIDCaption, CWnd* pParentWnd = NULL, UINT iSelectPage = 0);
MyProSheet(LPCTSTR pszCaption, CWnd* pParentWnd = NULL, UINT iSelectPage = 0);
virtual ~MyProSheet();
members
ProPage1 m_prop1;
ProPage2 m_prop2;
ProPage3 m_prop3;
protected:
DECLARE_MESSAGE_MAP()
};
// MyProSheet.cpp : implementation file
//
#include "stdafx.h"
#include "MfcPropTest.h"
#include "MyProSheet.h"
// MyProSheet
IMPLEMENT_DYNAMIC(MyProSheet, CPropertySheet)
MyProSheet::MyProSheet(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
{
}
MyProSheet::MyProSheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(pszCaption, pParentWnd, iSelectPage)
{
this->AddPage(&m_prop1);this->AddPage(&m_prop2);this->AddPage(&m_prop3);
}
MyProSheet::~MyProSheet()
{
}
BEGIN_MESSAGE_MAP(MyProSheet, CPropertySheet)
END_MESSAGE_MAP()
// MyProSheet message handlers