Chapter 49

ActiveX Controls

by Jim O'Donnell


CONTENTS

With Internet Explorer 3, Microsoft introduced ActiveX Technologies, a related set of technologies to "Activate the Internet." By building on its highly successful Object Linking and Embedding (OLE) standard, Microsoft has introduced a standard for adding active content to Web pages. This standard allows the capabilities of the Web browser to evolve continually and also allows data and information from existing applications to be easily accessed.

ActiveX Controls combine the convenience of Java applets with the permanence and functionality of Netscape Navigator plug-ins. Like Java applets, ActiveX Controls can be automatically downloaded to your system, either if they are not currently installed or if the installed version is not the most recent. Like plug-ins, ActiveX Controls remain available to your Web browser continuously once they are installed.

This chapter introduces you to ActiveX Controls and shows you examples of the available Controls and how they are used in Web pages. Chapter 50, "Web Authoring with ActiveX Controls," provides more information about programming the controls into your HTML documents, both by hand and by using Microsoft's ActiveX Control Pad.

What Are Internet Explorer ActiveX Controls?

With Internet Explorer 3, Microsoft extends the concept of Web browser plug-ins to its ActiveX Controls. These controls, formerly known as OLE Controls or OCXs, build on Microsoft's highly successful Object Linking and Embedding (OLE) standard to provide a common framework for extending the capability of its Web browser.

But ActiveX Controls are more than just a simple Web browser plug-in; because of the nature of ActiveX Controls, they cannot only be used to extend the functionality of Microsoft's Web browser, but they also can be used by any programming language or application that supports the OLE standard. For example, an ActiveX Control could be written to enable Internet Explorer 3 to automatically search UseNet newsgroups for specific information and, at the same time, can perform a similar function through integration into Microsoft Office products such as Excel or Access. Netscape Navigator plug-ins, on the other hand, can only be used in Navigator (and Internet Explorer 3).

As with Netscape Navigator's plug-ins, ActiveX Controls are dynamic code modules that exist as part of Microsoft's Application Programming Interface (API) for extending and integrating third-party software into any OLE-compliant environment. The creation of (and support for) ActiveX Controls by Microsoft is significant, primarily because it allows other developers to integrate their products seamlessly into the Web via Internet Explorer or any other OLE application, without having to launch any external helper applications.

For Internet Explorer users, ActiveX Controls allow you to customize Internet Explorer's interaction with third-party products and industry media standards. Microsoft's ActiveX Control API also attempts to address the concerns of programmers, providing a high degree of flexibility and cross-platform support.

What ActiveX Controls Mean for End Users

For most users, integrating ActiveX Controls is transparent because they open up and become active whenever Internet Explorer 3 is opened. Furthermore, you often will not even see ActiveX Controls at work because most ActiveX Controls are not activated unless you open a Web page that initiates them. For example, after you install the Shockwave for Macromedia Director ActiveX Control, you will notice no difference in the way Internet Explorer 3 functions until you come across a Web page that features Shockwave.

Once an ActiveX Control is installed on your machine and initiated by a Web page, it manifests itself in one of these three potential forms:

Embedded Controls  An embedded ActiveX Control appears as a visible, rectangular window integrated into a Web page. This window may not appear any different from a window created by a graphic, such as an embedded GIF or JPEG. The main difference between the previous windows supported by Internet Explorer 3 and those created by ActiveX Controls is that ActiveX Control windows support a much wider range of interactivity and movement, and thereby remain live instead of static.

In addition to mouse clicks, embedded ActiveX Controls also read and take note of mouse location, mouse movement, keyboard input, and input from virtually any other input device. In this way, an ActiveX Control can support the full range of user events required to produce sophisticated applications.

Full-Screen Controls  A full-screen ActiveX Control takes over the entire current Internet Explorer 3 window to display its own content. This is necessary when a Web page is designed to display data that is not supported by HTML. An example of this type of ActiveX Control is the VRML 1.0 ActiveX Control available from Microsoft. If you view a VRML world using Internet Explorer 3 with the VRML 1.0 ActiveX Control, it loads into your Web browser like any other Web page, but it retains the look and functionality of a VRML world, with three-dimensional objects that you can navigate through and around.

Hidden Controls  A hidden ActiveX Control doesn't have any visible elements but works strictly behind the scene to add some features to Internet Explorer 3 that are not otherwise available. An example of a hidden control is the Preloader Control, discussed later in this chapter. This ActiveX Control is used to preload a graphic, sound, or other element that will subsequently be viewed by the Internet Explorer 3 user. Since the element is downloaded while the user is browsing through the current Web page, appearance response time is much greater.

