ActiveX Controls: Adding Another Custom Property Page

OverviewHow Do IFAQSample

Occasionally, an ActiveX control will have more properties than can reasonably fit on one property page. In this case, you can add property pages to the ActiveX control to display these properties.

This article discusses adding new property pages to an ActiveX control that already has at least one property page. For more information on adding stock property pages (font, picture, or color), see the article ActiveX Controls: Using Stock Property Pages.

The following procedures use a sample ActiveX control framework created by ControlWizard. Therefore, the class names and identifiers are unique to this example.

For more information on using property pages in an ActiveX control, see the following articles:

Note   It is strongly recommended that new property pages adhere to the size standard for ActiveX control property pages. The stock picture and color property pages measure 250x62 dialog units (DLUs). The standard font property page is 250x110 DLUs. The default property page created by ControlWizard uses the 250x62 DLU standard.

To create another property page

  1. With your control project open, click the ResourceView tab in the Project Workspace window.

  2. On the Insert menu, click Resource.

  3. Double-click on the dialog resource type to create a new dialog resource.

  4. Delete the OK and Cancel button controls.

  5. Right-click on the dialog template to open the Dialog Properties box, and type a resource ID.

    This example uses IDD_PROPPAGE_NEWPAGE.

  6. Click the Styles tab. From the Style box, select Child. From the Border box, select None.

    Make sure that on the Styles tab the Titlebar option is not checked, and on the More Styles tab the Visible option is not checked.

  7. Click Save on the toolbar.

  8. Double-click the dialog template to open ClassWizard.

  9. In the Adding a Class dialog box, click OK.

  10. In the Class Name box in the New Class dialog box, type a name for the new dialog class.

    (In this example, CAddtlPropPage.)

  11. If you want to change file names, click Change. Type in the names for your implementation and header files, or accept the default names.

  12. In the Base Class box, select COlePropertyPage.

  13. In the Dialog ID box, select IDD_PROPPAGE_NEWPAGE.

  14. Click OK to create the class.

  15. Click OK to close ClassWizard.

To allow the control’s users access to this new property page, make the following changes to the control’s property page IDs macro section (located in the control implementation file):

BEGIN_PROPPAGEIDS(CSampleCtrl, 2)
    PROPPAGEID(CMyPropPage::guid)
   PROPPAGEID(CAddtlPropPage::guid)
...
END_PROPPAGEIDS(CSampleCtrl)

Note that you must increase the second parameter of the BEGIN_PROPPAGEIDS macro (the property page count) from 1 to 2.

You must also modify the control implementation file (.CPP) file to include the header (.H) file of the new property page class.

The next step involves creating two new string resources that will provide a type name and a caption for the new property page.

To add new string resources to a property page

  1. With your control project open, click the ResourceView tab in the Project Workspace window.

  2. Double-click the String Table folder, then double-click the existing string table resource to which you want to add a string.

    This opens the string table in a window.

  3. Select the blank line at the end of the string table and type the text, or caption, of the string: for example, “Additional Property Page.”

    This opens a String Properties page showing Caption and ID boxes. The Caption box contains the string you typed.

  4. In the ID box, select or type an ID for the string. Press Enter when you finish.

    For example purposes, we’ve used IDS_SAMPLE_ADDPAGE for the type name of the new property page.

  5. Repeat steps 3 and 4 using IDS_SAMPLE_ADDPPG_CAPTION for the ID and “Additional Property Page” for the caption.

  6. In the .CPP file of your new property page class (in this example, CAddtlPropPage) modify the CAddtlPropPage::CAddtlPropPageFactory::UpdateRegistry so that IDS_SAMPLE_ADDPAGE is passed by , as in the following example:

    BOOL CAddtlPropPage::CAddtlPropPageFactory::UpdateRegistry(BOOL bRegister)
    {
        if (bRegister)
            return AfxOleRegisterPropertyPageClass(AfxGetInstanceHandle(),
                         m_clsid, IDS_SAMPLE_ADDPAGE);
        else
            return AfxOleUnregisterClass(m_clsid, NULL);
    }
    
  7. Modify the constructor of CAddtlPropPage so that IDS_SAMPLE_ADDPPG_CAPTION is passed to the COlePropertyPage constructor, as follows:

    CAddtlPropPage::CAddtlPropPage() :
    // ****** Add your code below this line ********** //
         COlePropertyPage(IDD,  IDS_SAMPLE_ADDPPG_CAPTION)
    // ****** Add your code above this line ********** //
    {
        //{{AFX_DATA_INIT(CAddtlPropPage)
        // NOTE: ClassWizard will add member initialization here
        //    DO NOT EDIT what you see in these blocks of generated code !
        //}}AFX_DATA_INIT
    }
    

After you have made the necessary modifications rebuild your project and use Test Container to test the new property page. For more information on testing an ActiveX control with Test Container, see Test Container.