Visual C++ 6 Unleashed

Visual C++ 6 Unleashed

By MICKEY WILLIAMS and David Bennett

Testing an ActiveX Control

To ensure that your ActiveX control works properly, you should test it in as many environments as possible. At a minimum, you should test your ActiveX controls in the following environments:

Displaying a Control on a Web Page

To "activate the Internet" with ActiveX controls, as the Microsoft marketing folks are fond of saying, you have to have a way of embedding those ActiveX controls in an HTML file.

The W3C controls the HTML standard. The current HTML standard is version 4.01. Like most standards, it is continually updated and modified as technology progresses. As the standard progresses, the controlling agency tries to ensure backward compatibility so that any HTML browser that does not yet support the newest standard will degrade gracefully and allow the HTML to be viewed.

The <OBJECT> HTML tag allows the insertion of dynamic content on the Web page, such as ActiveX controls. The tag is just a way of identifying such dynamic elements. It is up to the browser to parse the HTML tags and perform the appropriate action based on the meaning of the tag. In Listing 28.13, you can see the HTML syntax for the <OBJECT> tag. This syntax comes directly from the W3C, which controls the HTML standard. In this case, it is HTML standard Version 4.01.

Example 28.13. HTML Syntax for the <OBJECT> Tag

 1:  <OBJECT
 2:     ALIGN= alignment type
 3:     BORDER= number
 4:     CLASSID= universal resource locator
 5:     CODEBASE= universal resource locator
 6:     CODETYPE= codetype
 7:     DATA= universal resource locator
 8:     DECLARE
 9:     HEIGHT= number
 10:    HSPACE= value
 11:    NAME= universal resource locator
 12:     SHAPES
 13:     STANDBY= message
 14:     TYPE= type
 15:     USEMAP= universal resource locator
 16:     VSPACE= number
 17:     WIDTH= number
 18: </OBJECT>
						

By using the <OBJECT> tag, you can insert an object such as an image, document, applet, or control into the HTML document.

Table 28.6 shows the acceptable range of values to be used by the parameters of the <OBJECT> tag.

Table 28.6. Values for the Parameters of the <OBJECT> Tag

Parameter Values
ALIGN= alignment type Sets the alignment for the object. The alignment type is one of the following values: BASELINE, LEFT, MIDDLE, CENTER, RIGHT, TEXTMIDDLE, TEXTTOP, and TEXTBOTTOM.
BORDER= number Specifies the width of the border if the object is defined to be a hyperlink.
CLASSID= universal resource locator Identifies the object implementation. The syntax of the universal resource locator (URL) depends on the object type. For example, for registered ActiveX controls, the syntax is CLSID:class-identifier.
CODEBASE= universal resource locator Identifies the codebase for the object. The syntax of the URL depends on the object.
CODETYPE= codetype Specifies the Internet media type for code.
DATA= universal resource locator Identifies data for the object. The syntax of the URL depends on the object.
DECLARE Declares the object without instantiating it. Use this when creating cross-references to the object later in the document or when using the object as a parameter in another object.
HEIGHT= number Specifies the height for the object.
HSPACE= number Specifies the horizontal gutter. This is the extra empty space between the object and any text or images to the left or right of the object.
NAME= universal resource locator Sets the name of the object when submitted as part of a form.
SHAPES Specifies that the object has shaped and shared hyperlinks.
STANDBY= message Sets a message to be displayed while an object is loaded.
TYPE= type Specifies the Internet media type for data.
USEMAP= universal resource locator Specifies the imagemap to use with the object.
VSPACE= number Specifies a vertical gutter. This is the extra white space between the object and any text or images above or below the object.
WIDTH= number Specifies the width for the object.

In Listing 28.14, you can see HTML document source code with an embedded ActiveX object in it. In addition, note the <PARAM NAME= value> tag. This tag was used to set any properties your ActiveX control can have.