Regardless of which ActiveX Controls you are using and whether they are embedded, full-screen, or hidden, the rest of Internet Explorer's user interface should remain relatively constant and available. So even if you have a VRML world displayed in Internet Explorer 3's main window, you can still access Internet Explorer 3's menus and navigational controls.

What ActiveX Controls Mean for Programmers

For programmers, ActiveX Controls offer the possibility of creating Internet Explorer 3 add-on products and using development ActiveX Controls to create your own Internet-based applications. Creating a custom ActiveX Control requires much more intensive background, experience, and testing than actually using one. If you are a developer or are interested in creating an ActiveX Control, the following discussion is useful.

The current version of the ActiveX Control Application Programming Interface (API) supports four broad areas of functionality.

ActiveX Controls can do the following:

ActiveX Controls are ideally suited to take advantage of platform-independent protocols, architectures, languages, and media types such as Java, VRML, and MPEG. While ActiveX Controls should be functionally equivalent across platforms, they should also be complementary to platform-specific protocols and architectures.

When the Internet Explorer 3 client is launched, it knows of any ActiveX Controls available through the Windows 95 Registry but does not load any of them into RAM. Because of this, an ActiveX Control resides in memory only when needed, but many ActiveX Controls may be in use at one time, so you still need to be aware of memory allocation. ActiveX Controls simply reside on disk until they are needed. By having many ActiveX Controls readily available, without taking up any RAM until the time they are needed, the user is able to seamlessly view a tremendous amount of varied data. An ActiveX Control is removed from RAM as soon as the user moves to another HTML page that does not require it.

Integration of ActiveX Controls with the Internet Explorer client is quite elegant and flexible, allowing the programmer to make the most of asynchronous processes and multithreaded data. ActiveX Controls can be associated with one or more MIME types, and Internet Explorer 3 can, in turn, create multiple instances of the same ActiveX Control.

At its most fundamental level, an ActiveX Control can access an URL and retrieve MIME data just as a standard Internet Explorer 3 client does. This data is streamed to the ActiveX Control as it arrives from the network, making it possible to implement viewers and other interfaces that can progressively display information. For instance, an ActiveX Control may draw a simple frame and introductory graphic or text for the user to look at while the bulk of the data is streaming off the network into Internet Explorer 3's existing cache. All the same bandwidth considerations adhered to by good HTML authors need to be accounted for in ActiveX Controls.

Of course, ActiveX Controls can also be file-based, requiring a complete amount of data to be downloaded first before the ActiveX Control can proceed. This type of architecture is not encouraged due to its potential user delays, but it may prove necessary for some data-intensive ActiveX Controls. If an ActiveX Control needs more data than can be supplied through a single data stream, multiple, simultaneous data streams can be requested by the ActiveX Control, so long as the user's system supports this.

While an ActiveX Control is active, if data is needed by another ActiveX Control or by Internet Explorer 3, the ActiveX Control can generate data itself for these purposes. Thus, ActiveX Controls not only process data, but they also generate it. For example, an ActiveX Control can be a data translator or filter.

ActiveX Controls are generally embedded within HTML code and accessed through the OBJECT tag.

NOTE
While creating an ActiveX Control is much easier to do than, say, writing a spreadsheet application, it still requires the talents of a professional programmer. Third-party developers offer visual programming tools or BASIC environments that provide ActiveX Control templates, making the actual coding of ActiveX Controls much less tedious. However, most sophisticated ActiveX Controls are and will be developed in sophisticated C++ environments, requiring thousands of lines of code.

ON THE WEB
http://www.microsoft.com/intdev/  This site is the home of Microsoft's Internet Developer's Web site. If you are interested in learning more about creating ActiveX Controls, this Web site is a good place to start.

ActiveX Control Security

ActiveX Controls are pieces of software; therefore, all of the dangers of running unknown software apply to them as much as anything you may download off of the Internet. ActiveX Controls are unlike Java applets, which run in an environment designed to ensure the safety of the client and can usually only cause trouble by exploiting bugs or flaws in the Java run-time security systems. ActiveX Controls, on the other hand, can do anything on the client computer. Although this increases their potential to perform functions within your Web browser and other compatible applications, it also poses an added security risk. How do you know that a downloaded ActiveX Control won't erase your hard drive?

To address this concern, Microsoft's Internet Explorer 3 Web browser supports Authenticode code-signing technology. This enables vendors of ActiveX Controls and other software components to digitally sign these components. When they are downloaded and the digital signature is recognized, a code signature certificate, like that shown in Figure 49.1, is displayed on the screen. This certificate ensures that the software component is coming from the named source and that it hasn't been tampered with. At this point, you get to choose if you want to install the software component.

Figure 49.1 : Authenticode technology in Microsoft's Internet Explorer 3 helps ensure that downloaded software components are genuine and come from a trusted source.

