An ActiveX control is implemented as an in-process server (typically a small object) that can be used in any OLE container. Note that the full functionality of an ActiveX control is available only when used within an OLE container designed to be aware of ActiveX controls. The following products and all their subsequent releases fully support ActiveX controls: Microsoft FoxPro 3.0, Microsoft Access 2.0, Microsoft Visual Basic 4.0, and OLE containers built with MFC in Visual C++ version 4.0. This container type, hereafter called a “control container,” can operate an ActiveX control by using the control’s properties and methods, and receives notifications from the ActiveX control in the form of events. The following figure demonstrates this interaction.
Interaction Between an ActiveX Control Container and a Windowed ActiveX Control
These articles describe creating ActiveX controls with MFC. For information on creating ActiveX controls with ActiveX Template Library (ATL), see the .
An ActiveX control uses several programmatic elements to interact efficiently with a control container and with the user. These are class , a set of event-firing functions, and a dispatch map.
Every ActiveX control object you develop inherits a powerful set of features from its MFC base class, COleControl. These features include in-place activation, and Automation logic. COleControl can provide the control object with the same functionality as an MFC window object, plus the ability to fire events. COleControl can also provide windowless controls, which rely on their container for help with some of the functionality a window provides (mouse capture, keyboard focus, scrolling), but offer much faster display.
Because the control class derives from COleControl, it inherits the capability to send, or “fire,” messages, called events, to the control container when certain conditions are met. These events are used to notify the control container when something important happens in the control. You can send additional information about an event to the control container by attaching parameters to the event. For more information about ActiveX control events, see the article ActiveX Controls: Events.
The final element is a dispatch map, which is used to expose a set of functions (called methods) and attributes (called properties) to the control user. Properties allow the control container or the control user to manipulate the control in various ways. The user can change the appearance of the control, change certain values of the control, or make requests of the control, such as accessing a specific piece of data that the control maintains. This interface is determined by the control developer and is defined using ClassWizard. For more information on ActiveX control methods and properties, see the articles ActiveX Controls: Methods and Properties.
When a control is used within a control container, it uses two mechanisms to communicate: it exposes properties and methods, and it fires events. The following figure demonstrates how these two mechanisms are implemented.
Communication Between an ActiveX Control Container and an ActiveX Control
The above figure also illustrates how other OLE interfaces (besides automation and events) are handled by controls.
All of a control’s communication with the container is performed by COleControl. To handle some of the container’s requests, COleControl will call member functions that are implemented in the control class. All methods and some properties are handled in this way. Your control’s class can also initiate communication with the container by calling member functions of COleControl. Events are fired in this manner.
A control has two basic states: active and inactive. Traditionally, these states were distinguished by whether or not the control had a window. An active control had a window; an inactive control did not. With the introduction of windowless activation, this distinction is no longer universal, but still applies to many controls.
When a windowless control goes active, it invokes mouse capture, keyboard focus, scrolling, and other window services from its container. You can also provide mouse interaction to inactive controls, as well as create controls that wait until activated to create a window.
When a control with a window becomes active, it is able to interact fully with the control container, the user, and Windows. The figure below demonstrates the paths of communication between the ActiveX control, the control container, and the operating system.
Windows Message Processing in a Windowed ActiveX Control (When Active)
The ability to serialize data, sometimes referred to as persistence, allows the control to write the value of its properties to persistent storage. Controls can then be re-created by reading the object’s state from the storage.
Note that a control is not responsible for obtaining access to the storage medium. Instead, the control’s container is responsible for providing the control with a storage medium to use at the appropriate times. For more information on serialization, see the article ActiveX Controls: Serializing. For information on optimizing serialization, see Optimizing persistence and initialization in ActiveX Controls: Optimization.
When you install Visual C++, the MFC ActiveX control classes and retail and debug ActiveX control run-time DLLs are automatically installed if ActiveX controls are selected in Setup (they are selected by default). For more information on Test Container, see the article Test Container.
By default, the ActiveX control classes and tools are installed in the following subdirectories under \Program Files\Microsoft Visual Studio:
Contains the Test Container files (TstCon32.exe, as well as its Help files) as well as RegSvr32.exe.
Contains the executable for the ActiveX ControlWizard (MFCTLWZ.AWX).
Contains the PSS help file (PSS.HLP) and the help file that discusses adding your own .HLP files to the development environment.
Contains the include files needed to develop ActiveX controls with MFC
Contains the source code for specific ActiveX control classes in MFC
Contains the libraries required to develop ActiveX controls with MFC
There are also samples for MFC ActiveX controls. Information about these samples is available online; search for sample.
The articles listed below explain the details of developing ActiveX controls using Visual C++ and the MFC ActiveX control classes. The articles are listed in functional categories.
Articles about the ActiveX control development process
- MFC ActiveX ControlWizard
- MFC ActiveX ControlWizard: Step-by-Step
- Prepare Your MFC ActiveX Control Program for Use (Register it)
- Add Code to the MFC ActiveX Control Starter Files
- Test Container
Articles about optimizing ActiveX controls
Articles about the events, methods, and properties of ActiveX controls
- ActiveX Controls: Events
- ActiveX Controls: Adding Stock Events to an ActiveX Control
- ActiveX Controls: Adding Custom Events to an ActiveX Control
- ActiveX Controls: Methods
- Methods: Adding Stock Methods to an ActiveX Control
- ActiveX Controls: Adding Custom Methods to an ActiveX Control
- ActiveX Controls: Returning Error Codes From a Method
- ActiveX Controls: Properties
- ActiveX Controls: Adding Stock Properties
- ActiveX Controls: Adding Custom Properties
- ActiveX Controls: Advanced Property Implementation
- ActiveX Controls: Accessing Ambient Properties
Articles about user-interface aspects of ActiveX controls
- ActiveX Controls: Painting an ActiveX Control
- ActiveX Controls: Property Pages
- ActiveX Controls: Adding Another Custom Property Page
- ActiveX Controls: Adding Context-Sensitive Help
- ActiveX Controls: Using Stock Property Pages
- ActiveX Controls: Using Fonts in an ActiveX control
- ActiveX Controls: Using Pictures in an ActiveX Control
- ActiveX Controls: Optimization
Articles about advanced topics of ActiveX controls
- ActiveX Controls: Advanced Topics
- ActiveX Controls: Distributing ActiveX Controls
- ActiveX Controls: Licensing an ActiveX Control
- ActiveX Controls: Localizing an ActiveX Control
- ActiveX Controls: Serializing
- ActiveX Controls: Subclassing a Windows Control
- ActiveX Controls: Optimization
Other articles regarding ActiveX controls
- ActiveX Controls: Using Data Binding in an ActiveX Control
- ActiveX Controls: Adding an ActiveX Control to an Existing CDK Project
- ActiveX Controls: VBX Control Migration
- ActiveX Controls: Converting a CDK Project to a Visual C++ Project
Articles about creating ActiveX controls with ActiveX Template Library (ATL)
See Also Test Container