ActiveX Control Containers: Manually Enabling ActiveX Control Containment

If you did not enable ActiveX control support when you used the MFC Application Wizard to generate your application, you will have to add this support manually. This article describes the process for manually adding ActiveX control containment to an existing OLE container application. If you know in advance that you want ActiveX control support in your OLE container, see the article Creating an MFC ActiveX Control Container.

Note

This article uses a dialog-based ActiveX control container project named Container and an embedded control named Circ as examples in the procedures and code.

To support ActiveX controls, you must add one line of code to two of your project's files.

  • Modify your main dialog's InitInstance function (found in CONTAINER.CPP) by the MFC Application Wizard making a call to AfxEnableControlContainer, as in the following example:

    // COleContainerApp initialization
    BOOL COleContainerApp::InitInstance()
    {
        AfxEnableControlContainer();
    
    
    ...
    
    
    }
    
  • Add the following to your project's STDAFX.H header file:

    #include <afxdisp.h>        // MFC Automation classes
    

After you have completed these steps, rebuild your project by clicking Build on the Build menu.

See Also

Concepts

ActiveX Control Containers