By default, Internet Explorer 3 installs in high security mode. In this mode, downloaded software components that are unsigned, or whose signatures can't be verified, will not be installed. In this case, an alert box appears that reads something like "This page contains active content that is not verifiably safe to display. To protect your computer, this content will not be displayed. Choose Help to find out how you can change your safety settings so you can view potentially unsafe content." Note that in high security mode, the user doesn't even have the option of installing software components whose authenticity can't be verified.

To change the security mode of Internet Explorer 3, select the Security tab of the View, Options menu. Click the Safety Level button and select your desired security level. Under Medium security, you will be warned of all potential security problems and given the option to proceed or not (see Figure 49.2).

Figure 49.2 : Medium security level puts the burden on the user-you will be warned of potential security risks but given the option to continue anyway.


CAUTION
You should almost never select the None security level, as this leaves your system completely unprotected from malevolent or poorly written software. Only select this level if you are certain all of the sites you are visiting are safe.

NOTE
Fred McLain created the ActiveX Exploder Control to demonstrate the dangers that ActiveX Controls pose to the security unwary. This control, if installed and executed, performs a clean shutdown of your computer and, if you have an energy-conservation BIOS, it actually turns your machine off! The ActiveX Exploder Control Web site is located at http://www1.halcyon.com/mclain/ActiveX/.

Microsoft ActiveX Controls

Microsoft provides a set of ActiveX Controls with Internet Explorer 3 and hosts an ActiveX Gallery Web site to show them off, along with ActiveX Controls from other vendors. This Web site, shown in Figure 49.3, is located at http://www.microsoft.com/activex/controls/.

Figure 49.3 : Microsoft maintains an ActiveX Gallery to show off the capabilities of its ActiveX Controls.

The following sections describe some of these controls and demonstrate how they can be used within a Web page.

Animated Button Control

The ActiveX Animated Button Control creates an area of the Web page that can be used as an animated button. The control takes an AVI animation file as one of its parameters and plays different sequences of frames in the AVI, depending on certain events. The events that the Animated Button Control can respond to include the following:

Listing 49.1 shows an example of how this control is implemented in an HTML document. The TYPE, WIDTH, and HEIGHT attributes of the <OBJECT> tag control the size and placement of the control on the page. The <PARAM> tags for the control determine the AVI animation to be used, along with the frame sequences to be used for each event.


Listing 49.1  HTML Code to Implement the Animated Button Control
<OBJECT
     ID="anbtn"
     CLASSID="clsid:0482B100-739C-11CF-A3A9-00A0C9034920"
     CODEBASE="http://activex.microsoft.com/controls/iexplorer/ieanbtn.
           ocx#version=4,70,0,1161"
     TYPE="application/x-oleobject"
     ALIGN="left"
     WIDTH=300
     HEIGHT=100      
>
<PARAM NAME="url" VALUE="butani.avi">
<PARAM NAME="defaultfrstart"   VALUE="0">
<PARAM NAME="defaultfrend"     VALUE="7">
<PARAM NAME="mouseoverfrstart" VALUE="8">
<PARAM NAME="mouseoverfrend"   VALUE="15">
<PARAM NAME="focusfrstart"     VALUE="16">
<PARAM NAME="focusfrend"       VALUE="23">
<PARAM NAME="downfrstart"      VALUE="24">
<PARAM NAME="downfrend"        VALUE="34">
</OBJECT>

The upper graphic in Figure 49.4 shows the response of the Animated Button Control example (shown on the ActiveX Controls Gallery Web site) for the default event. For this event, the beginning of the animation sequence is shown.

Figure 49.4 : The Animated Button Control plays different parts of an animation depending on the mouse state with respect to the control.

The middle and lower graphics in Figure 49.4 also show the animations for the mouseover and click-and-hold events, playing completely different sections of the animation (in this case). Note that there is no reason that the framing sequences used for the events need to be disjoint. They can overlap or leave gaps that cannot be seen at all, as appropriate.

Chart Control

An example at the Microsoft ActiveX Gallery Web site shows one of the many kinds of charts that can be displayed using the ActiveX Chart Control (see Figure 49.5). Listing 49.2 shows an example of the way the Chart Control is embedded in an HTML document.

Figure 49.5 : The chart shown is one of the many possible kinds of charts that are possible with the ActiveX Chart Control.


Listing 49.2  HTML Code to Implement the Chart Control
<OBJECT
     ID="chart1"
     CLASSID="clsid:FC25B780-75BE-11CF-8B01-444553540000"
     CODEBASE="http://activex.microsoft.com/controls/iexplorer/iechart.
           ocx#Version=4,70,0,1161"
     TYPE="application/x-oleobject"
     WIDTH=400
     HEIGHT=200