Example 28.14. The HTML Page with an Embedded <OBJECT> Tag Showing an ActiveMovie ActiveX Control Embedded in the Page

 1:  <HTML>
 2:  <HEAD>
 3:  <TITLE>AN EMBEDDED ActiveX Control</TITLE>
 4:  </HEAD>
 5:  <BODY>
 6:
 7:  <p align=center><font size=6><em><strong><u>An EMBEDDED ActiveX Control </u></strong></em></font></p>
 8:  <OBJECT
 9:  ID="ActiveMovie1"
 10: WIDTH=347
 11: HEIGHT=324
 12: ALIGN=center
 13: CLASSID="CLSID:05589FA1-C356-11CE-BF01-00AA0055595A"
 14: CODEBASE="http://www.microsoft.com/ie/download/activex/amovie.ocx# Version=4,70,0,1086">
 15:    <PARAM NAME="_ExtentX" VALUE="9155">
 16:    <PARAM NAME="_ExtentY" VALUE="8573">
 17:    <PARAM NAME="MovieWindowSize" VALUE="2">
 18:    <PARAM NAME="MovieWindowWidth" VALUE="342">
 19:    <PARAM NAME="MovieWindowHeight" VALUE="243">
 20:    <PARAM NAME="FileName" VALUE="E:\vinman\dstuds.avi">
 21:    <PARAM NAME="Auto Start" VALUE="TRUE">
 22: </OBJECT>
 23:
 24: </BODY>
 25: </HTML>
						

When a browser such as Internet Explorer encounters this page, it begins to parse the HTML source code. When it finds <OBJECT> in line 8, it realizes it has encountered a dynamic object. The browser then takes lines 10 to 12—the WIDTH, HEIGHT, and ALIGN attributes, which in this case are 347, 324, and center, respectively—and sets up a placeholder for the object on the rendered page. It then takes the ID "ActiveMovie1" in line 9 and the CLASSID "CLSID:05589FA1-C356-11CE-BF01-00AA0055595A" in line 13 and checks to see whether this control has been registered in the Registry. If the control object has never been registered, it uses the CODEBASE attribute to locate the ActiveX control on the server machine and downloads the object into a local directory. The browser then registers AMOVIE.OCX by calling DllRegisterServer to register the control on the local machine. Now, with the control properly registered, the browser can get the CLSID for the object from the Registry. To use the control, the browser passes the CSLID to CoCreateInstance to create the object, and this returns the pointer to the control's IUnknown. The browser can use this pointer and the property information in lines 15 to 22 to actually render the object on the page.

Now, you can see that embedding controls to enhance a Web page with dynamic content is fairly easy. It is important that you, as an ActiveX control designer, understand how these controls are rendered.

ActiveX Control Pad

The ActiveX Control Pad provides a method of generating the HTML code, discussed earlier, to embed ActiveX and other dynamic objects into HTML source code (see Figure 28.14). This is a free tool provided by Microsoft to aid in the production of Internet-enabled applications.

28fig14.jpg

Figure 28.14 The ActiveX Control Pad with the ActiveMovie control properties being edited.

You can use this tool to quickly embed your control in a page so that you can test its functionality. The ActiveX Control Pad can be a great time-saver, freeing you from having to remember how to write HTML source code. It even allows you to test the control using VBScript (see Figure 28.15).

28fig15.gif

Figure 28.15 The ActiveX Script Wizard helps you create scripts to further activate your controls.

In addition, the ActiveX Control Pad comes with a suite of ActiveX controls for you to use in the development of your Web pages and your ActiveX-enabled applications. Some of these controls are the same controls that come with Internet Explorer; however, there are a few new ones to add to your bag of ActiveX controls.

ActiveX Control Test Container

The ActiveX Control Test Container is provided with Visual C++ to allow you to fully test your ActiveX control. This tool enables you to test your control's registration, events, properties, and methods. To invoke the ActiveX Control Test Container, choose Tools, ActiveX Control Test Container. The ActiveX Control Test Container appears, as shown in Figure 28.16.

28fig16.gif

Figure 28.16 The ActiveX Control Test Container is a tool to help you test your controls.

In addition to the ActiveX Control Test Container, you might want to consider using Rational Software's Visual Test. This tool previously was known as the Microsoft Visual Test.

ActiveX Controls in Development Tools

One last way to test your ActiveX controls is with your development tools: Visual C++, Borland C++, Visual Basic, Delphi, PowerBuilder, Access, and almost any other mainstream Windows or Internet development suite. Become familiar with these development tools and ensure that they work in all environments. In addition, most of these tools come with ActiveX controls. So use and take advantage of the components provided for you. This approach will make your job much easier and your users much happier.

Share ThisShare This

Informit Network