Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org

Related items

un-Gratuitous Gradients

Browser Redirection using VBScript

Rattling Keys and Chasing Mice With VBScript

Introduction to Visual Basic Scripting (VBScript)

The Amazing ActiveX - Part 1

You are here: irt.org | Articles | VBScript | The Amazing ActiveX - Part 1 [ previous next ]

Published on: Monday 9th August 1999 By: Ryan Detert

Overview

"The Amazing ActiveX" will be a series of journals to give you an understanding of how ActiveX works. We will explore the uses of pre-made ActiveX controls as well as guide you through making your own using Microsoft's developing tools.

ActiveX is Microsoft's patented Windows technology that allows you to load a type of applet into your web browser. These applets are very much the same as Java Applets and can add an incredible amount of dynamics to your web page.

ActiveX first appeared in MSIE 3.0, before the completion of DHTML. In addition, MSIE 3.0+ are the only browsers that currently support ActiveX components. For this reason, many people have not used them because Netscape used to be ahead in the browser war.

Darwinism and the Evolution of OLE

What made Windows great back in the dark-ages was its ability to share information between applications. This type of technology was known as OLE (object linking and embedding), this technology is still widely used in today's Win 3.1, Win98, etc. OLE allowed you to do things such as 'cut and paste' and was very useful. However, as things progressed, Windows began to utilize another, better kind of technology known as COM (component object module), which is a super OLE.

COM is really the heart of ActiveX and other things dealing with Windows. For example, if you have ever used Word 97 and have ever inserted a spreadsheet you can see that although only Word is open you can still work with an Excel spreadsheet normally. This is known as embedding; it is when one type of document or application is placed inside another document or application. The original OLE did not have this capability.

Benefits of ActiveX

ActiveX components are really just small applications that are made in some other language like Visual Basic or C++, and are meant to run in another environment called a 'container.' You do not have to install ActiveX because Windows already utilizes such things as COM and OLE. However, in order to use ActiveX you must have a 'container' that supports ActiveX. For example, Internet Explorer and Microsoft Word are ActiveX containers.

What's the point of using ActiveX if Java Applets do the same thing? This raises a very good question and has been the center of some debate. The point is this: Java Applets can only run in an internet browser environment. This is great and allows you to do much more with your web page, but ActiveX will run in any Windows container, which can be a Visual Basic Form, Internet Explorer, etc. By this, ActiveX can be used in places other than your web browser. This makes it much more versatile and robust.

Making Your Own ActiveX Components

We could open a whole other section at irt.org on this topic alone. Basically, Microsoft's Visual Developer's Series (Visual Basic, Visual C++, etc.) offer ActiveX capabilities, meaning that you can compile Visual Basic Code as an ActiveX component. However, this goes beyond the scope of this journal entry and we will stick with some of the basic ActiveX components that come with IE. Perhaps later on we will make our own controls from scratch.

The HTML <OBJECT> Tag

To insert an ActiveX control into your web page you need to use an HTML tag known as the <OBJECT></OBJECT> tag. This does just what it says, inserts an object. However, there are a few more attributes that need to be added in order to get you ActiveX control to work (some more than others.)

The most important of these attributes is the classid. The classid is a long number that Windows uses to identify the control. This way, every control has its own unique identification. All of these classids can be found in the Windows registry, where the operating system keeps track of them all.

