Transferred from: http://www.jizhuomi.com/software/164.html
category of a Property Page dialog box
Property Pages dialog box presumably everyone is not unfamiliar, XP system desktop right-click Properties, Pop-up is the Property Page dialog box, it through the tabs to switch individual pages. In addition, the wizard dialog box that we used when we created the MFC project is also part of the property Pages dialog, which toggles the page by clicking the button "Next".
The Property Pages dialog box contains both the General Property Page dialog box and the wizard dialog box. It integrates multiple dialogs into one, and toggles the page by tabs or buttons .
Two Property Page dialog box related classes
When we use the Property Page dialog box, there are two main classes used: TheCPropertyPage class and the CPropertySheet class.
1.CPropertyPage class
The CPropertyPage class inherits from the CDialog class, which is used to process a single property page, so create a subclass that inherits from CPropertyPage for each property page. You can find detailed descriptions of the CPropertyPage class and its members in MSDN, VS2010. Here are some of the main member functions of the CPropertyPage class listed in MSDN.
(1) Constructors
Here are three constructors for the Cproperty class, the function prototypes are:
CPropertyPage (); Explicit CPropertyPage ( UINT nidtemplate, 0, sizeof( Propsheetpage) ); Explicit CPropertyPage ( lpctstr lpsztemplatename, 0, sizeof (propsheetpage) );
The first is a constructor without any arguments.
In the second constructor, the parameter nidtemplate is the dialog resource ID for the property page, the parameter nidcaption is the ID of the string resource used for the caption of the Property Page dialog Box tab, and if set to 0, the tab caption uses the title of the dialog resource for that property page.
In the third constructor, the parameter lpsztemplatename is the name string of the dialog resource for the property page, and cannot be null. Parameter Nidcaption Ibid.
(2) Canceltoclose () function
After you have made an unrecoverable operation on the properties page of the Modal Property Page dialog box, use the Canceltoclose () function to change the OK button to the Close button and disable the Cancel button. The function prototypes are:
void Canceltoclose ();
(3) setmodified () function
Call this function to activate or disable the "Apply" button, the function prototype is:
void SetModified (BOOL bchanged = TRUE);
(4) Can overload function
The CPropertyPage class provides a number of message-handling functions to respond to various messages in the Property Page dialog box. By overloading these message handlers, we can customize the handling of the Property Page dialog box operations.
The message handler functions that can be overloaded include:
onapply: Handling the message clicked on the "Apply" button of the property page
OnCancel: Processing the message clicked on the "Cancel" button of the property page
onkillactive: Handles the message that the property page is currently active, often used for data validation
OnOK: Processing the "OK" button of the property page, the "Apply" button, or the message clicked by the "Close" button
onquerycancel: Processing a message from the "Cancel" button of a property page before it is clicked
onreset: Handling the message clicked on the Reset button of the property page
onsetactive: Processing a property page message that is being toggled to the currently active page
Onwizardback: Handles the message that the "Back" button of the property page clicked, only valid in the wizard dialog box
Onwizardfinish: Handles the message clicked on the "Finish" button of the property page, only valid in the wizard dialog box
Onwizardnext: The message that handles the "next" button of the property page is clicked, only valid in the wizard dialog box
2.CPropertySheet class
the CPropertySheet class inherits from the CWnd class, which is the property sheet class that is responsible for loading, opening, or deleting property pages, and you can toggle property pages in the Property Pages dialog box. It is similar to a dialog box and also has both modal and non-modal types. Some of the member functions of the CPropertySheet class are explained below.
(1) Constructors
The three constructors for the CPropertySheet class are still listed here:
CPropertySheet (); Explicit CPropertySheet ( UINT nidcaption, CWnd* pParentWnd = NULL, 0 ); Explicit CPropertySheet ( lpctstr pszcaption, CWnd* pParentWnd = NULL, 0 );
Parameter nidcaption: The ID of the string resource for the caption.
Parameter pParentWnd: The parent window of the Property Pages dialog box, if set to null, the parent window is the main window of the application.
Parameter iselectpage: The initial state, the index of the Active property page, defaults to the first property page added to the property sheet.
Parameter pszcaption: Title string.
(2) Getactiveindex () function
Gets the index of the currently active property page. The function prototypes are:
int Getactiveindex () const;
Return value: The index of the currently active property page.
(3) GetActivePage () function
Gets the currently active property Page object. The function prototypes are:
cpropertypage* getactivepage () const;
Return value: A pointer to the currently active property Page object.
(4) GetPage () function
Gets a property Page object. The function prototypes are:
cpropertypage* getpage (int npage) const;
Parameter npage: The index of the target property page.
Return value: A pointer to the target property Page object.
(5) Getpagecount () function
Gets the number of property pages. The function prototypes are:
int getpagecount () const;
Return value: The number of property pages.
(6) Getpageindex () function
Gets the index of a property page in the Property Pages dialog box. The function prototypes are:
int Getpageindex (cpropertypage* pPage);
Parameter ppage: A pointer to the property Page object to get the index.
Return value: The index of the property Page object in the Property Pages dialog box.
(7) Setactivepage () function
Sets a property page as the Active property page. The function prototypes are:
BOOL Setactivepage (
int Npage
);
BOOL Setactivepage (
cpropertypage* PPage
);
Parameter npage: The index to set as the Active property page.
Parameter ppage: The object pointer to be set as the Active property page.
(8) SetWizardButtons () function
When you enable or disable the back, Next, or Finish buttons on the wizard dialog box, you should call this function before calling DoModal. The function prototypes are:
void SetWizardButtons (
DWORD DwFlags
);
Parameter dwflags: Sets the appearance and feature properties of the wizard button. Can be a combination of the following values:
Pswizb_back enable the Back button and disable the Back button if this value is not included.
Pswizb_next enable the "Next" button and disable the "Next" button if this value is not included.
Pswizb_finish enable the "FINISH" button.
Pswizb_disabledfinish Displays the disabled "Finish" button.
(9) SetWizardMode () function
Setting the Property Pages dialog box for the wizard dialog mode, you should call this function before calling DoModal. The function prototypes are:
void SetWizardMode ();
(Ten) Settitle () function
Sets the caption of the Properties dialog box. The function prototypes are:
void Settitle (
LPCTSTR LpszText,
UINT Nstyle = 0
);
Parameter lpsztext: Title string.
Parameter nstyle: Specifies the style of the property sheet title. should be 0 or psh_proptitle. If set to Psh_proptitle, the word "Properties" appears after the specified title. For example, this invocation of Settitle ("simple", psh_proptitle) causes the property sheet to be titled "Simple Properties".
(one) AddPage () function
Adds a new property page for the Properties dialog box. The function prototypes are:
void AddPage (
CPropertyPage *ppage
);
Parameter ppage: The object pointer to the new property page to add.
() Pressbutton () function
Simulates pressing a specified button. The function prototypes are:
void Pressbutton (
int Nbutton
);
Parameter Nbutton: To simulate a pressed button, it can be one of the following values:
Psbtn_back Select the "Back" button.
Psbtn_next Select the "NEXT" button.
Psbtn_finish Select the "FINISH" button.
PSBTN_OK Select the "OK" button.
Psbtn_applynow Select the "Apply" button.
Psbtn_cancel Select the "CANCEL" button.
PSBTN_HELP Select the Help button.
() Removepage () function
Deletes a property page. The function prototypes are:
void Removepage (
CPropertyPage *ppage
);
void Removepage (
int Npage
);
Parameter ppage: The object pointer to the property page to delete.
Parameter npage: The index of the property page to delete.
The Properties dialog box and the related two classes are introduced here, primarily for the subsequent use of the Property Page dialog box.
VS2010-MFC (dialog box: Description of the Property Pages dialog box and related classes)