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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
 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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.