If you would like to try this out then follow these steps (NOTE: DO NOT change any of the registries values if you don't know what you are doing!):

You will be surprised at how many of these ActiveX controls there are.

Object Attributes

Aside from the most crucial of the Object attributes, the classid, there are also many other attributes that are optional and for the most part nothing new. Here is a long list of possible attributes that you may use within the first <Object> tag:

However, the Object tag provides for (and sometimes requires) more than just the above attributes to function as you would like them to. In order to interact with the ActiveX control via HTML, you need to include <Param></Param> tags. Without them, the ActiveX controls will load with their default values, which may not be what you want.

The <PARAM> Tag, Initializing ActiveX

PARAM tags pass parameters, or arguments, to the ActiveX control. When the ActiveX controls are made, (usually) they are designed so that the user has the ability to change certain aspects of the control, such as font size, background color, etc.

These tags always begin the the word PARAM, then the NAME of the parameter followed by its VALUE.

For instance, to set the caption of a button you would go:

<PARAM NAME="Caption" VALUE="Please Click Me!">

No ActiveX Support, No Problem

If the client's browser does not support the Object tag it will ignore the <Object> and <Param> tags and will either display an error message like "This Object Not Supported." or allow you to insert an image to display in place of the ActiveX control. For instance:

<Object>
...
<IMG SRC="no_activeX.gif">
...
</Object>

Intrinsic Scripting Events

Intrinsic is just a fancy word for "inherited" and once you look at the table below of the some of most common events you will all know what I'm talking about. We will go over how to use these more in depth in upcoming jounral entries. Please note that not all ActiveX controls supports all of these events:

VBScript Meets ActiveX

You have the ability to integrate ActiveX components with scripting. Since ActiveX is more closely related with VBScript, we will use it instead of JavaScript.

Hypothetically, if you made a button using the HTML <INPUT> tag you would have the ability trigger an event every time that button is clicked. Likewise, you may also do the same thing with a button that was created as an ActiveX object. The only difference is that you have much more control over such things as how the ActiveX button looks, is positioned, etc.

Here is an example of how to read a click event on ActiveX button:

<OBJECT ID="myButton" CLASSID="CLSID:D7053240-CE69-11CD-A777-00DD01143C57">
</OBJECT>

<script langauge="VBScript">
	Sub myButton_Click()
		Msgbox "Click Me To A Better Place!"
	End Sub
</script>

Notice that this is almost exactly how you read a regular <INPUT TYPE="button">.

Working Example

<OBJECT ID="button1" WIDTH=61 HEIGHT=29
 CLASSID="CLSID:D7053240-CE69-11CD-A777-00DD01143C57">

    <PARAM NAME="ForeColor" VALUE="2147483653">
    <PARAM NAME="BackColor" VALUE="2147483650">
    <PARAM NAME="VariousPropertyBits" VALUE="268435483">
    <PARAM NAME="Caption" VALUE="Click Me!">
    <PARAM NAME="Size" VALUE="1606;764">
    <IMG SRC="ie4.gif">

</OBJECT>

<SCRIPT LANGUAGE="VBScript">

	Sub button1_Click()
		On Error Resume Next

		If button1.caption = "Click Me!" Then
			button1.caption = "Thank you for Clicking! (click again to reset)"
		Else
			button1.caption = "Click Me!"
		End If

	End Sub

</SCRIPT>

Scroll the bar with the side arrows to watch it fade.

<OBJECT ID="fadeScroll" WIDTH=171 HEIGHT=21 ALIGN=CENTER
  CODEBASE="http://activex.microsoft.com/controls/mspert10.cab"
  CLASSID="CLSID:DFD181E0-5E2F-11CE-A449-00AA004A803D"
  STYLE="filter:Alpha(Opacity=100, FinishOpacity=100)">

    <PARAM NAME="BackColor" VALUE="&H80">
    <PARAM NAME="ForeColor" VALUE="&H80000005">
    <PARAM NAME="Size" VALUE="4516;318">
    <PARAM NAME="Max" VALUE="100">
    <PARAM NAME="Position" VALUE="100">
    <PARAM NAME="LargeChange" VALUE="10">
    <PARAM NAME="Orientation" VALUE="5">

</OBJECT>

<SCRIPT language="VBScript">

	Sub fadeScroll_Change()
		On Error Resume Next

		If fadeScroll.Value > 20 Then
			fadeScroll.filters.alpha.opacity = fadeScroll.Value
		End If

	End Sub
</SCRIPT>

ActiveX specification reference material obtained from QUE's USING HTML 3.2 by Mark R. Brown and Jerry Honeycutt.

Related items

un-Gratuitous Gradients

Browser Redirection using VBScript

Rattling Keys and Chasing Mice With VBScript

Introduction to Visual Basic Scripting (VBScript)

©2018 Martin Webb