>
<PARAM NAME="hgridStyle" VALUE="3">
<PARAM NAME="vgridStyle" VALUE="0">
<PARAM NAME="colorscheme" VALUE="0">
<PARAM NAME="DisplayLegend" VALUE="0">
<PARAM NAME="ChartType" VALUE="8">
<PARAM NAME="BackStyle" VALUE="1">
<PARAM NAME="BackColor" VALUE="#FFFFFF">
<PARAM NAME="ForeColor" VALUE="#0000FF">
<PARAM NAME="Scale" VALUE="100">
<PARAM NAME="url" VALUE="data.txt">
</OBJECT>

The <PARAM> tags are used to configure the Chart Control for display. The two most important parameter tags in the example shown are the NAME="url" parameter, which defines the file containing the data to be charted, and the NAME="ChartType" parameter, which defines the type of chart to be used. The ActiveX Chart Control supports the following chart types shown in Table 49.1 with the appropriate ChartType parameter value.

Table 49.1  ActiveX Chart Control Chart Types

ChartType Value
Type of Chart Displayed
0
Simple Pie Chart
1
Special Pie Chart
2
Simple Point Chart
3
Stacked Point Chart
4
Full Point Chart
5
Simple Line Chart
6
Stacked Line Chart
7
Full Line Chart
8
Simple Area Chart
9
Stacked Area Chart
10
Full Area Chart
11
Simple Column Chart
12
Stacked Column Chart
13
Full Column Chart
14
Simple Bar Chart
15
Stacked Bar Chart
16
Full Bar Chart
17
HLC Simple Stock Chart
18
HLC WSJ Stock Chart
19
OHLC Simple Stock Chart
20
OHLC WSJ Stock Chart

Notice that the chart type and the horizontal and vertical grid types used by the Chart Control can be changed dynamically to show the new chart immediately. You can program your Web pages that use the Chart Control with JavaScript or VB Script to allow the user to decide which type of chart he or she would like.

Gradient Control

The ActiveX Gradient Control provides for the creation of areas with smooth color gradients from one point in the area to another. It is a way of including multicolor boxes and lines in a Web page, without requiring a separate download of an image. Also, gradients included with the Gradient Control can be easily animated with a small JavaScript or VB Script.

Listing 49.3 is an example of the ActiveX Gradient Control demonstrating a smooth transition from white to black in a rectangular box. The result is shown in Figure 49.6.

Figure 49.6 : The Gradient Control allows the creation of cool color effects without requiring the downloading of large image files.



Listing 49.3  Gradient.htm-HTML Example Showing the Gradient Control
<HTML>
<HEAD>
<TITLE>Gradient Example</TITLE>
</HEAD>
<BODY BGCOLOR=#FFFFFF>
<CENTER>
<H1>Gradient Example</H1>
<HR>
<OBJECT
	ID="iegrad1"
	CLASSID="CLSID:017C99A0-8637-11CF-A3A9-00A0C9034920"
	WIDTH=400
	HEIGHT=50
>
<PARAM NAME="StartColor" VALUE="#000000">
<PARAM NAME="EndColor" VALUE="#FFFFFF">
<PARAM NAME="Direction" VALUE="0">
<PARAM NAME="StartPoint" VALUE="(0,0)">
<PARAM NAME="EndPoint" VALUE="(100,50)">
</OBJECT>
</CENTER>
<BR>
<HR>
This example of the ActiveX Gradient Control demonstrates the ability of the
control to display a smooth color gradient in a given box.
</BODY>
</HTML>

CAUTION
It should be noted at this point that the ActiveX Control technology is still pretty young, and a few of the ActiveX Controls are not 100% reliable. For instance, the Gradient Control seems to be a lot slower than it should be, and if you attempt to create a gradient that is too large (much larger than the one shown in the example), Internet Explorer 3 is liable to hang. This is nothing to worry about, as Internet Explorer can be shut down and restarted without disturbing any of the other programs running on your machine, but it is something to keep in mind.

Label Control

The ActiveX Label Control, shown in Figure 49.7, allows text to appear within a Web page using any installed font, with any style, color, and at an arbitrary angle. It is also possible to curve the line of text and animate its appearance. In the example shown in Figure 49.10 (whose code is shown in Listing 49.4) the angle of the text changes whenever the region is clicked.

Figure 49.7 : The Label Control gives the Web author the ability to place text arbitrarily on the Web page, without having to resort to graphics.


Listing 49.4  Label.htm-HTML Example Showing the Label Control
<HTML>
<HEAD>
<TITLE>Label Example</TITLE>
<SCRIPT LANGUAGE="VBS">
Sub Label1_Click
     Label1.Angle = (Label1.Angle + 15) mod 360
