January 21, 2021
Hot Topics:

Exploring RapiDemo Initializations

  • By Nancy Nicolaisen
  • Send Email »
  • More Articles »

The RapiDemo application relies on the MFC implementation of the Property Sheet Control. This type of control is really nothing more than a stack of dialog boxes, surmounted by a control that looks like the tabs in an index file, recipe box, or your junior high school binder. The function of the property sheet control is to arbitrate "page changing" behavior. When a user clicks on a tab, the property sheet control brings the corresponding dialog to the top of the z-order.

This means that each "page" of the property sheet must have a dialog resource from which the sheet can build a view. You don't have to worry about making the dialog templates exactly the same size because the property sheet control is assembled based on the size of the largest constituent page. However, the styles of the dialog resources are important. Set these styles for property page dialog resources, using the File.Properties dialog:

  • On the Styles Tab, set Style to "Child", Border to "Thin", check the "Title Bar " checkbox, and clear other checkboxes.
  • On the More Styles tab, check the "Disabled" checkbox.

Now, let's dissect the code for the application-specific behaviors of the classes that make up RapiDemo.

The Application Object, RapiDemoApp

The code for the class that implements the application object, CRapiDemoApp, is generated for us, for the most part. We make a few small modifications to the RapiDemoApp.cpp file. First, we add the header file for the class that implements the property sheet. (If you forget to do this, you'll get compiler error messages naming the CAllPages class members as undefined symbols.)

#include "AllPages.h"

We also modify the InitInstance() member, where the property sheet object is constructed, initialized, and launched as a modal dialog.

// The one and only CRapiDemoApp object

CRapiDemoApp theApp;

// CRapiDemoApp initialization

BOOL CRapiDemoApp::InitInstance()


   CAllPages   AllPages( "RapiDemo", NULL, 0 );
   m_pMainWnd = &AllPages;

   return FALSE;

We declare and initialize an object of the CAllPages class. This class implements the property sheet control, and is derived from CPropertySheet. CPropertySheet has three constructors. The one we use to construct the CAllPages object takes the following arguments: a character string specifying the caption for the property sheet control, the handle to the control's parent window, and the index of the property page that is initially visible. A property page's index is determined by the order in which it was added to the control. Passing a NULL parent window handle sets the application's main window as parent of the property sheet control.

Next, we call the AllPages AddPropPages() member function, which adds the individual pages to the property sheet control. Calling the DoModal() member launches the property sheet control, making it visible when the application opens.

Construction and Initializing The Property Sheet Object, AllPages

The CAllPages class contains the code that implements the property sheet control. First, we make modifications to both the class header file, AllPages.h. For starters, we add some include files:

#include "WalkReg.h"                 // "Walk Registry Tree" page's
                                     // class header
#include "SystemStatusPage.h"        // "System Status" page's class
                                     // header
#include "RemoteFileAccessPage.h"    // "Remote File Access" page's
                                     // class header

#include <rapi.h>

The first three #include files are for the classes that implement the behavior of the individual pages in the property sheet control. The last one is the RAPI header and is needed in any source file that calls RAPI functions. (If you forget to add this include file, RAPI function calls and structures will come up as undeclared symbols when you build.)

// Implementation
   CRemoteFileAccessPage m_RemoteFileAccessPage;
   CSystemStatusPage     m_SystemStatusPage;
   CWalkReg              m_WalkRegPage;
   void AddPropPages();
   virtual ~CAllPages();
   HICON m_hIcon;

We add three member variables, one for each property page of the property sheet control. These members are typed according to the class that implements the behavior for its specific page. We also add a function prototype for the AddPropPages(); member.

Next, we make some additions to the AllPages.cpp file, adding the AddPropPages() member function.

// CAllPages message handlers

void CAllPages::AddPropPages()
   m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
   m_psh.dwFlags |= PSP_USEHICON;
   m_psh.hIcon    = m_hIcon;
   m_psh.dwFlags |= PSH_NOAPPLYNOW;    // Lose the Apply Now button
   m_psh.dwFlags &= ~PSH_HASHELP;      // Lose the Help button



The first part of this function manipulates the PROPSHEETHEADER structure, a base class data member that defines the appearance and behavior of the property sheet control. It's a fairly large structure that allows great flexibility in the creation of the property sheet control. The m_psh base class data member is a pointer to this structure.

The next three lines add property page objects to the property sheet control. The pages' indices are the reverse of the order in which they were added. Put another way, in the example shown above, the leftmost tab of this property sheet control will be the "System Status" page, the "Walk The Registry Tree" tab will be in the middle, and the rightmost tab will be for the "Remote File Access" page.

Page 1 of 3

This article was originally published on June 24, 2004

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date