ActiveX has to be one of the most misunderstood and ambiguously used expressions in the Internet technology arena. When Microsoft released their first set of Internet tools in March 1996, they announced ActiveX technology – which in all truth was just a new marketing name for their existing OLE technology. ActiveX (or 3rd generation OLE technology) is a framework that allows software components to co-operate even if they have been written by different vendors, at different times using different tools and different languages, and if the objects are located in the same process, same machine or distributed over multiple machines. Put simply, ActiveX provides the software plumbing between software objects and insulates the component developer from such complexities.
Many people get confused because ActiveX actually encompasses a number of technologies and is not just one thing. Each ActiveX technology defines the interfaces between the objects to implement the particular technology. For the Internet, examples include:
To most users, ActiveX is transparent and they just see the effects of these technologies - it is irrelevant to them whether it is ActiveX or black magic that is operating behind the scenes. However, it is different for the developer - we shall see later how the Internet ActiveX technologies provide a powerful environment for creating interactive Web content.
Underneath ActiveX is the generic Component Object Model (COM) which defines the binary interface between objects. The original specification of COM always allowed for co-operating objects to be located on different machines, but this was not implemented until Windows NT 4.0 and was then called Distributed COM (DCOM). Because of this, in reality DCOM and COM are now the same animal. This is all we really need to know about COM/DCOM, although they will be mentioned throughout the book.
There does exist a small anti-ActiveX camp (with members typically having investments in alternative technologies!), that are concerned this will make the Internet as Windows-centric as today's desktops. However, since ActiveX is the most advanced component software platform around, there is no doubt that it will build on its current momentum and play a major role in the next wave of Internet application development.
Corresponding to Microsoft's recent focus on Internet technology has been their aim to embrace industry standards and support openness. The ActiveX technologies have been given to an independent consortium called The Active Group and Microsoft has been working with a number of third parties to support ActiveX on non-Windows platforms including UNIX and Apple Macintosh. NCompass Labs http://www.ncompasslabs.com
have an ActiveX Plug-in for the Netscape Navigator browser.
Let's now see ActiveX in action.
As part of their move towards seamless browsing, ActiveX Documents are fundamental to Microsoft's aim to achieve a document-centric world rather than the current application-centric notion. ActiveX Documents are based on the previous OLE DocObjects technology that allowed in-place activation or visual editing. For example, an MS Excel spreadsheet embedded in a MS Word document could be edited directly within the Word frame, with the menus and toolbars adapting to make available the Excel facilities.
If you look at the size of the IE4 executable, IEXPLORE.EXE
, you will see it is so very small for an application that is as rich in functionality as IE4. In fact, this executable is just a simple process that loops to handle windows messages and provide a container for ActiveX Documents. Normally IE4 displays HTML – this is handled by a software component providing Web Browser support and using the IE4 container for displaying the page. The Web browser functionality is provided by an object implemented in SHDOCVW.DLL
.
As IE4 is an ActiveX Document container, it can support any applications that support the interfaces (i.e. methods, properties and events) that are defined by the ActiveX Document specifications. This includes the Microsoft Office products and other application vendors that are rapidly supporting this technology. This means that as we navigate the numerous resources within an Intranet, we no longer need to invoke separate word processors, spreadsheets, etc. to access the various items of information, IE4 can do it for us:
Scripting is an easy way to make our Web pages come alive and allows the browser to interact with the user and software components (i.e. trap events, invoke methods and access properties). It involves incorporating high level script commands into the HTML document that automatically get invoked by the browser when loaded or by the user clicking on something.
Rather than just develop script processing for IE4, Microsoft has used ActiveX to provide a flexible architecture for adding any scripting language to an application. ActiveX Scripting allows script hosts to invoke scripting services within script engines. Further the hosts and engines can be from different software vendors and can implement different languages, since the plumbing between the two is handled by COM/DCOM. The ActiveX Scripting specifications define the interfaces that a script host and script engine must support. The script language, syntax and execution rules are defined by the vendor of the script engine. All script logic is interpreted on the fly by the script engine, there is no concept of compiling the scripts. This is shown as follows:
IE4, ASP and Visual InterDev are examples of script hosts, but you can now easily add scripting to your own applications. VBScript and JScript are examples of script languages, but again, you can also develop your own. VBScript is a subset of Visual Basic for Applications (as used by the Microsoft Office Products) which in turn is a subset of the popular Visual Basic programming language. JScript is Microsoft's implementation of the Netscape's JavaScript, although Microsoft and Netscape are currently working on standardizing their versions of JavaScript.
The real power of scripting comes with the ability to interact with other objects. This enables accessing an object's properties, invoking methods and detecting events, and of course all this happens using COM/DCOM under the covers. Accessible objects are either:
Client-side scripting can be inserted into an HTML page using the <SCRIPT>
tags pair, and so can be incorporated within minimal impact. To identify the script language, the LANGUAGE
attribute is used, as shown in the following template.
<HTML>
<HEAD>
<TITLE>Document title
</TITLE>
<SCRIPT LANGUAGE="VBSCRIPT">
Client-side VBS scripting logic
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>
If you wish your page to viewed normally in older browsers that cannot process script as well, then you can hide the script within HTML comment tags <!--
and -->
.
The client-side scripting can interface to all element objects in a web page (e.g. tags, images, text, etc.), browser objects (e.g. windows, frames, history, etc.) and 'talk to' any object that has been included in the page. From this, we can see that scripting is what really enables the Dynamic in Dynamic HTML. We can now change any part of the Web page as a user interacts with the page, as demonstrated in our Wrox Press orders example earlier.
While there are third parties supplying alternative scripting languages (e.g. Perl etc.), most people will use one of the two Microsoft supplied core options, VBScript or JScript – but which is best? Well the truth is that there is very little difference in between the capabilities of the two. Both languages are capable of being used by those with minimal programming experience. At the time of writing, IE3/IE4 are the only browsers that support VBScript. Thus, if you are aiming for mass penetration on the Internet then you should probably restrict the scripting to JavaScript, although to remain functional on both IE and Netscape browsers you will require a lot more than just one simple JavaScript program, because the two implementations of Dynamic HTML are so different. If you are developing for an Intranet, where you have control over the infrastructure and can enforce IE4 as the choice of browser, you can choose to use VBScript.
Active Server Pages (ASP) is a technology that provides a server-side application framework. You may wonder why we're discussing a server-side technology in a books focussed primarily on the client-side. This is because ASP provided a robust object model that also allowed the web page developer to do things dynamically. Later in the book we will take a look at how can combine the two technologies, but first we need to take a brief look at what ASP can do.
ASP allows executable script logic to be embedded within an HTML page. It enables the scripting to interface to a number of internal objects, which automatically handle many of the menial tasks, and so simplifies the script logic. ASP uses server-side scripting to dynamically create HTML responses. The content generated is typically based on the following features:
ASP provides a number of built in objects and useful components. The built-in objects simplify many of the common server-side tasks such as handling the HTTP request/responses, the user's session and the Web environment.
Server-side scripting is inserted in an ASP file using either the <SCRIPT>
tags pair or <%
and %>
delimiters. To distinguish client-side from server-side scripting, the latter's <SCRIPT>
tag should include the RUNAT="SERVER"
attribute and value. For example:
<HTML>
<HEAD>
<TITLE>Document title
</TITLE>
<SCRIPT LANGUAGE="VBSCRIPT" RUNAT="SERVER">
Server-side VBS scripting logic
</SCRIPT>
<SCRIPT LANGUAGE="VBSCRIPT">
Client-side VBS scripting logic
</SCRIPT>
</HEAD>
<BODY>
<% Server-side VBS scripting logic %>
</BODY>
Script that runs on the server can always run VBScript, because it has to be running on IIS which is a Microsoft Product. The script which runs on the client(browser) has to be either JavaScript or VBScript, depending on the browser or preference.
Prior to scripting, all user interactions had to be handled by communication with the Web Server. Script logic now enables client-side processing to occur and can help to avoid some of the time-consuming communication with overburdened servers. It should be noted that the ASP server-side scripting is not exposed in the generated HTML file, where as client-side scripting could be inspected by simply viewing the HTML source code. This means that if you are concerned about the people copying your clever code or seeing your confidential business rules then you should engage such logic in the server. In practise, you will find that both server-side and client-side scripting have specific uses and that the design of your Web application will require a combination of the two.
An ActiveX Control is a software component that gives a specific item of functionality to a parent application (i.e. an ActiveX Control container). IE4 is such an application that can host ActiveX Controls within a Web page. The forerunners to ActiveX Controls were OLE Controls (for 32 bit applications) and the original, but limited, VBX controls (for 16 bit Visual Basic applications only).
ActiveX Controls expose properties and methods and can fire events, using COM/DCOM under the covers. The combining of this with ActiveX Scripting provides our goal of user interactivity. For example, clicking a button would fire the associated event and could cause a script to invoke a method on a control, which may then effect the results seen in the Web page. ActiveX Controls cannot directly communicate with each other. However, this can be achieved via script logic.
ActiveX Controls can contain sophisticated logic and add features to Web pages that could never be achieved with standard HTML even with scripting. It is estimated that there are over 1,000 commercial ActiveX Controls on the market; examples of cool controls include:
http://www.citrix.com
http://www.bdiamond.com
http://www.macromedia.com
http://www.activex.com
One great advantage that ActiveX Controls provide is that they are automatically downloaded and installed, as needed. If a Web page references an ActiveX Control that is either not installed or is out of date, the deployment of the control is automatically handled by a helpful facility within IE4 called the Internet Component Download Service (ICDS). ICDS is also responsible for handling the Authenticode processing. Authenticode is Microsoft's and Verisign's Digital Signing system. It provides a mechanism to digitally sign and authenticate code to independent vendors. It will present the user with a certificate dialog highlighting details of the component's origin and can be used to hold vendors accountable to their software, whenever it causes problems:
{bmc0707_01_11.bmp}
Or alternatively, IE4 will flag a problem such as the control being is unsigned or not in the exact format as when released by the author. If this last case happens, it could mean that the control has been tampered with and isn't safe to use.
ActiveX Controls are compiled into native machine code. This means that if you intend to support multiple target client platforms you must produce a separate version for each. You should also remember that code size is important as many users connect to the Internet using slow modems, and might not be patient enough to wait for a fat control to arrive.
An ActiveX Control is embedded into an HTML page by specifying a number of attributes between the <OBJECT>
tag pair. For a visual control, this will be displayed in the page at the point where the tag is placed. Every ActiveX Control is uniquely identified by a sequence of numbers called a Class ID or Globally Unique Id (GUID). For example, the Class ID of the Microsoft NetShow Client Control is {2179C5D3-EBFF-11CF-B6FD-00AA00B4E220
}. Since it is obviously not possible to remember such sequences for the numerous controls that are available, we need a quick way finding the Class ID.
One easy way is to use the Insert ActiveX Control facility in the Microsoft FrontPad (that ships with full installation of IE4) & FrontPage HTML editors. By selecting this menu option, the user is able to select an ActiveX Control from all controls installed in the Registry, and this will automatically insert the <OBJECT>
tags with the appropriate Class ID. This automatic insertion is very useful since the nature of Class IDs tend to make typos frequent; it is very easy to key a wrong digit and not realize it until the control fails to instantiate.
Control properties are specified using the <PARAM>
tag that takes two attributes – NAME
and VALUE
, for the property name and the value to initialize the property to. The following example shows what the code for a Tab control looks like:
<HTML>
<HEAD>
<TITLE>Tabs</TITLE>
<SCRIPT LANGUAGE="VBScript">
<!—to be added -->
</SCRIPT>
</HEAD>
<BODY bgcolor=cyan>
<OBJECT ID="TabStrip1" WIDTH=69 HEIGHT=107
CLASSID="CLSID:EAE50EB0-4A62-11CE-BED6-00AA00611080">
<PARAM NAME="ListIndex" VALUE="3">
<PARAM NAME="BackColor" VALUE="16776960">
<PARAM NAME="Size" VALUE="1834;2822">
<PARAM NAME="Items" VALUE="One;Two;Three;Four;">
<PARAM NAME="TabOrientation" VALUE="2">
<PARAM NAME="MultiRow" VALUE="-1">
<PARAM NAME="TipStrings" VALUE="One;Two;Three;Four;">
<PARAM NAME="Names" VALUE="One;Two;Three;Four;">
<PARAM NAME="NewVersion" VALUE="-1">
<PARAM NAME="TabsAllocated" VALUE="4">
<PARAM NAME="Tags" VALUE=";;;;">
<PARAM NAME="TabData" VALUE="4">
<PARAM NAME="Accelerator" VALUE=";;;;">
<PARAM NAME="FontCharSet" VALUE="0">
<PARAM NAME="FontPitchAndFamily" VALUE="2">
<PARAM NAME="TabState" VALUE="3;3;3;3">
</OBJECT>
</BODY>
</HTML>
Remember that the <OBJECT>
tag attributes, including <PARAM>
are all editor generated and you wouldn't have type these in yourself.
The tab control is inserted in the page as follows, but if you click on it, there is no response:
An important attribute in the <OBJECT>
tag is the ID
that is used to provide an easier name to reference the control; in particular it is used by the scripting language to apply any logic to the object. We have to first set the ID
in the HTML:
...
<BODY bgcolor=cyan>
<OBJECT ID="TabStrip1" WIDTH=69 HEIGHT=107
CLASSID="CLSID:EAE50EB0-4A62-11CE-BED6-00AA00611080">
...
in order to be able to reference it within a scripting language and therefore get the tab control to respond to each tab that is selected:
<SCRIPT LANGUAGE="VBScript">
Sub TabStrip1_Click(Index)
select case Index
case 0 msgbox "one"
case 1 msgbox "two"
case 2 msgbox "three"
case 3 msgbox "four"
end select
end sub
</SCRIPT>
The <OBJECT>
tag can include a CODEBASE
attribute to specify the location of the control and the required version. If the control has not been previously installed or it is out of date, the ICDS uses the CODEBASE
's URL to retrieve and install the control. For example
CODEBASE="http://activex.microsoft.com/controls/iexplorer/timer.ocx#
Version=4,70,0,1161">
Until IE4 there was no smart way of managing the numerous ActiveX Controls that were downloaded and installed. It was possible that controls could be installed, used only once, and then would become redundant wasting disk space. With IE4, downloaded controls are installed in a folder called Downloaded Program Files within the Windows folder. When this folder is viewed via the Windows Explorer, a shell extension provides special functionality to manage the content. Each installed control is represented by an icon. By right clicking on an icon, a control can either be uninstalled or have its properties inspected.
You have three different choices of view, which supply general information such as the Class ID, Dependency Information and Version Information:
To create ActiveX Controls, the developer has several options, including the following:
http://www.microsoft.com/vbasic/