Partager via


Visual Basic Concepts

What Is an ActiveX Document?

The word "document" in "ActiveX document" is somewhat misleading. While the genesis of ActiveX documents reveals that a Microsoft Visual Basic ActiveX document is analogous to a Word document, when you create a Visual Basic ActiveX document, the distinction between a "document" and an application becomes genuinely blurred. While a traditional document (such as a Word document) is static, ActiveX documents need not be. Using Visual Basic, you can create a complete application with the semantics of a traditional document. In other words, you have the functionality of the application, but the flexibility of a document's behavior — when a user opens an ActiveX document, she will not only have the full functionality of an application, but the ability to persist and distribute "copies" of the data intrinsic to the application. Thus, the "document" is truly active.

An Analogy: Word Document = ActiveX Document

ActiveX documents are not an entirely new concept. You are probably already familiar with Word documents. As you know, a Word document is not the same as the Word application — the Word document (with the extension .doc) contains the actual content, whereas the Word application (Winword.exe) is used to create the document.

You may also know that a Word document can be viewed in other containers. In that case, the Word application supplies the objects that enable another ActiveX container (such as Internet Explorer) to view and activate the document. And this same mechanism works for ActiveX documents created with Visual Basic.

As Figure 11.1 shows, when you create an ActiveX document-based project, you are creating a Visual Basic "document" that can be contained in an ActiveX container (such as Internet Explorer). Compiling the ActiveX document creates both a Visual Basic Document file (with the extension .vbd) and its corresponding server — which can be an ActiveX .dll, or ActiveX .exe file. In other words, the .vbd file is to the .exe or .dll file what the .doc file is to the Winword.exe file.

Figure 11.1   Word Documents and ActiveX Documents Compared