Control.ocx: A Button-Based ActiveX Control

Basing custom controls on existing control types is useful, because it means that the standard events, such as mouse button presses or character entry, are already supported, and we can add event-handling functions to a control simply by using Visual C++'s ClassWizard. In fact, we can draw the control ourselves even if we base it on a standard Windows control. For example, let's draw a button with a cloudy day image that changes to a sunny day when the button is pushed. Although this control is based on the Windows button type, we can make it look like and act however we want, because we'll draw it ourselves. Let's call this new project CONTROL; when we insert a control of this type in a Web page, we'll be able to control its appearance when we draw it:

Web Page
         -----------------------
        |                       |
        |        ------------   |
        |       |            |<--- we draw our button here 
        |       |            |  |
        |       |            |  |
        |       |            |  |
        |        ------------   |
        |                       |
         -----------------------

Using OLE ControlWizard, give this new project the name CONTROL and create it as we did for Lister. In Step 2 of the OLE ControlWizard, select BUTTON as the type of control our project should subclass (just as we selected LISTBOX in LISTER). Click Finish to allow ControlWizard to create this project.

As before, ControlWizard creates many files, including these important ones:

CONTROL.MAK: The project file

CONTROL.CPP: OLE DLL initialization, termination, other bookkeeping

CONTROLCTL.CPP: Main implementation file (CControlCtrl class)

CONTROLPPG.CPP: Implementation of the CControlPropPage property page class

CONTROL.ODL: Object Description Language source code for the type library

© 1996 by Steven Holzner. All rights reserved.