![]() |
Property Sheet Buttons |
There are two types of property sheets: modal and modeless. A modeless property sheet does not display buttons. A modal property sheet is equipped with command buttons that allow the user to make a decision after selecting items on the pages or changing the values of the page’s controls. By default, after creating a property sheet, it is equipped with the OK, the Cancel, and the Apply buttons. By design, the CPropertySheet class, which is the implementer of the property sheet, has a member variable called m_psh. This member represents the PROPSHEETHEADER structure, which is the Win32 implementer of a property sheet. One way you can use the m_psh member variable is to hide the Apply button if you do not need it in your application. Otherwise, this button is available by default on a property sheet. Here is an example from the Components dialog box of Microsoft Visual Basic:
In this classic design, the functionality of the buttons is commonly standardized:
Once the Apply button is enabled, the user can use it. If the user clicks the Apply button, 1) any
change(s) made on the control(s) is(are) sent to the object that called the property sheet, 2) the Apply button becomes disabled again, 3) the dialog box remains opened.
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, IDCANCEL for the Cancel button, ID_APPLY_NOW for the Apply button, and IDHELP for the Help button. Therefore, to manipulate any of these buttons, you can call the CWnd::GetDlgItem() method 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() method 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;
CFont ctlFont;
ctlFont.CreateStockObject(DEFAULT_GUI_FONT);
Whatever->SetFont(&ctlFont, FALSE);
}
Another issue you would deal with is each of the messages sent by your dynamic button. void SetModified(BOOL bChanged = TRUE); This method is called by the control whose value you want to validate once the user has modified it.
|
|
|
| Copyright © 2003-2007 FunctionX, Inc. |
|
|