Sams Teach Yourself Visual Basic 6 in 24 Hours

Sams Teach Yourself Visual Basic 6 in 24 Hours

By Greg Perry

ActiveX: The Tools You Use

In Hour 12, "Dialog Box Basics," you learned how to add the Common Dialog Box control to Visual Basic's Toolbox window. In Hour 19, "Toolbars and More Graphics," you added additional tools to produce a toolbar and an image list. The tools that you added are examples of ActiveX controls.

An ActiveX control is a control you can add to Visual Basic's Toolbox window. If the Toolbox window doesn't contain the control you need, you might find an ActiveX control that suits your purpose, and you can add that control to the Toolbox window for use in your application.

All the controls you find in Visual Basic's Components dialog box (shown in Figure 21.1) are ActiveX controls. You might never use all the controls, but some you'll use many times (such as the Toolbar control). Depending on your version of Visual Basic, you may see more or fewer controls.

21fig01.gif

Figure 21.1 Visual Basic comes with many ActiveX controls.

Previous versions of Visual Basic supported these extra controls, but Visual Basic used to work only within a 16-bit environment. Therefore, the tools the Visual Basic programmers used were 16-bit tools called VB custom controls. A custom control was a control you added to your Visual Basic Toolbox window to gain additional power.

As the need for tools grew and as other programming platforms such as Visual C++ began requiring such extra tools, these other platforms began supporting the use of VB custom controls. If a Visual C++ programmer wanted a Text Box control, he had to locate a Visual Basic Text Box control file and add the text box to Visual C++'s development environment. (Those C++ programmers are always playing catch-up to Visual Basic programmers!)

Encapsulation refers to a package of data and code that works like a small program. A control is encapsulated.

Soon, shortcomings of the VB custom controls began surfacing and their capability for taking advantage of new technology, such as 32-bit operating environments, became obvious. Microsoft developed a new control standard called OCX controls. One of the nice things about VB custom controls was their capability to work between and inside several programs even if the programs that used them weren't Visual Basic programs. The controls were encapsulated so that the programming language only needed to know the properties, methods, and events supported by the controls to use the controls. The OCX controls, so called because of their .ocx filename extensions, kept all the advantages of 16-bit controls but also worked inside the 32-bit environment.

OLE (short for Object Linking and Embedding) refers to the process of inserting linked and embedded objects in one application that another application created.

Along the way, the distinction between OLE and OCX controls became blurred. An OLE process used a custom control to do its job, and the OCX controls further refined the OLE process so that a programmer could embed a complete application written in Visual Basic inside a Visual C++ program. In addition, the user could even drag an Excel worksheet into a Word document, and that worksheet not only became another data item inside the document, but also the worksheet was active; when the user clicked the worksheet, Excel's menus appeared in place of Word's. That Excel worksheet was nothing more than an advanced OCX control.

ActiveX controls are OCX controls that take these drag-and-drop and drop-into-code concepts even further. An ActiveX control can appear on a Web page for anyone to use (if the page is ActiveX-enabled and the user's browser is also; most Web browsers are ActiveX-enabled today). In other words, if a Web page contains an ActiveX control, even if that control is a complete Visual Basic application turned into an ActiveX control (no size limitation for controls exists), the users who view the Web page see the application and interact with it as if they were running it from their own hard disk. ActiveX controls took the concept of OCX controls to the Internet. Now, if you want a special tool such as a command button on your Web page, you can just place an ActiveX command button control on the Web page during the page's development, and your page's users will be able to click the command button.

Don't throw out your Visual Basic programming language skills just yet, however. The ActiveX control as a total solution is still theory and is only partially available and working today in reality. Your Visual Basic skills are not only going to be needed in the future as ActiveX controls gather steam, but your Visual Basic programming skills are going to be needed even more as companies retool their applications and turn applications into such controls.

Share ThisShare This

Informit Network