CPropertySheet: Adding additional buttons


I need to know that apart from the default Ok, Apply & Cancel buttons ( and  an optional Help Button ) Can we have our own custom buttons on the property sheet created using MFC's CPropertySheet class?

If I add that button on the property page then i have to keep the same button  in all the Property Pages of that property sheet, which is not desirable.

Further, How to call the OnApply of the other pages within a Property sheet explicitly if Apply Button of a particular page is clicked?

Making more general, if a class A is containing two other class variables B & C then from a member function of B can we call any of the member functions of C?

Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

shaigConnect With a Mentor Commented:
To make things simple:
Yes! You can place any button you want on the property sheet, the only catch about it is that you will need to move the button yourself (if the sheet is resizable).
It will be somewhat inconvinient to create this button, since you can't use the resource editor for this (the sheet obvously doesn't have a dialog resource), so you will have to use the buttons Create function (say in the sheets OnInitDialog function).
 this code snippet is to display/enable Help button  in Property sheet .

Let us say CSheet is the PropertySheet class

Wherever U are doing DoModal() for the Property sheet add the following code:
This code enables the standard Help button
      CSheet dlg("Add Help");
      dlg.m_psh.dwFlags |= PSH_HASHELP ;

In the constructor of the property sheet class

CSheet::CSheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(pszCaption, pParentWnd, iSelectPage)
      m_page1.m_psp.dwFlags |=PSP_HASHELP ;
             m_page2.m_psp.dwFlags |=PSP_HASHELP ;

This will enable the help button . The Help button is not displayed in the Property page but is displayed in the property

Map OnCommand() function in the CSheet( property sheet) class
Add the following code there
BOOL CSheet::OnCommand(WPARAM wParam, LPARAM lParam)
UINT nID = LOWORD(wParam);
if(nID == IDHELP)
       OnHelpDisplay(wParam, lParam);
 return CPropertySheet::OnCommand(wParam, lParam);

where OnHelpDisplay() is a user defined message

In this functiomn U can display Help by calling ::WinHelp

U can have custom buttons in addition to the standard ones
The following codde displays that

In the OnInitdialog of the PropertySheet Class add the following
BOOL CSheet::OnInitDialog()
BOOL bResult = CPropertySheet::OnInitDialog();
 CRect rectWnd,rect;
  SetWindowPos(NULL, 0, 0,
             rectWnd.Width() + 100,
   m_button.CreateEx( WS_EX_CLIENTEDGE, _T("Button"), "New",
                       WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER, rectWnd.Width(), 20, 80, 24, m_hWnd, 0, 0 );

      return bResult;
where m_Button is of type CButton

Yes U can  call the member functions of C from member function of B by having an object of Class c in Class B.
All Courses

From novice to tech pro — start learning today.