activex overview
ActiveX is fundamentally different from Java in several ways:
activex tutorial
For our tutorial, I'll take you through the steps we used to implement the area menu on the navigation bar above. (Only available on the Internet Explorer versions of our site.)
The ActiveX control was originally downloaded from the Microsoft ActiveX repository, now relocated to http://www.activex.com/.
This is the code we used to initialize the ActiveX control:
<OBJECT ID="AreaMenu" WIDTH=192 HEIGHT=192
CLASSID="CLSID:275E2FE0-7486-11D0-89D6-00A0C90C9B67"
CODEBASE="http://activex.microsoft.com/controls/mcsi/mcsimenu.cab#version=1,0,0,44">
<PARAM NAME="ForeColor" VALUE="&H00000000">
<PARAM NAME="BackColor" VALUE="&H00BEBEBE">
<PARAM NAME="FontName" VALUE="Verdana">
<PARAM NAME="FontSize" VALUE="10">
<PARAM NAME="FontBold" VALUE="0">
<PARAM NAME="FontItalic" VALUE="0">
<PARAM NAME="FontUnderline" VALUE="0">
<PARAM NAME="FontStrikethrough" VALUE="0">
<PARAM NAME="FontCharset" VALUE="0">
</OBJECT>
I realize that this looks intimidating, but, after I explain the different tags and parameters used, everything will fall into place. First, the <object> tag performs the self-explanatory action of creating an ActiveX object. The five major parameters, used here, are:
AreaMenu.open();
the <param> tag
The other half of ActiveX control implementation is the <param> tag.
ActiveX controls expose a set of properties that affect how it operates and displays.
You can change these properties using the <param> tag, as shown above.
It requires only two parameters:
accessing activex objects with scripts
Many scripts are useless on their own, but very powerful when coupled with JavaScript or VBScript.
Our area menu is one such example.
To add items to the menu, the MCSi Menu control (the menu we use) supports a function,
<body bgcolor="black" text=#F0F0F0 onLoad="JavaScript:InitMenu();">
<OBJECT ID="AreaMenu" WIDTH=192 HEIGHT=192
CLASSID="CLSID:275E2FE0-7486-11D0-89D6-00A0C90C9B67"
CODEBASE="http://activex.microsoft.com/controls/mcsi/mcsimenu.cab#version=1,0,0,44">
<PARAM NAME="ForeColor" VALUE="&H00000000">
<PARAM NAME="BackColor" VALUE="&H00BEBEBE">
<PARAM NAME="FontName" VALUE="Verdana">
<PARAM NAME="FontSize" VALUE="10">
<PARAM NAME="FontBold" VALUE="0">
<PARAM NAME="FontItalic" VALUE="0">
<PARAM NAME="FontUnderline" VALUE="0">
<PARAM NAME="FontStrikethrough" VALUE="0">
<PARAM NAME="FontCharset" VALUE="0">
</OBJECT>
<script language="JavaScript">
function InitMenu()
{
// This function is called when the window is opened
// because of the onLoad attribute defined in the <body> tag above.
AreaMenu.AddItem(0, "Menu Item 1", 1);
AreaMenu.AddItem(0, "Menu Item 2", 2);
AreaMenu.AddItem(0, "Menu Item 3", 0);
AreaMenu.AddItem(0, "", 4); // This is a spacer
AreaMenu.AddItem(0, "Menu Item 4", 4);
}
</script>
<input type="button" value="Popup Menu" OnClick="JavaScript:AreaMenu.Popup()">
</body>
Of course, having a menu doesn't do any good if the web page can't respond when the user selects an item.
To add this functionality, ActiveX controls supply us with events. Events allow scripts embedded in the web page to handle user responses.
To trap the Click(IDofClicked) function that the MCSi Menu Control exposes, insert the following code inside the <body> tag:
<script language="vbscript">
Sub AreaMenu_Click(Cmd)
' This function is executed when a menu item is selected.
' The ID of the menu item is automatically inserted into
' the Cmd variable, defined in the function header.
Msgbox("You have selected Menu Item #" & Cmd)
' Append the ID of the menu item selected to a friendly message.
End Sub
</script>
This code might be unlike the standard scripting code you've been working with, but don't let it unnerve you. First, note that ActiveX events can only be trapped with VBScript code. The syntax for handling an ActiveX event is:
Sub ObjectID_EventName([Optional Arguments])
Code to be executed when the event is triggered
End Sub
After implementing the event handling code, your final menu should work like this:
Congratulations! You've completed the ActiveX tutorial.
Now, check out our Links section for resources providing ActiveX controls that you can use in your own web pages!
Click here to go back to the table of contents.
Copyright © 1998 Webworks Team. All rights reserved. Email alphaomega@proaxis.com with questions or comments about this web site.