|
To access the contents, click the chapter and section titles.
Advanced Visual Basic Techniques
(Publisher: John Wiley & Sons, Inc.)
Author(s): Rod Stephens
ISBN: 0471188816
Publication Date: 06/01/97
Part Six ActiveX on the Web
ActiveX specifies how objects should interact with each other. Applying ActiveX principles to Web browsers, such as Microsoft Internet Explorer, allows ActiveX controls to run within Web pages. The applications described in this section use ActiveX controls to bring extra functionality to Web pages.
Chapter 17 explains how a program can include ActiveX controls in a Web page. It shows how to build a Web page that displays data using the histogram control described in Chapter 16.
Most Web pages take data from a server and send it to a Web user. The WebSurvey application described in Chapter 18 does the opposite: It takes input from a Web user and sends it to a remote server computer.
Chapter 19 finishes the discussion of ActiveX on the Web by explaining the SiteMapper application. This application retrieves documents from a server so it can map out the pages at a Web site.
Chapter 17 ActiveX Controls on the Web
A control that follows the ActiveX specification allows itself to be manipulated by other objects. An application can create an instance of the control, examine and change its property values, invoke its methods, and respond to events it generates.
One of the more interesting ways in which an object can manipulate an ActiveX control is over a network. A Web page designer can place ActiveX controls directly on a Web page. When a user with an ActiveX-enabled browser such as Microsoft Internet Explorer visits the page, the control is downloaded to the users machine. It can then run locally on the users computer rather than remotely on the Web page server. The control can run much faster locally than it can remotely.
This chapter explains how a Web page can use ActiveX controls. The first section, Using ActiveX Controls on Web Pages, shows several Web pages from the users point of view. These pages use ActiveX controls to display data and interact with the user.
The Key Techniques section briefly lists the most important techniques used to place ActiveX controls on Web pages. The rest of the chapter explains those techniques in detail.
Using ActiveX Controls on Web Pages
The Ch17 directory on the compact disk contains four Web documents that include ActiveX controls served by a computer named Beauty. You need to edit these Web pages so they can find the controls on your network before you can test them. The two sections, Displaying Active Controls and Learning Class Ids, explain how you can make the necessary changes.
The document Colors.HTM uses the WebLabel control described later in this chapter to display a set of sample colors. It is shown in Figure 17.1.
The document Gauge.HTM shown in Figure 17.2 uses the WebLabel control and the BarGauge control described in Chapter 15. When the user changes the value of a BarGauge, VBScript code in the document changes the caption of the corresponding label.
FIGURE 17.1 Internet Explorer displaying Colors.HTM.
Histgram.HTM, shown in Figure 17.3, uses the histogram control explained in Chapter 16 to display 100 data values using 10 bar gauges. Using the scroll bar, the user can examine different parts of the data just as if the histogram were running in a Visual Basic application.
Finally, the document PickClr.HTM shown in Figure 17.4 allows the user to experiment with colors displayed by a Web browser. As the user adjusts the red, green, and blue scroll bars, VBScript code computes and displays the selected color value. In Figure 17.4, for example, the colors selected red, green, and blue components are 128, 128, and 255, respectively. The color value RGB(128, 128, 255) has numeric value 16744576 and is pale blue when seen in color.
Key Techniques
Some of the following sections are very different from those presented in earlier chapters. Most of the applications discussed so far reside on a single computer. Even the client/server applications in Chapters 11, 12, and 13 are designed to run on a small number of computers. Placing controls on a public network such as the Internet creates new problems and requires extra work to ensure that the controls are used safely.
FIGURE 17.2 Internet Explorer displaying Gauge.HTM.
The following list briefly describes the new concepts covered in this chapter. The rest of the chapter explains these concepts in greater detail.
- Ensuring Safe Use. A Web page designer may use an ActiveX controls properties and methods in ways the control author never intended. This section describes issues the control designer must consider to ensure that the control is used safely.
- Displaying ActiveX Controls. Displaying ActiveX controls on a Web page is fairly simple using the HTML (hypertext markup language) OBJECT command. This section explains this command and describes some of the Web pages shown in Figures 17.1 through 17.4.
- Learning Class IDs. To use an ActiveX control, a Web page must include the controls class ID as recorded in the registry. This section tells how to determine the class ID and how to arrange for the control to be downloaded to the users computer when necessary.
- Updating Labels. HTML does not provide updateable labels. This section describes a simple WebLabel ActiveX control that can be updated by VBScript code in a Web page.
- Selecting Colors. Passing color parameters to ActiveX controls is not easy since they must be decimal values. This section explains the documents Colors.HTM and PickClr.HTM that can make color selection easier.
- Loading Data Asynchronously. The World Wide Web is designed to load documents asynchronously. This section shows how an ActiveX control can use the AsyncRead method to read its own data asynchronously.
Ensuring Safe Use
If an ActiveX control is placed on a public Web page, some Web user will eventually find the control and use it to create other Web pages. The controls original author cannot know how that other person will use the control. If the control is used indiscreetly, it might damage the computer of an innocent person viewing those other Web pages.
For example, suppose a control generates and displays a large amount of data. The controls NumPoints property determines how many data points it creates. To save time, the control stores intermediate data values in a temporary file named DATA.TMP. When the control is finished creating the data, it removes the file.
Next, suppose someone takes a copy of the control from the Web and adds it to a new Web page. Suppose further that this page initializes the controls NumPoints property to 1 billion. If an innocent bystander views this page, the control will try to create 1 billion data values. It will write each value into the file DATA.TMP on the bystanders computer, taking up a huge amount of space and possibly filling the hard disk completely.
This control is not safe for initialization. Because it was initialized with a property value that was not anticipated by the original control designer, the control turned into a dangerous trap. When an ActiveX control is placed in a public place such as a Web page, it should be as safe as possible.
FIGURE 17.3 Internet Explorer displaying Histgram.HTM.
FIGURE 17.4 Internet Explorer displaying PickClr.HTM.
Just as a control developer cannot always anticipate how another Web page author will initialize a controls properties, there is no way to be certain its methods will be used correctly. If a control provides a CreateTempFile method that takes as a parameter the name or size of a file to create, that method can be abused. By specifying a particular file name, an ill-intentioned Web page could make the control write over files on the users computer. By specifying a large temporary file size, a Web page could use up all of the available space on the users hard disk.
Once a control is initialized, its methods can be invoked by a Web page scripting language such as VBScript. If a controls methods can be abused by the script, the control is not safe for scripting.
|