Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Visual Basic 6 Black Book
(Publisher: The Coriolis Group)
Author(s): Steven Holzner
ISBN: 1576102831
Publication Date: 08/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Chapter 20
Creating ActiveX Controls And Documents

If you need an immediate solution to:
Creating An ActiveX Control
Designing An ActiveX Control From Scratch
Giving ActiveX Controls Persistent Graphics
Basing An ActiveX Control On An Existing Visual Basic Control
Handling Constituent Control Events In An ActiveX Control
Adding Controls To An ActiveX Control (A Calculator ActiveX Control)
Testing An ActiveX Control
Creating A Visual Basic Project Group To Test An ActiveX Control
Registering An ActiveX Control
Using A Custom ActiveX Control In A Visual Basic Program
Adding A Property To An ActiveX Control
Making ActiveX Control Properties Persistent (PropertyBag Object)
Adding A Method To An ActiveX Control
Adding An Event To An ActiveX Control
Adding Design Time Property Pages
Creating An ActiveX Document
ActiveX Document DLLs Vs. EXEs
Adding Controls To An ActiveX Document (A Tic-Tac-Toe Example)
Handling Constituent Control Events In An ActiveX Document
Testing An ActiveX Document
Creating ActiveX Documents That Run Outside Visual Basic
Distributed Computing: ActiveX Documents And Integrated Browsers
Making ActiveX Document Properties Persistent (PropertyBag Object)

In Depth

ActiveX controls and ActiveX documents are two of the ActiveX components you can build with Visual Basic. In fact, the ActiveX part of Visual Basic has exploded in scope lately, along with many changes in terminology, and will surely do so again. We’ll start this chapter with an overview of ActiveX and ActiveX controls and documents in particular.

All About ActiveX Components

The whole ActiveX field started originally to differentiate controls designed for Internet usage from general OLE (Object Linking and Embedding) controls. In time, however, all OLE controls have come to be referred to as ActiveX controls. In fact, the field has taken off so vigorously that now Visual Basic can build not just ActiveX controls in Visual Basic (you used to have to build ActiveX controls for use in Visual Basic in other programming packages, like Visual C++), but ActiveX components.

What is an ActiveX component? In programming terms, all ActiveX components are really OLE servers, but that doesn’t help us understand what’s going on. It’s better to break things down and look at the three types of ActiveX components:

  ActiveX controls
  ActiveX documents
  Code components (OLE automation servers)

Let’s take a look at these types now.

ActiveX Controls

We have seen ActiveX controls throughout the book—those are the controls you can add to the Visual Basic toolbox using the Components dialog box. You can add those controls to a Visual Basic program like any other control. You can also use ActiveX controls on the Internet, embedding them in your Web pages, as we’ll see when we work on creating ActiveX controls. ActiveX controls can support properties, methods, and events.

Your ActiveX control can be built entirely from scratch (in other words, you’re responsible for its appearance), it can be built on another control (such as a list box), or it can contain multiple existing controls (these ActiveX controls are said to contain constituent controls). Visual Basic ActiveX controls are based on the Visual Basic UserControl object. When you create an ActiveX control, you create a control class file with the extension .ctl. Visual Basic uses that file to create the actual control, which has the extension .ocx. After you register that control with Windows (you can use Windows utilities like regsvr32.exe to register a control, as we’ll see in this chapter), the control will appear in the Visual Basic Components dialog box, ready for you to add to a program. You can also use these controls in Web pages.

ActiveX Documents

ActiveX documents are new to many programmers, but the idea is simple. Instead of restricting yourself to a single control in a Web page, now you can create the whole page. ActiveX documents can include as many controls as any other Visual Basic program, and as we’ll see when we start creating ActiveX documents, the result is just like running a Visual Basic program in your Web browser or other application.

Visual Basic ActiveX documents are based on the Visual Basic UserDocument object. When you create an ActiveX document, you save it with the extension .dob. Visual Basic uses that DOB file to create the EXE or DLL file that holds the actual code for the ActiveX document. In addition, Visual Basic produces a specification file, with the extension .vbd, that describes the ActiveX document, and it’s that file that you actually open in the host application, such as the Microsoft Internet Explorer. With ActiveX documents, you can let users save data (using the PropertyBag property); that data is stored in the VBD file.

Code Components

Code components were formerly called OLE automation servers. These objects let you use their code in other programs. For example, you might have a calculation routine that you expose in a code component; doing so makes that routine available to other programs. Code components can support properties and methods. We’ll see more about code components in Chapter 27.

If you take a look at the kind of ActiveX components you can build with Visual Basic in the New Project window, you’ll see all kinds:

  ActiveX document DLL, ActiveX EXE
  ActiveX control
  ActiveX EXE, ActiveX DLL (these are code components)

There’s still quite a confusion of terms here—what’s the difference between a DLL and EXE ActiveX component? Let’s explore further.

In-Process Vs. Out-Of-Process Components

If an ActiveX component has been implemented as part of an executable file (EXE file), it is an out-of-process server and runs in its own process. If it has been implemented as a dynamic link library (DLL file), it is an in-process server and runs in the same process as the client application.

If your ActiveX component is an out-of-process server, it is an EXE file, and can run standalone. Applications that use in-process servers usually run faster than those that use out-of-process servers because the application doesn’t have to cross process boundaries to use an object’s properties, methods, and events.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.