Wednesday, August 27, 2008

Disable Help Button on Selected PropertyPages

This is a very common problem most programmers encounter while developing Property Wizard in VC++ (MFC). When we add Help button to the wizard, it gets enabled on all the property pages by default. Sometimes this is not what we desire. Let us take an example to illustrate it more.

I am developing a wizard from the product on which my team is working. This wizard consists of following pages:
  • Start Page
  • Select Class
  • Select Students
  • Initiate job of retrieving information of these students and storing them in database.
  • Finish page
For these pages, I have created following CPropertyPage classes:
  • CPropertyStart
  • CPropertySelectClass
  • CPropertySelectStudents
  • CPropertyRetrieve
  • CPropertyFinish
The next task is to add these CPropertyPage objects to the CPropertySheet wizard in the constructor. I have created following CPropertySheet class for this purpose.
  • CPropertyStudentWizard

In this class, I have created following objects for each property page.

  • CPropertyStart m_propStart;
  • CPropertySelectClass m_propSelectClass;
  • CPropertySelectStudents m_propSelectStudents;
  • CPropertyRetrieve m_propRetrieve;
  • CPropertyFinish m_propFinish;

I also have to create chm help for all pages except finish page. So I would like to disable Help button on this page only. This is how I can achieve this.

CPropertyStudentWizard::CPropertyStudentWizard (UINT nIDCaption,CWnd* pParentWnd, UINT iSelectPage) :CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
{

SetWizardMode();
m_propFinish.m_psp.dwFlags &= ~PSP_HASHELP;

AddPage( & m_propStart);
AddPage( & m_propSelectClass);
AddPage( & m_propSelectStudents);
AddPage( & m_propRetrieve);
AddPage( & m_propFinish);
}