使用CPropertySheet和CPropertyPage實現
步驟:
1.新建一個MFC對話框工程, 工程名爲PageSwitch。
2.在資源中插入兩個對話框IDD_PAGE1、IDD_PAGE2,作爲兩個子頁:
分別爲兩對話框增加一個各自的類,分別爲CPage1和CPage2,基類選擇CPropertyPage。
3. 增加一個屬性頁類CSheetBase, 基類選擇CPropertySheet。
4. 在類CSheetBase中增加兩個成員變量m_page1,m_page2。
5.在類CSheetBase的構造函數中添加如下代碼,增加兩個頁:
CSheetBase::CSheetBase(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
{
AddPage(&m_page1);
AddPage(&m_page2);
}
CSheetBase::CSheetBase(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(pszCaption, pParentWnd, iSelectPage)
{
AddPage(&m_page1);
AddPage(&m_page2);
}
CSheetBase::~CSheetBase()
{
}
- 在工程文件“PageSwitch.cpp”中 #include “SheetBase.h”
- 在CPageSwitchApp類的InitInstance()函數中將原來聲明的對象CPageSwitchDlg dlg;
改爲CPageSwitchDlg dlg;
如下:
// CPageSwitchDlg dlg; //原來
CSheetBase dlg("SaleSystem");//
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
運行結果: