Add Code to the MFC ActiveX Control Starter Files

OverviewDetails

After using the MFC ActiveX ControlWizard to create an ActiveX (formerly OLE) Control project, you get a working starter program with whatever functionality you asked for when completing the steps in the ControlWizard.

This starter program includes all the files necessary to build the control, including source (.CPP) and header files (.H), resource files (.RC), a module-definition file (.DEF), a project file (.DSP), an object description language file (.ODL), and so on. These files are compatible with ClassWizard, and you can then use ClassWizard to define the control’s events, properties, and methods, some of which have been already implemented in MFC.

Your project files contain a large amount of built-in functionality. This functionality includes code to draw the control, serialize data, and define dispatch, event, and message maps that you expand later in the development cycle.

Your final step is to supply the application-specific source code and connect the control to a parent program by defining what messages and commands the starter files should respond to. If you don’t already have a parent application, you can create an ActiveX control container using AppWizard.

If you selected the comments option when creating your program, the newly created starter files will display comments in green when viewed in the project workspace. The comments indicate where to add your source code, and help define the class behaviors for your specific control.

Note   In the source code look for the comment: // TODO: , which is followed by an explanation of what to do. The comments also explain where not to edit specific blocks of code.

Example of where to add your code

CTestControl::CTestControl()
{
   InitializeIIDs(&IID_DTest, &IID_DTestEvents);
   //TODO: Initialize your control's instance data here.
}

CTestControl::~CTestControl()
{
   //TODO: Cleanup your control's instance data here.
}

What do you want to know more about?