A property sheet is primarily a dialog box. As such it appears as a rectangular box with one or more tabs and buttons. In the Win32 library, a property page is created from a structure named PROPSHEETPAGE. To give you a connection to that structure, the CPropertyPage is equipped with a member variable named m_psh: PROPSHEETPAGE m_psp; In the Win32 library, a property sheet is created from a structure named PROPSHEETHEADER. This structure is represented in CPropertySheet class by a property named m_psh: CPropertySheet::m_psh; The m_psh gives access to the Win32 characteristics of a property sheet.
In its normal design, a property is usuqlly equipped with an OK and a cancel button. In some cases, it may have an Apply button. The functionality of the buttons of a property sheet are:
In reality, you are completely free to do what you want with the buttons on the property sheet:
Some of these issues we already know how to do. We already know that each control of an MFC application has an identifier. The buttons automatically added to a property sheet are identified as IDOK for the OK button and IDCANCEL for the Cancel button. If a property sheet has an Apply button, its identifier is ID_APPLY_NOW. If the property sheet has a Help button, the identifier of that button is IDHELP. To manipulate any of these buttons, you can call the CWnd::GetDlgItem() member function to get a handle to the desired button and do what you want with it. Here is an example code you can use to change the caption of a button, hide another button, or simply destroy another: BOOL CGeomeSheet::OnInitDialog() { BOOL bResult = CPropertySheet::OnInitDialog(); // TODO: Add your specialized code here // Change the caption of the OK button CButton *btnOK; btnOK = reinterpret_cast<CButton *>(GetDlgItem(IDOK)); btnOK->SetWindowText("Sumbit"); // Hide the Apply button CButton *btnApply; btnApply = reinterpret_cast<CButton *>(GetDlgItem(ID_APPLY_NOW)); btnApply->ShowWindow(FALSE); // Destroy the Help button CButton *btnHelp; btnHelp = reinterpret_cast<CButton *>(GetDlgItem(IDHELP)); btnHelp->DestroyWindow(); return bResult; } To add a button, declare a pointer to CButton and call its Create() member function to initialize. We have seen various examples of how to dynamically create a control. If you decide to dynamically create a button, some of the issues you would have to deal with here are the location and probably the size of the new button, which have little to do with programming but with geometry. Here is an example: BOOL CGeomeSheet::OnInitDialog() { BOOL bResult = CPropertySheet::OnInitDialog(); // TODO: Add your specialized code here // A pointer to button we will need CButton *btnApply; // We will need to location and dimensions of the Apply button CRect RectApply; // Get a handle to the Apply button btnApply = reinterpret_cast<CButton *>(GetDlgItem(ID_APPLY_NOW)); // Get the location and the dimensions of the Apply button btnApply->GetWindowRect(&RectApply); // Convert the location and dimensions to screen coordinates ScreenToClient(&RectApply); CButton *Whatever = new CButton; Whatever->Create("&Whatever", WS_CHILD | WS_VISIBLE, CRect(6, RectApply.top, 85, RectApply.top+RectApply.Height()), this, 0x188); return bResult; } Another issue you would deal with is each of the messages sent by your dynamic button. Manipulating one button has no influence on the other(s). For example, if you destroy the Cancel button, the OK button does not move to the right. You would have to reposition any button as you judge it necessary. We have already mentioned that, by standard and by design, the Apply button is disabled when the property sheet comes up. It is supposed to become enabled once the user gets any control "dirty"; that is, once a control, any control, is not the same as it was when the dialog box came up, the Apply button becomes available. To enable this control programmatically, once a control becomes dirty, call the CPropertyPage::SetModified(). Its syntax is: void SetModified(BOOL bChanged = TRUE); This member function is called by the control whose value you want to validate once the user has modified it. When the user clicks the OK button, the CPropertyPage::OnOK() event fires. By design, the changes made on the controls are acknowledged. The controls receive the status of "clean". The property sheet closes. When the user clicks the Cancel button, the CPropertyPage::OnCancel() event fires. By design, the changes made on the controls are dismissed. The controls values are kept as they were when the property sheet displayed as long as the user did not previously click Apply since the property sheet was opened. The property sheet closes. When the user clicks the Apply button, the CPropertyPage::OnApply() event fires. The changes that were made on the controls are acknowledged. The property sheet stays opened. Once again, these behaviors are the default suggested by
the standard but you can change them as you wish, although you should remain
with these suggestions because your users may be more familiar with them.
|
|
|||||||||
|