End Sub    
</SCRIPT> 
</HEAD>
<BODY BGCOLOR=#FFFFFF>
<CENTER>
<H1>Label Example</H1>
<HR>
<OBJECT
     ID="label1"
     CLASSID="clsid:99B42120-6EC7-11CF-A6C7-00AA00A47DD2"
     CODEBASE="http://activex.microsoft.com/controls/iexplorer/ielabel.
           ocx#version=4,70,0,1161"
     TYPE="application/x-oleobject"
     WIDTH=300
     HEIGHT=250
     VSPACE=0
     ALIGN=center
>
<PARAM NAME="Angle" VALUE="0">
<PARAM NAME="Alignment" VALUE="4" >
<PARAM NAME="BackStyle" VALUE="1" >
<PARAM NAME="BackColor" VALUE="#F0F000" >
<PARAM NAME="Caption" VALUE="ActiveX Label Control">
<PARAM NAME="FontName" VALUE="Verdana">
<PARAM NAME="FontSize" VALUE="16">
<PARAM NAME="ForeColor" VALUE="#000000" >
<PARAM NAME="FontBold" VALUE="1" >
</OBJECT>
</CENTER>
<BR>
<HR>
This example of the ActiveX Label Control demonstrates the ability of the
control to display text at an arbitrary position and orientation. A VB Script
changes the orientation of the text whenever the control is clicked.
</BODY>
</HTML>

Marquee Control

In its Internet Explorer 2 Web browser, Microsoft introduced the <MARQUEE> tag, which allows scrolling marquees to be easily included in a Web page. Their ActiveX Marquee Control takes this concept one step further. In addition to horizontal, vertical, or diagonal scrolling of a text marquee, the ActiveX Marquee Control can also scroll images and other HTML elements. Listing 49.5 shows an example of this, which scrolls a home page through an area that makes up about 50% of the screen. The result is shown in Figure 49.8.

Figure 49.8 : The ActiveX Marquee Control can create scrolling marqueesthat move in any direction and display many different HTML elements.



Listing 49.5  Marquee.htm-HTML Example Showing the Marquee Control
<HTML>
<HEAD>
<TITLE>Marquee Example</TITLE>
</HEAD>
<BODY BGCOLOR=#FFFFFF>
<CENTER>
<H1>Marquee Example</H1>
<HR>
<OBJECT 
     ID="Marquee1" 
     CLASSID="CLSID:1A4DA620-6217-11CF-BE62-0080C72EDD2D"
     TYPE="application/x-oleobject"
     WIDTH=100%
     HEIGHT=50%
>
<PARAM NAME="szURL" VALUE="index.html">
<PARAM NAME="ScrollPixelsX" VALUE="0">
<PARAM NAME="ScrollPixelsY" VALUE="-5">
<PARAM NAME="ScrollDelay" VALUE="100">
<PARAM NAME="Whitespace" VALUE="100">
</OBJECT>
</CENTER>
<HR>
This not-terribly-useful example of the ActiveX Marquee Control
demonstrates the ability of the control to display not just text, but
also correctly render images, hypertext links, and other HTML
elements.
</BODY>
</HTML>

NOTE
There are limitations to what can be properly displayed in a scrolling marquee. For instance, in the example shown in Figure 49.8, though the hypertext links appear to be displayed correctly, they are not active. Also, embedded objects such as inline VRML scenes of other ActiveX Controls will not be displayed.
Also note that Microsoft Internet Explorer also supports the <MARQUEE> HTML tag to create scrolling marquees, but this tag can only support text.

Menu Control

The ActiveX Menu Control enables you to create drop-down menus within a Web page. Items selected from these menus can be set up to trigger events, as well as JavaScript or VB Script functions. Listing 49.6 shows example code that is used to construct two simple drop-down menus. In this example, no events are triggered by selection of the items (see Figure 49.9).

Figure 49.9 : Drop-down menus can be created, changed on the fly, and used to trigger scripted events, all within a Web page.


Listing 49.6  Menu.htm-HTML Example Showing the Menu Control
<HTML>
<HEAD>
<TITLE>Menu Example</TITLE>
<SCRIPT Language="VBS">
<!-- Hide script from incompatible browsers!
Function Timer_Timer()
     If IsObject(mnuEdit) Then
          Timer.Enabled="0"
          mnuFile.Caption="File"
          mnuFile.AddItem "New", 1
          mnuFile.AddItem "Open", 2
          mnuFile.AddItem "Save", 3
          mnuFile.AddItem "Save As...", 4     
' 
          mnuEdit.Caption="Edit"
          mnuEdit.AddItem "Cut", 1
          mnuEdit.AddItem "Copy", 2     
          mnuEdit.AddItem "Paste", 3
          mnuEdit.AddItem "Delete", 4
     End If
