LISTER.OCX: A Listbox-Based OLE Custom Control

Our first example custom OLE control is a customized listbox control. In all ways, this control acts as a listbox except when the user clicks it. After being clicked, our customized listbox displays the text "Hello world.":

Web Page
         -----------------------
        |                       |
        |        ------------   |
        |       |Hello, world|  |
        |       |            |  |
        |       |            |  |
        |       |            |  |
        |        ------------   |
        |                       |
         -----------------------

We will place the support for this custom control in a file named LISTER.OCX, and we'll be able to add this control to our VBScript pages in the same way we add any other ActiveX control.

Visual C++ provides an excellent tool for testing the ActiveX controls we create. In the Visual C++ Tools menu, you will find the menu item OLE Control Test Container. Clicking that tool opens the Visual C++ test container, and the Edit menu of that container program has an item named Insert OLE Control:


	-----------------------
         | Container             |
         |-----------------------|
         | File Edit             |
         |-----|---------------------
         |     |Insert Ole Control...|
         |     |                     |
         |      ---------------------
         |                       |
         |                       |
         |                       |
          -----------------------

When you select that item, the Insert OLE Control box opens, displaying all the custom controls available, including our LISTER control:


	-----------------------
         | Container             |
         |-----------------------|
         |         -------------------------------
         |        |Insert OLE Control   --------  |
         |        |                    |   OK   | |
         |        |Object Type          --------  |
         |        | ---------------     --------  |
         |        ||Lister Control |   | Cancel | |
          --------||               |    --------  |
                  | ---------------               |
                   -------------------------------

Here, you see the entry Lister Control in the Object Type box. (We assume that we have already registered our ActiveX control with Windows, and now Windows is informing us that it is available.) When we select Lister Control in the Object Type box and then click OK, a new LISTER control appears in the test container. (It is just an empty listbox at this point):


	-----------------------
         | Container             |
         |-----------------------|
         |        ------------   |
         |       |            |  |
         |       |            |  |
         |       |            |  |
         |       |            |  |
         |        ------------   |
         |                       |
          -----------------------

When a user clicks this listbox, it displays the text "Hello, world.":


	-----------------------
         | Container             |
         |-----------------------|
         |        ------------   |
         |       |Hello, world|  |
         |       |            |  |
         |       |            |  |
         |       |            |  |
         |        ------------   |
         |                       |
          -----------------------

Now we know what we are aiming for. Let's get started.

© 1996 by Steven Holzner. All rights reserved.