Summary

Many user interface elements on a computer are intended to mimic the behavior of the mechanical controls that abound in everyday life. Although operating systems such as Windows provide a base set of control objects, developers can create their own custom controls to extend the available set. In the past, several standards for writing custom controls have existed, but none were designed for extensibility and integration with arbitrary containers. The VBX standard for Visual Basic controls, for example, does not extend well to the 32-bit world. For that reason, Microsoft created OLE Controls, a new standard based on OLE.

A control implemented according to this standard is basically an OLE object that supports persistence, embedding, in-place activation, automation, outgoing interfaces (event sets), property pages, and keyboard mnemonics. To support these features, a control implements many interfaces, including IOleObject, IOleInPlaceObject, IOleInPlaceActiveObject, IDispatch, IConnectionPointContainer, ISpecifyPropertyPages, IDataObject, IViewObject2, IProvideClassInfo, IRunnableObject, any of the IPersist* interfaces (except IPersistFile), and the interface named IOleControl, which distinguishes a control from other types of objects.

In the same manner, a container for OLE controls must be capable of handling all these control features. It must also be capable of in-place activation as well as act something like an automation controller by assigning actions to control events that are handled inside event sinks. A container also provides an implementation of IDispatch to expose what are called ambient properties—characteristics of the container that apply to all controls. In addition, a container's site exposes the interface IOleControlSite to provide specific services to the control in that site.

For the most part, the OLE Controls technology uses many of the other technologies in OLE. Only the implementations of the IOleControl and IOleControlSite interfaces represent those functions that are relevant to controls. This includes, in addition to standard ambient properties, keyboard mnemonics, default and cancel buttons, additional MiscStatus bits, and a number of standard control properties, methods, and events.

This chapter explores the architecture of the OLE Controls technology and demonstrates parts of its implementation using the Patron and Polyline samples from previous chapters. Although controls are complex (and have a large number of interfaces), they are also quite powerful and will become more and more important in the future of component software.