End Function
<!-- -->
</SCRIPT> 
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<CENTER>
<H1>Menu Example</H1>
<HR>
<OBJECT 
     ID="mnuFile" 
     CLASSID="CLSID:52DFAE60-CEBF-11CF-A3A9-00A0C9034920"
     CODEBASE="http://activex.microsoft.com/controls/iexplorer/btnmenu.
           ocx#Version=4,70,0,1161"
     TYPE="application/x-oleobject"
     WIDTH=60
     HEIGHT=30
>
</OBJECT>
<OBJECT 
     ID="mnuEdit" 
     CLASSID="CLSID:52DFAE60-CEBF-11CF-A3A9-00A0C9034920"
     CODEBASE="http://activex.microsoft.com/controls/iexplorer/btnmenu.
           ocx#Version=4,70,0,1161"
     TYPE="application/x-oleobject"
     WIDTH=60
     HEIGHT=30
>
</OBJECT>
<OBJECT
     ID="timer"
     CLASSID="clsid:59CCB4A0-727D-11CF-AC36-00AA00A47DD2"
     CODEBASE="http://activex.microsoft.com/controls/iexplorer/ietimer.
           ocx#version=4,70,0,1161"
     TYPE="application/x-oleobject"
     ALIGN=middle
>
<PARAM NAME="Interval" VALUE="100">
<PARAM NAME="Enabled" VALUE="True">
</OBJECT>
</CENTER>
<HR>
This example of the ActiveX Menu Control demonstrates the ability of the
control to create and support menus within the Web browser.
</BODY>
</HTML>

Delayed ActiveX Control Configuration Using the ActiveX Timer Control
Look through Listing 49.6 to see a curious use of the ActiveX Timer Control. At first glance, it is not obvious what the Timer Control is doing or why it is doing it.
The Timer Control is continuously running through its count sequence, from its Interval parameter of 100 milliseconds to zero. Each time it hits zero, it triggers the Timer_Timer() VB Script function. This function checks to see if the mnuEdit object is defined, and if it is, the function sets the menu and item names for the two drop-down menus and disables the Timer Control. If the mnuEdit object doesn't exist, the function will do nothing and the Timer Control will continue to operate.
Why is this necessary? As you will see in Chapter 50, the CODEBASE attribute of the <OBJECT> tag is used to allow the ActiveX Control to be automatically downloaded and installed if it either doesn't exist on the client computer or if a more recent version of it exists at the source. This means that there might be a considerable delay before the ActiveX Menu Control object becomes defined and active. If the VB Script required to configure the menu objects is run before completion of this download and installation, an error will occur because the menu objects are not yet defined.
So the Timer Control and the corresponding Timer_Timer() VB Script function are used to check periodically to see if the menu object has been defined. Once it is defined, the function runs to configure it, and the Timer Control is disabled.

Popup Menu Control

The ActiveX Popup Menu Control is similar to the Menu Control described previously, except that it displays popup menus rather than drop-down menus. The example in Listing 49.7 shows how VB Script is used to dynamically change the menu using the RemoveItem() and AddItem() methods of the Popup Menu Control. Figure 49.10 displays the initial configuration of the Popup Menu Control, which is triggered by clicking the Show Menu button.

Figure 49.10 : By attaching the Popup Menu Control to the onClick() method of the Show Item HTML forms button, the menu appears whenever the button is clicked.


Listing 49.7  Popmenu.htm-HTML Example Showing the Popup Menu Control
<HTML>
<HEAD>
<TITLE>Popup Menu Example</TITLE>
</HEAD>
<SCRIPT Language="VBS">
Sub Iepop1_Click(ByVal x)
     Alert "Item #" & x & " SELECTED!!!"
     Call Iepop1.RemoveItem(x)   
     Call Iepop1.AddItem("Item #" & x & " SELECTED!!!",x)
End Sub

Sub ShowMenu_onClick
     Call Iepop1.PopUp
End Sub
</SCRIPT> 
<BODY BGCOLOR=#FFFFFF>
<CENTER>
<H1>Popup Menu Example</H1>
<HR>
<OBJECT
     ID="iepop1"
     CODEBASE="http://activex.microsoft.com/controls/iexplorer/iemenu.
           ocx#Version=4,70,0,1161"
     TYPE="application/x-oleobject"
     CLASSID="clsid:7823A620-9DD9-11CF-A662-00AA00C066D2"
     WIDTH=1
     HEIGHT=1
>
<PARAM NAME="Menuitem[0]" value="Item #1">
<PARAM NAME="Menuitem[1]" value="Item #2">
<PARAM NAME="Menuitem[2]" value="Item #3">
<PARAM NAME="Menuitem[3]" value="Item #4">
<PARAM NAME="Menuitem[4]" value="Item #5">
</OBJECT>
<INPUT TYPE="button" NAME="ShowMenu" VALUE="Show Menu" ALIGN=RIGHT>
</CENTER>
<HR>
This example of the ActiveX Popup Menu Control demonstrates the ability of
the control to create and support popup menus within the Web browser.
</BODY>
</HTML>

