- Table of Contents
- Copyright
- About the Authors
- About the Contributors
- Acknowledgments
- Tell Us What You Think!
- Introduction
- How to Use This Book
- What You Need to Use This Book
- What's New in Visual C++ 6.0
- Contacting the Main Author
- Part I: Introduction
- Chapter 1. The Visual C++ 6.0 Environment
- Part II: MFC Programming
- Chapter 2. MFC Class Library Overview
- Chapter 3. MFC Message Handling Mechanism
- Chapter 4. The Document View Architecture
- Chapter 5. Creating and Using Dialog Boxes
- Chapter 6. Working with Device Contexts and GDI Objects
- Chapter 7. Creating and Using Property Sheets
- Chapter 8. Working with the File System
- Chapter 9. Using Serialization with File and Archive Objects
- Part III: Internet Programming with MFC
- Chapter 10. MFC and the Internet Server API (ISAPI)
- Chapter 11. The WinInet API
- Chapter 12. MFC HTML Support
- Part IV: Advanced Programming Topics
- Chapter 13. Using the Standard C++ Library
- Chapter 14. Error Detection and Exception Handling Techniques
- Chapter 15. Debugging and Profiling Strategies
- Chapter 16. Multithreading
- Chapter 17. Using Scripting and Other Tools to Automate the Visual C++ IDE
- Part V: Database Programming
- Chapter 18. Creating Custom AppWizards
- Chapter 19. Database Overview
- Chapter 20. ODBC Programming
- Chapter 21. MFC Database Classes
- Chapter 22. Using OLE DB
- Chapter 23. Programming with ADO
- Part VI: MFC Support for COM and ActiveX
- Chapter 24. Overview of COM and Active Technologies
- Chapter 25. Active Documents
- Chapter 26. Active Containers
- Chapter 27. Active Servers
- Chapter 28. ActiveX Controls
- Part VII: Using the Active Template Library
- Chapter 29. ATL Architecture
- Chapter 30. Creating COM Objects Using ATL
- Chapter 31. Creating ActiveX Controls Using ATL
- Chapter 32. Using ATL to Create MTS and COM+ Components
- Part VIII: Finishing Touches
- Chapter 33. Adding Windows Help
- Part IX: Appendix
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:
- A Web page, if your control is intended for use in a browser
- The ActiveX control container
- Visual C++, Visual Basic, or any other environments you're targeting
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.
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).
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.
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.
Methods of Creating ActiveX Controls | Next Section

Account Sign In
View your cart