Building ActiveX Controls is a pretty technical exercise. Using C++ and ActiveX Template Libraries requires a thorough understanding of the OLE and COM object specifications. However, you don't need to build ActiveX Controls in order to produce dynamic Web pages. In fact, Microsoft is quite hopeful that a large third-party market in ActiveX Controls will develop, much as the VBX and OCX market has developed. Using ActiveX Controls in a Web page is really a straightforward exercise, once you've learned a few basics.
These varying alternatives all take a swipe at defining a more general nomenclature for describing new multimedia content. Serving in its role of developing standards for the Web, the World Wide Web Consortium (W3C) convened a group of experts to define a new tag, <OBJECT>, which encompasses the <IMG> tag and provides a general solution for handling diverse multimedia content. In addition, <OBJECT> allows you to specify various parameters for initializing the object when it is placed on a Web page.
The <OBJECT> tag allows you to specify object parameters in a number of ways including the following:
ActiveX Controls typically use named properties to initialize. Note that there are also standard properties, such as HEIGHT and WIDTH, that may be specified for all objects.
This tag can also point to the code that is to be executed in the object's space. This makes it easy for Web authors to include and change referenced objects. The code can also be referenced in the following ways:
ActiveX, as you'll see, uses the class name option to be referenced.
Listing 19.1-7-1LSTNG.HTM-Object Tag Example #1
<! -------------------------------------------------
<! --
<! -- Description: Simple OBJECT tag Example #1
<! --
<! -- Author: Brian Farrar
<! --
<! -- Date: 5/11/96
<! -------------------------------------------------
<HTML>
<TITLE>Simple OBJECT Tag Example #1
</TITLE>
<BODY>
<H1>Simple Object Tag Example #1</H1>
<P>
If your browser supports display of avi movies inline
you'll see a movie here,
otherwise you'll see a simple graphic.
<OBJECT
DATA=SomeFile.avi
TYPE="application/avi">
<IMG SRC=SomeGif.gif ALT="ActiveX">
</OBJECT>
</BODY>
</HTML>
If the Web browser you use supports in-line playing of AVI video format, the movie called SomeFile.avi would be played. Otherwise, the Web browser will substitute the graphic SomeGif.gif. Thus, the <OBJECT> tag allows you to include specific content that is not supported by all browsers, without getting involved in content negotiation.
![]() Various Web browsers support different features. For instance, Netscape Navigator 2.0 and Microsoft Internet Explorer 3.0 both support frames. However, most other browsers do not. In order to use more advanced features like frames without excluding those who use browsers that don't support an advanced feature, Web authors sometimes engage in content negotiation. Content negotiation usually employs a CGI application to examine the USER_AGENT field passed through the CGI (which indicates the type of browser) and selects a page optimized for the requesting browser. ![]() |
The TYPE attribute makes it easy for Web browsers to determine if the indicated <OBJECT> is supported and, if it is not supported, does not download the object thereby avoiding unnecessary bandwidth use. Making TYPE available also allows the Web browser to avoid guessing at the application format based on the extension.
Attribute | Description |
---|---|
ALIGN | Determines placement of the object relative to other items on the page |
BORDER | Suggests the width of the border to be placed around the display |
CLASSID | Identifies an implementation of the object to be rendered on the page |
CODE | Some objects (like Java applets) need this as reference to other code |
DATA | Points to any data required by the object referred to by CLASSID |
DECLARE | Indicates whether the object referred to in CLASSID is to be declared or instantiated |
HEIGHT | Suggests the height that the Web browser should provide for display of the object |
HSPACE | Area to be preserved as white space to the left and right of the border and display space of the <OBJECT> |
ID | A document-wide identifier used to refer to the <OBJECT> |
ISMAP | When the object is clicked, this attribute causes the mouse coordinates to be sent to the server |
NAME | Used to indicate if the <OBJECT>'s value should be included in a FORM |
STANDBY | Identifies the text to be displayed while the object is being loaded |
TYPE | Refers to Internet Media Type (RFC 1590) of the item referred to in the CLASSID field |
USEMAP | Points to a client-side image map |
VSPACE | Area to be preserved as white space above and below the border and display space of the <OBJECT> |
WIDTH | Suggests the width that the Web browser should provide for display of the object |
Use the summary table as a quick reference for the <OBJECT>'s tag attributes. Each of these attributes bears a bit of explanation.
Value | Meaning |
---|---|
TEXTTOP | The top of the object aligned with the top of the current font |
MIDDLE | The middle of the object aligned vertically with the baseline |
TEXTMIDDLE | The middle of the object vertically aligned with a position halfway between the baseline and the height of the lowercase letter x |
BASELINE | The object's bottom aligned with the baseline of the text line on which it appears |
Table 19.3-Values for the ALIGN attribute as a Free-Floating Object
Value | Meaning |
---|---|
LEFT | The object will be placed on the left margin below the previous text or object in the page. |
CENTER | The object will be placed midway between the left and right margins. |
RIGHT | The object will be placed on the right margin below the previous text or object in the page. |
The ALIGN tag is currently fully implemented in MSIE 3.0.
![]() http://www.w3.org/pub/WWW/Addressing/clsid-scheme-For further information on the CLASSID: URL scheme, check out this Web site. ![]() |
The CLASSID for any ActiveX Control can also be obtained from the registry in Windows 95. To do this, follow these steps:
If the CLASSID attribute is missing, ActiveX data streams will include a class identifier that can be used by the ActiveX loader to find the appropriate control. The CODE attribute can be used to provide an URL from which the control can be obtained.
Fig. 19.1 - How placement attributes affect the <OBJECT> tag.
![]() ftp://ds.internic.net/rfc/rfc1590.txt-You can learn more about Internet Media Types by refering to RFC 1590, which you can find at this FTP site. ![]() |
Currently, the TYPE attribute is supported in a limited fashion in MSIE 3.0. Microsoft has indicated that TYPE will be implemented for all relevant MIME types.
Attribute | Description |
---|---|
NAME | Defines the name of the property. Your ActiveX Control can treat the name as case-sensitive, if desired. |
VALUE | Specifies the value of the property identified in NAME. |
VALUETYPE | Can be one of REF, OBJECT, or DATA. |
TYPE | Refers to Internet Media Type (RFC 1590) of the item referred to in the VALUE field when VALUETYPE = REF. |
There is no need to go through all of these attributes. Except for the VALUETYPE attributes, they are mostly self-explanatory. The VALUETYPE attributes are explained briefly in Table 19.5.
Value | Meaning |
---|---|
REF | Indicates that the value found in the VALUE attribute is a URL. |
OBJECT | Indicates that the value found in the VALUE attribute is the URL of another OBJECT element. |
DATA | Indicates that the value found in the VALUE attribute is intended to be passed to the OBJECT as a string. This is the default VALUETYPE. |
In each of the following sections, you'll work an example and then review important properties.
Listing.19.2-HTMLSTUB.HTM-HTML Document Template
<! -------------------------------------------------
<! --
<! -- Description:
<! --
<! -- Author: Brian Farrar
<! --
<! -- Date:
<! -------------------------------------------------
<HTML>
<TITLE>
</TITLE>
<BODY BGCOLOR=#FFFFFF>
<H1></H1>
<P>
<OBJECT
</OBJECT>
</BODY>
</HTML>
To use the New control in HTML document, follow these steps:
Listing 19.3-NEWCTL.HTM-Customizing the HTML Template
<! -------------------------------------------------
<! --
<! -- Description: Using the New Control
<! --
<! -- Author: Brian Farrar
<! --
<! -- Date: 5/12/96
<! -------------------------------------------------
<HTML>
<TITLE>
New Item ActiveX Control Example
</TITLE>
<BODY BGCOLOR=#FFFFFF>
<H1>What's New on Our Web Site</H1>
<P>
</BODY>
</HTML>
Listing 19.4-2NEWCTL.HTM-First Instance of <OBJECT> in NEWCTL.HTM
<OBJECT
ID="NewLabel"
CLASSID="CLSID:642B65C0-7374-11CF-A3A9-00A0C9034920"
WIDTH=20
HEIGHT=10
HSPACE=10
>
<PARAM NAME="date" value="6/1/96">
</OBJECT>
Listing 19.5-3NEWCTL.HTM-Expired New Control <OBJECT> Listing
<OBJECT
ID=NewLabel
CLASSID="CLSID:642B65C0-7374-11CF-A3A9-00A0C9034920"
WIDTH=20
HEIGHT=10
HSPACE=10
>
<PARAM NAME="date" value="5/1/96">
</OBJECT>
Now that the HTML document is complete, you can test your work using Microsoft Internet Explorer 3.0. To test your HTML document, follow these steps:
Fig. 19.2 - First test of NEWCTL.HTM.
Fig. 19.3 - Second test of NEWCTL.HTM.
If you've managed a Web site, you can see the tremendous benefit for an ActiveX Control like the New control.
Property | Description |
---|---|
DATE | This property sets the date on which the New sticker should expire. This allows a document to decide for itself whether the content is new. |
IMAGE | This property allows you to select an image other than the default image. Provide a URL to an appropriate image. |
Listing 19.6-LABEL.HTM-<OBJECT> Tag For Inserting Label ActiveX Control
<OBJECT
CLASSID="clsid:99B42120-6EC7-11CF-A6C7-00AA00A47DD2"
ID=label
WIDTH=200
HEIGHT=100
VSPACE=0
ALIGN=left
>
<PARAM NAME="angle" value="30">
<PARAM NAME="alignment" value="3">
<PARAM NAME="BackStyle" value="0">
<PARAM NAME="caption" value="Announce">
<PARAM NAME="FontName" value="Impact">
<PARAM NAME="FontSize" value="40">
<PARAM NAME="frcolor" value="255">
</OBJECT>
![]() Note that the order parameters that appear in the code depend upon whether you typed the code or used the ActiveX Control Pad's Edit menu and property sheet. The examples in this chapter were typed. ![]() |
Listing 19.7-2LABEL.HTM-Second Label Control in LABEL.HTM
<OBJECT
CLASSID="clsid:99B42120-6EC7-11CF-A6C7-00AA00A47DD2"
ID=label
WIDTH=300
HEIGHT=100
VSPACE=0
ALIGN="center"
>
<PARAM NAME="angle" value="180">
<PARAM NAME="alignment" value="2">
<PARAM NAME="BackStyle" value="0">
<PARAM NAME="caption" value="Surprise">
<PARAM NAME="FontName" value="Brush Script MT">
<PARAM NAME="FontSize" value="110">
<PARAM NAME="frcolor" value="16776960">
</OBJECT>
Now that you've completed the HTML document, you can test your work using Microsoft Internet Explorer 3.0. To testing your HTML document, follow these steps.
Fig. 19.4 - Check your Label control example results.
Property | Description |
---|---|
Caption | Indicates the text to be displayed within the Label control. The appearance of this text will be affected by other properties. |
Angle | Indicates the angle of the base line for the text. This item is specified in degrees counter-clockwise from horizontal. |
Alignment | Indicates the alignment of the control within the rectangular area specified for the control |
BackStyle | Indicates how to display the area of the control not covered by the caption text. |
FontName | Indicates the True Type font used to draw the Caption text. |
FontSize | Indicates the size of the font used to draw the Caption text. |
FontItalic | Indicates that the Caption text should be italicized. |
FontBold | Indicates that the Caption text should be bolded. |
FontUnderline | Indicates that the Caption text should be underlined. |
FontStrikeout | Indicates that the Caption text should be marked with strikethrough. |
FrColor | Indicates the RGB triplet for the color. |
The following sections examine a few details related to some of these properties.
Value | Description |
---|---|
0 | Causes the control to be aligned along the left edge of the control's frame. |
1 | Causes the control to be aligned along the right edge of the control's frame. |
2 | Causes the control to be centered within the control's frame. |
3 | Causes the control to be aligned along the top of the control's frame. |
4 | Causes the control to be aligned along the bottom of the control's frame. |
Value | Description |
---|---|
0 | Transparent-the area within the control's frame not covered by the Caption text is set to the page's background color. |
1 | Opaque-the area within the control's frame not covered by Caption text is set to a default color (usually gray). |
Listing 19.8-TIMER.HTM-Label Control for Use with Timer Control
<OBJECT
CLASSID="clsid:99B42120-6EC7-11CF-A6C7-00AA00A47DD2"
ID=Spinner
WIDTH=350
HEIGHT=350
ALIGN=center
HSPACE=30
VSPACE=50
>
<PARAM NAME="angle" value="0">
<PARAM NAME="alignment" value="2">
<PARAM NAME="BackStyle" value="0">
<PARAM NAME="caption" value="Spin a web">
<PARAM NAME="FontName" value="Monotype Corsiva">
<PARAM NAME="FontSize" value="30">
</OBJECT>
Listing 19.9-2TIMER.HTM-Timer Control
<OBJECT
CLASSID="59CCB4A0-727D-11CF-AC36-00AA00A47DD2"
ID=SpinTimer
ALIGN=middle
>
<PARAM NAME="TimeOut" value="100">
<PARAM NAME="enable" value="1">
</OBJECT>
Fig. 19.5 - Enter the code in Code View from the Script Wizard.
Listing 19.10-3TIMER.HTM-VBScript to Implement Timer Response Function
<SCRIPT LANGUAGE="VBScript" FOR="SpinTimer" EVENT="time">
Spinner.Angle = (Spinner.Angle - 5) mod 360
If Spinner.FontSize > 100 Then
Spinner.FontSize = 10
If Spinner.Caption = "Spin a web" Then
Spinner.Caption = "Don't get dizzy"
Else
Spinner.Caption = "Spin a web"
End If
Else
Spinner.FontSize = Spinner.FontSize + 5
End If
</SCRIPT>
Take a minute and study what this function does. First, the Angle property of the Spinner Label control is decreased by five. Then the modulus of the result and 360 is taken. (This ensures that the result is always less than 360 degrees.) As the Angle property is being changed, the FontSize property is increased until it exceeds 100. When the FontSize exceeds 100, the Caption property is toggled between two different strings.
Now that you've completed the HTML document, you can test your work using Microsoft Internet Explorer 3.0. These next steps take you through testing your HTML document:
Fig. 19.6 - Timer control example results.
Property | Description |
---|---|
Enable | This property indicates whether the Timer has been enabled or not. |
TimeOut | Use this property to set the time, in milliseconds, when the Timer is triggered. |
Status | Meaning |
---|---|
1 | Timer is enabled |
0 | Timer is disabled |
To experiment with response function naming, go back to the LABEL.HTM file created previously and implement a response function for the Mouse Click event. A simple way to do this is to use the MsgBox function which takes a text string as a parameter.
Copyright ©1996, Que Corporation. All rights reserved. No part of this book may be used or reproduced in any form or by any means, or stored in a database or retrieval system without prior written permission of the publisher except in the case of brief quotations embodied in critical articles and reviews. Making copies of any part of this book for any purpose other than your own personal use is a violation of United States copyright laws. For information, address Que Corporation, 201 West 103rd Street, Indianapolis, IN 46290.Notice: This material is from BackOffice Intranet Kit, ISBN: 0-7897-0848-5. The electronic version of this material has not been through the final proof reading stage that the book goes through before being published in printed form. Some errors may exist here that are corrected before the book is published. This material is provided "as is" without any warranty of any kind.