3-D Buttons

The first example (ocx.htm) is a Web page that holds a number of the most popular ActiveX controls, and the first step is to insert such a control into the Web page. Let's start by giving our Web page a title and a header ("OCX Control Page"):

<HTML>
    <HEAD>
    <TITLE>OCX Control Page</TITLE>
    </HEAD>
    <BODY LANGUAGE = VBScript ONLOAD = "Page_Initialize">
    <CENTER>
--> <H1>OCX Control Page</H1>
    </CENTER>
        .
        .
        .

Now we'll insert our first ActiveX control, the 3-D push-button control. This button is much like the standard buttons we have used throughout this book, but it has a more three-dimensional appearance. The 3-D button is supported by the threed.ocx file, which should be in your windows\system directory if you want to use this control; you can do Windows registration of .ocx files using RegSvr32.exe. We'll need the registration value of this control in the Windows registry.

To get that registration value, you can use the Windows regedit.exe tool (regedit.exe is in your Windows directory); start regedit and select Find in the Edit menu, opening the Find dialog box. Type the name of the control you are looking for, Threed Command Button, in the Find what: box and click Find Next. You can also use Microsoft's aclist.exe tool, available from www.microsoft.com, to list ActiveX controls available in your computer. You'll find that this control has a class ID in the registry: 0ba686b4-f7d3-101a-993e-0000c0ef6f5e. This value, called the control's class ID or clsid, uniquely represents the 3-D command button to Windows. We add it to our Web page using the <OBJECT> tag, giving the 3-D command button the ID Cmd1:

<HTML>
    <HEAD>
    <TITLE>OCX Control Page</TITLE>
    </HEAD>
    <BODY LANGUAGE = VBScript ONLOAD = "Page_Initialize">
    <CENTER>
    <H1>OCX Control Page</H1>
    </CENTER>
    <!- SSCommand>
    <PRE>
--> SSCommand:   <OBJECT CLASSID="clsid:0ba686b4-f7d3-101a-993e-0000c0ef6f5e"
                   HEIGHT=30 WIDTH=70 ID=Cmd1></OBJECT>
    </PRE>
        .
        .
        .

Note: Each control that we are discussing in this chapter must be registered with Windows 95 in order to be accessible to VBScript. If one or more of the controls do not work, you should check your Registry to find out what ActiveX controls you have available.

That's the general form of the <OBJECT> tag; we fill the properties of the new OLE control with the <PARAM> tag between <OBJECT> and </OBJECT>:

<OBJECT CLASSID = "clsid:   " HEIGHT = 30 WIDTH = 70 ID=IDname>
                <PARAM NAME = "FontName" VALUE = "Arial">
                <PARAM NAME = "FontSize" VALUE = 12>
        </OBJECT>

Using the <PARAM> tag, we supply both the name of the property we are setting and the value we want to set it to. If we want to let users download our .ocx file automatically (for example, if we know they don't have it on disk), we can use the CODEBASE keyword, indicating that the needed support file, called control96.ocx, is in the server directory ocxcode:

<OBJECT CLASSID = "clsid:   " HEIGHT = 30 WIDTH = 70
            CODEBASE="/ocxcode/control96.ocx" ID=IDname>
                <PARAM NAME = "FontName" VALUE = "Arial">
                <PARAM NAME = "FontSize" VALUE = 12>
        </OBJECT>

In the case of our 3-D command button, we now refer to it as Cmd1 because we gave it that ID:

SSCommand:   <OBJECT CLASSID="clsid:0ba686b4-f7d3-101a-993e-0000c0ef6f5e"
                   HEIGHT=30 WIDTH=70 ID=Cmd1></OBJECT>

As with standard buttons, we can set the button's caption to, say, "Hello," when the page first loads by setting Cmd1's Caption property in Page_Initialize:

<HTML>
    <HEAD>
    <TITLE>OCX Control Page</TITLE>
    </HEAD>
    <BODY LANGUAGE = VBScript ONLOAD = "Page_Initialize">
    <CENTER>
    <H1>OCX Control Page</H1>
    </CENTER>
    <!- SSCommand>
    <PRE>
    SSCommand:   <OBJECT CLASSID="clsid:0ba686b4-f7d3-101a-993e-0000c0ef6f5e"
                   HEIGHT=30 WIDTH=70 ID=Cmd1></OBJECT>
    </PRE>
       .
       .
       .
    <SCRIPT LANGUAGE = VBScript>
 -->        Sub Page_Initialize
 -->              Cmd1.Caption = "Hello"
 -->        End Sub
    </SCRIPT>
    </BODY>
    </HTML>

The result appears in Figure 6.1, where you can see the new 3-D button with the caption "Hello."

Figure 6.1  Our ActiveX Controls Web page.

We can use Cmd1 like any standard button, adding a click event like this (assuming we have a textbox named Text1):

Sub Cmd1_Click()
                  Text1.Text = "Hello World!"
            End Sub

So that's how we connect ActiveX controls to VBScript: we add them with an <OBJECT> tag and give them a control ID (such as Cmd1) that we can refer to in code. Now let's examine two more 3-D controls: 3-D frames and 3-D panels.

© 1996 by Steven Holzner. All rights reserved.