ActiveX property page can be added in two situations:
- Add inherent property page
- Add custom property page
1. Add an inherent property page
MFC provides three inherent property pages for ActiveX Controls: clsid_ccolorproppage, clsid_cfontproppage, and clsid_cpictureproppage. They represent three property pages: color, Font, and image. To add them to the control, you only need to add their IDs to the initialization code of the ID array on the control property page. For
Example
BEGIN_PROPPAGEIDS(CMyAxOptCtrl, 4) PROPPAGEID(CMyAxOptPropPage::guid) PROPPAGEID(CLSID_CFontPropPage) PROPPAGEID(CLSID_CColorPropPage) PROPPAGEID(CLSID_CPicturePropPage)END_PROPPAGEIDS(CMyAxOptCtrl)
Note: The number 4 in begin_proppageids indicates the number of attribute pages. When you add an attribute page, you must update it in time.
PS: if the control's inherent property page cannot be accessed, it may be because the mfc dll (mfcxx. dll) is not correctly registered by the current operating system.
2. Add a custom property page
First, add a new property page resource to your project.
- Open resource view
- Right-click resource view and choose add resource from the shortcut menu.
- Expand the dialog node and select idd_ole_proppage_small.
- Click new to add resources to your project.
- Go to the new property page
- Change its ID
- Click Save on the toolbar.
Next, create a class that is associated with this property page. The method is skipped. Note that the base class is "colepropertypage. Assume that the class name is cyourownppage.
To allow the control user to access the newly added property page, you also need to add the corresponding statement in the initialization code of the ID array of the control property page, such:
BEGIN_PROPPAGEIDS(CMyAxUICtrl, 2) PROPPAGEID(CMyAxUIPropPage::guid) PROPPAGEID(CYourOwnPPage::guid)END_PROPPAGEIDS(CMyAxUICtrl)
Note: Increase the count in the in_proppageids macro. Of course, do not forget to include the header file.
Finally, add a new string resource to the attribute page. Here, we need two string resources. The adding method is omitted and the two resource IDs are ids_sample_addpage and ids_sample_addppg_caption. Modify the second code in the cyourownppage class.
1,
BOOL CAddtlPropPage::CAddtlPropPageFactory::UpdateRegistry(BOOL bRegister){ if (bRegister) return AfxOleRegisterPropertyPageClass(AfxGetInstanceHandle(), m_clsid, IDS_SAMPLE_ADDPAGE); else return AfxOleUnregisterClass(m_clsid, NULL);}
2,
CAddtlPropPage::CAddtlPropPage() : COlePropertyPage(IDD, IDS_SAMPLE_ADDPPG_CAPTION){}
Now, the property page is added