How to create a property sheet using the CPropertyPage class and the CPropertySheet class

Source: Internet
Author: User

The CPropertyPage class is a property page class, which is equivalent to a dialog box for each class. It inherits from the CDialog class.

The CPropertySheet class is a property sheet class that has multiple property pages. It inherits from the CWnd class

The Create attribute table steps are as follows:
This is simply an example of a property sheet with only two property pages.

1. Create a main dialog box.
:

2. Create a menu in the resource
:

3. Add an event handler to the menu
:

4. Add a menu to the main dialog box properties
:

5. Add two dialog boxes as a property page
:

It's important to note that the dialog box is best set to thin (MSDN), but I don't feel the problem when I'm testing ...
There is also a dialog box title that is the title of the property page, and below, continue to look down on the line.

6. Add a class to two dialog boxes (property pages), respectively
Need special attention! The selection of the base class must be CPropertyPage.
:

7. Add a property sheet class of your own
It is particularly important to note that this class inherits from the CPropertySheet
The class added here is not a simple C + + class, but an MFC Class!
:

8. Add two property page variables to the CMyPropertySheet header file
:

9. Add two property pages to the property sheet in CMyPropertySheet two constructors
:

10. In this step, the property sheet has been created, let's open it and see how it works.
We open a property sheet through a menu. So you have to fill in the code in the menu event handler.

The code is as follows:

void CMFCCPropertySheetDlg::OnProperty(){    //第一个参数是属性表的标题    CMyPropertySheet mypsheet(TEXT("属性表"));    //打开模态对话框,就是属性表    mypsheet.DoModal();}

Effect:

The "OK", "Cancel" and "Apply" help buttons above are automatically generated, and the base class has already implemented their code. But the "Apply" button needs to write the appropriate event handling, as described below.

11. Next, implement the control's functionality in the respective property pages.
Click on the Property Page 1 button to pop up a message box.

:

12. Make the App button active.
You can make it work when you change the contents of the property page.
Here's how:
Add radio button Event handling
The code is as follows:

void CPage1::OnBnClickedRadio1(){    SetModified(TRUE);    //其它代码    //......}

For convenience, multiple buttons respond to the same message

ON_BN_CLICKED(IDC_RADIO1, &CPage1::OnBnClickedRadio1)    ON_BN_CLICKED(IDC_RADIO2, &CPage1::OnBnClickedRadio1)    ON_BN_CLICKED(IDC_RADIO3, &CPage1::OnBnClickedRadio1)

13. Responding to App button messages
There is a onapply function in the CPropertyPage class. Its ID is id_apply_now, when the message is mapped, the ID cannot be changed, and the function name can be one of its own.

First, the message map

ON_BN_CLICKED(ID_APPLY_NOWCMyPropertySheet::OnApply)

And then declare it in the header file.

void OnApply();

Finally write the function body realization

void CMyPropertySheet::OnApply(){    AfxMessageBox(TEXT("点击了应用按钮"));    m_Page1.SetModified(FALSE//使应用按钮无效    m_Page2.SetModified(FALSE);    //按下应用的时候更新页面的数据    GetActivePage()->UpdateData(TRUE);    //接下来可以SendMessage给其它函数来执行更新后的操作}

How to create a property sheet using the CPropertyPage class and the CPropertySheet class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.