Share via


Using ActiveX Controls

The topics in this section present an overview of using ActiveX controls.

An ActiveX control is a COM component that supports standard interfaces relating to persistence, connection points, and hosting. These standard interfaces define a protocol by which a control can be hosted in a control container, exchange messages, and handle events.

As COM servers, ActiveX controls have:

Properties Controls have member variables to represent internal state and are implemented as Get and Set accessor functions. A Get function is generated for each accessor method with a propget tag in the .idl file. A Set function is generated for each accessor method with either a propput or propputref IDL tag.

Use wrapper classes or the OLE/COM Object Viewer to determine how accessor functions are defined.

Methods A control's behavior is defined by its public methods. Wrapper classes give you access to a control's methods.

If you do not use wrapper classes, you get access to a control's methods by obtaining a pointer to an interface.

An example of a public method is the Refresh method in the ADO Data Control, which updates the retrieved rowset.

Events A control can generate an event to notify the host that something happened. An example is the OnClick event for the Button control. When the button gets clicked, the button generates an OnClick event. If the control's host has a handler for that event, it executes.
Type Library A type library tells a control container what properties, methods, and events are supported by a control. Type libraries can exist either as separate files (with a .tlb extension) or internally within the control.

Type libraries also contain the control's coclass information. A coclass is a COM class that is identified with a GUID. A coclass contains one or more interfaces that are defined by the control.

To examine type libraries, use the OLE/COM Object Viewer.

The following sections describe the use of an ActiveX control:

Inserting the Control into a Visual C++ Application

Wrapper Classes

Getting Help on Controls

Creating a Database Connection

Setting Control Properties at Design Time

Setting Event Handlers on ActiveX Controls

Modifying a Control's Run-Time Behavior

Redistributing Controls