Once an item is selected from the Popup Menu Control, the Click() method of the Control is triggered via the VB Script Iepop1_Click() subroutine. This subroutine removes the selected item and replaces it with one that reflects that this menu item slot has been previously selected and displays an alert box to display what item was picked. The next time the Popup Menu Control is selected, the updated menu item is displayed (see Figure 49.11).

Figure 49.11 : The Popup Menu Control allows menus and menu items to be changed dynamically.

Popup Window Control

The ActiveX Popup Window Control enables you to preview Web pages-displayed in their own popup window. The HTML displayed is subject to the same limitations as those used with the Marquee Control-hypertext links, though displayed correctly, will not be active, and embedded objects will not appear. Listing 49.8 shows an example of using the Popup Window Control to provide a preview of a Web page (see Figure 49.12). Notice that the VB Script StrGetUrlBase() function is used to parse the base (everything other than the document name itself) from the URL of the current document.

Figure 49.12 : The Popup Window Control allows you to present previews of HTML Web pages within their own window.


Listing 49.8  Popwin.htm-HTML Example Showing the Popup Window Control
<HTML>
<HEAD>
<TITLE>Popup Window Example</TITLE>
<SCRIPT Language="VBSCRIPT">
Sub Label0_MouseMove(ByVal s, ByVal b, ByVal x, ByVal y)
     PopObj.Popup strGetUrlBase & "index.html", True
End Sub
Function StrGetUrlBase() 
     Dim strBase, strSlash, idx 

     strBase = Location.HRef
     If (Left(strBase,5)) = "file:" then
          strSlash = "\"
     ElseIf (Left(strBase,5)) = "http:" then
          strSlash = "/"
     Else
          strBase = ""
          strSlash = "/"
     End If

     idx = Len(strBase)
     While idx > 0 And Mid(strBase, idx, 1) <> strSlash
          idx = idx - 1
     Wend

     strBase = Left(strBase,idx)

     StrGetUrlBase = strBase
End Function
</SCRIPT> 
</HEAD>
<BODY BGCOLOR=#FFFFFF>
<CENTER>
<H1>Popup Window Example</H1>
<HR>
<A ID="Link1" href="index.html"> 
<OBJECT
     ID="label0"
     CLASSID="clsid:99B42120-6EC7-11CF-A6C7-00AA00A47DD2"
     CODEBASE="http://activex.microsoft.com/controls/iexplorer/ielabel.
           ocx#version=4,70,0,1161"
     TYPE="application/x-oleobject"
     WIDTH=400
     HEIGHT=20
     VSPACE=0
     ALIGN=center
>
<PARAM NAME="Angle" VALUE="0">
<PARAM NAME="Alignment" VALUE="4" >
<PARAM NAME="BackStyle" VALUE="1" >
<PARAM NAME="BackColor" VALUE="#F0F000" >
<PARAM NAME="Caption" VALUE="Move the cursor here to preview my home page.">
<PARAM NAME="FontName" VALUE="Times New Roman">
<PARAM NAME="FontSize" VALUE="16">
<PARAM NAME="ForeColor" VALUE="#000000" >
</OBJECT>
</A> 
<OBJECT
     ID="PopObj"
     CLASSID="clsid:A23D7C20-CABA-11CF-A5D4-00AA00A47DD2"
     CODEBASE="http://activex.microsoft.com/controls/iexplorer/iepopwnd.
           ocx#Version=4,70,0,1161"
     TYPE="application/x-oleobject"
     WIDTH=400
     HEIGHT=20
>
</OBJECT>
</CENTER>
<HR>
This example of the ActiveX Popup Window Control demonstrates the ability of
the control to display Web pages in a popup window. In this example, the popup
window is attached to a MouseMove event on the displayed ActiveX Label
Control, and appears when the cursor touches the Label object.
</BODY>
</HTML>

Preloader Control

The ActiveX Preloader Control can be used to speed up the apparent throughput of a Web session by allowing Internet Explorer 3 to preload graphics, video, audio, or other HTML elements while a user is reviewing a given page.

Normally, the Web author would use the Preloader Control to quietly preload images or other HTML elements while the user is reading the current Web page. Then, when the user wants to go to the next page in the Web site, or when the user wants to view an image file, hear a sound, or watch a video clip, Internet Explorer will have downloaded it to the cache and the user can view it without any further delay. Listing 49.9 shows an excerpt of how the Preloader Control is set up to download an image file into the cache.


