CPropertySheet and CPropertyPage implement tab paging

The wizard mode and Tab mode implemented by the control method are introduced in the previous section. Here, the previous functions are implemented by means of a property sheet and a property page. The property sheet is used to associate with the child page window, and the property sheet is used to associate with the parent window for managing the child page window.

1. First create a new dialog program, and insert 3 sub-windows (as paging windows), the IDs are: IDD_PAGE1, IDD_PAGE2, IDD_PAGE3, the attributes set by the three windows are mainly: Caption, style: child, ID, etc. Note: We do not need to insert the parent window, because the property sheet (CPropertySheet) is the paging management window encapsulated by MFC.

2. Associate a class for each of the three word dialog boxes, and the parent class of the associated class is: CPropertyPage.

class CPage1 : public CPropertyPage

class CPage2 : public CPropertyPage

class CPage3 : public CPropertyPage

3. Add virtual functions for the three dialog classes: virtual BOOL OnSetActive(); and add the following code: mainly to set the button situation in wizard mode.

BOOL CPage1::OnSetActive()
{
	CPropertySheet* ps = (CPropertySheet*)GetParent();

	//you can't call SetWizardButtons before you call DoModal.
	//Enables or disables the Back, Next, or Finish button in a wizard property sheet(向导方式)
	ps->SetWizardButtons(PSWIZB_NEXT);

	return CPropertyPage::OnSetActive();
}

BOOL CPage2::OnSetActive()
{
	CPropertySheet* ps = (CPropertySheet*)GetParent();

	//you can't call SetWizardButtons before you call DoModal.
	//Enables or disables the Back, Next, or Finish button in a wizard property sheet(向导方式)
	ps->SetWizardButtons(PSWIZB_BACK|PSWIZB_NEXT);

	return CPropertyPage::OnSetActive();
}

BOOL CPage3::OnSetActive()
{
	CPropertySheet* ps = (CPropertySheet*)GetParent();

	//you can't call SetWizardButtons before you call DoModal.
	//Enables or disables the Back, Next, or Finish button in a wizard property sheet(向导方式)
	ps->SetWizardButtons(PSWIZB_BACK|PSWIZB_FINISH);

	return CPropertyPage::OnSetActive();
}

4. Add two buttons to the main dialog box, Wizard and Tab, to test two kinds of paging: ID: IDC_WIZARD, IDC_PROPERTY, and add a click message response function for the button:

Wizard button response function:

void CPropertySheetAndPageDlg::OnBnClickedWizard()
{
	CPage1 p1;
	CPage2 p2;
	CPage3 p3;

	CPropertySheet ps;

	//Add pages to the property sheet in the left-to-right order you want them to appear.

	//When you add a property page using AddPage, the CPropertySheet is the parent of the CPropertyPage,
	//To gain access to the property sheet from the property page, call CWnd::GetParent.

	//Typically, you will call AddPage before calling DoModal or Create.
	ps.AddPage(&p1);
	ps.AddPage(&p2);
	ps.AddPage(&p3);

	ps.SetWizardMode();//Set to wizard mode, the default is Tab mode

	ps.DoModal();
}

Tab button response function:

void CPropertySheetAndPageDlg::OnBnClickedProperty()
{
	CPage1 p1;
	CPage2 p2;
	CPage3 p3;

	CPropertySheet ps;

	//Add pages to the property sheet in the left-to-right order you want them to appear.

	//When you add a property page using AddPage, the CPropertySheet is the parent of the CPropertyPage,
	//To gain access to the property sheet from the property page, call CWnd::GetParent.

	//Typically, you will call AddPage before calling DoModal or Create.
	ps.AddPage(&p1);
	ps.AddPage(&p2);
	ps.AddPage(&p3);

	//ps.SetWizardMode();//The default is Tab mode, use the default mode

	ps.DoModal();
}

Click the Wizard button:


Click the Tab button:


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326326952&siteId=291194637