Listing 49.9  HTML Code to Implement the Preloader Control
<OBJECT 
     ID="PreLoader" 
     CLASSID="CLSID:16E349E0-702C-11CF-A3A9-00A0C9034920"
     CODEBASE="http://activex.microsoft.com/controls/iexplorer/iepreld.
           ocx#Version=4,70,0,1161"
     TYPE="application/x-oleobject"
     WIDTH=1 
     HEIGHT=1
>
<PARAM NAME="URL" VALUE="bigimage.gif">
<PARAM NAME="Enable" VALUE="1">
</OBJECT>

Stock Ticker Control

The ActiveX Stock Ticker Control is used to display scrolling stock ticker information across a Web page. Listing 49.10 shows a typical way the control would be coded to include in a Web page. Figure 49.13 shows the example on the Microsoft ActiveX Controls Gallery Web site.

Figure 49.13 : The data file used by the ActiveX Stock Ticker Control can be dynamically changed to allow the information displayed to be continuously updated.


Listing 49.10  HTML Code to Implement the Stock Ticker Control
<OBJECT
     ID=iexr2
     TYPE="application/x-oleobject"
     CLASSID="clsid:0CA4A620-8E3D-11CF-A3A9-00A0C9034920"
     CODEBASE="http://activex.microsoft.com/controls/iexplorer/iestock.
           ocx#Version=4,70,0,1161"
     WIDTH=300
     HEIGHT=50
>
<PARAM NAME="DataObjectName" VALUE="stocks.dat">
<PARAM NAME="DataObjectActive" VALUE="1">
<PARAM NAME="scrollwidth" VALUE="5">
<PARAM NAME="forecolor" VALUE="#ff0000">
<PARAM NAME="backcolor" VALUE="#0000ff">
<PARAM NAME="ReloadInterval" VALUE="5000">
</OBJECT>

Timer Control

Listing 49.11 demonstrates use of the ActiveX Timer Control. This control can be used to trigger events based on the passage of time. The "Cool OCX" and the "Cool Controls" text strings are created by the Label Control; the former rotates and the latter changes color, each as a function of time. Listing 49.11 shows the ActiveX Timer Controls and VB Scripts used to implement this example.


Listing 49.11  HTML Code to Implement the Timer Control
<OBJECT
     ID="timer1"
     CLASSID="clsid:59CCB4A0-727D-11CF-AC36-00AA00A47DD2"
     CODEBASE="http://activex.microsoft.com/controls/iexplorer/ietimer.
           ocx#Version=4,70,0,1161"
     TYPE="application/x-oleobject"
     ALIGN=middle
>
<PARAM NAME="Interval" VALUE="200">
<PARAM NAME="Enabled" VALUE="True">
</OBJECT>

<OBJECT
     ID="timer2"
     CLASSID="clsid:59CCB4A0-727D-11CF-AC36-00AA00A47DD2"
     CODEBASE="http://activex.microsoft.com/controls/iexplorer/ietimer.
           ocx#version=4,70,0,1161"
     TYPE="application/x-oleobject"
     ALIGN=middle
>
<PARAM NAME="Interval" VALUE="1000">
<PARAM NAME="Enabled" VALUE="True">
</OBJECT>

<SCRIPT LANGUAGE="VBScript">
Sub BtnToggle_OnClick
     Timer1.Enabled = Not Timer1.Enabled             
     Timer2.Enabled = Not Timer2.Enabled
End Sub
Sub Timer1_timer
     Label.Angle = (Label.Angle + 5) mod 360
End Sub
Sub Timer2_Timer
     Randomize
     Cool.ForeColor = rnd() * 16777216
End Sub
</SCRIPT>

View Tracker Control

The last example is the ActiveX View Tracker Control. This ActiveX Control has onHide and onShow events that are triggered when the place on the Web page where the control is embedded passes out of or into view. Figure 49.14 and 49.15 show the Controls Gallery example-the implementation is shown by the code in Listing 49.12.

Figure 49.14 : When the View Tracker Control first appears in view or each time it reappears, its onShow event is triggered.

Figure 49.15 : The View Tracker can be used to create context sensitive menus and Web pages, whose content changes depending on what is currently displayed.


Listing 49.12  HTML Code to Implement the View Tracker Control
<OBJECT
     ID="Track1"
     CLASSID="clsid:1A771020-A28E-11CF-8510-00AA003B6C7E"
     CODEBASE="http://activex.microsoft.com/controls/iexplorer/ietrack.
           ocx#Version=4,70,0,1161"
     WIDTH=1
     HEIGHT=1
     ALIGN="left"
>
</OBJECT>

<SCRIPT Language="VBScript">
Sub Track1_OnShow
     Alert "The View Track control is back on the screen"
End Sub
Sub Track1_OnHide
     Alert "The View Track control has left the screen"
End Sub
</SCRIPT>