Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!:ActiveX Controls
function GetCookie (name)
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg) {
var end = document.cookie.indexOf (";", j);
if (end == -1)
end = document.cookie.length;
return unescape(document.cookie.substring(j, end));
}
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
var m1='';
var gifstr=GetCookie("UsrType");
if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; }
document.write(m1+m2+m3);
Keyword
Title
Author
ISBN
Publisher
Imprint
Brief
Full
Advanced Search
Search Tips
Please Select
-----------
Components
Content Mgt
Certification
Databases
Enterprise Mgt
Fun/Games
Groupware
Hardware
IBM Redbooks
Intranet Dev
Middleware
Multimedia
Networks
OS
Prod Apps
Programming
Security
UI
Web Services
Webmaster
Y2K
-----------
New Titles
-----------
Free Archive
To access the contents, click the chapter and section titles.
Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!
(Publisher: The Coriolis Group)
Author(s): Peter G. Aitken
ISBN: 1576102815
Publication Date: 08/01/98
function isIE4()
{
return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') );
}
function bookMarkit()
{
var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0";
parent.location.href=url;
//var win = window.open(url,"myitk");
//if(!isIE4())
// win.focus();
}
Search this book:
Previous
Table of Contents
Next
Part 4Programming For The Internet
Chapter 17ActiveX Controls
With Visual Basic you can create your own ActiveX controlssoftware components you can use in program development and on the Web.
ActiveX is one of the most heavily hyped terms in his-toryand with the Microsoft juggernaut behind it, you can bet that is some serious hyping. Despite all the hoopla, ActiveX is indeed an important and powerful technology, and if you use or program for Windows, it is something you need to know about. You learned how to create one type of ActiveX component in Chapter 8. In this chapter, we will cover another type, the ActiveX control.
First, you should know that, popular perception to the contrary, ActiveX has nothing specifically to do with the Internet or the World Wide Web. It can be used on the Web (as Ill explain later in the chapter), but that is not the only thingor even the most important thingfor which ActiveX is designed. Confused? Theres good reason if you are. Let me explain.
For a number of years, Microsofts technology for software componentssharing of capabilities between chunks of softwarewas called Object Linking and Embedding (OLE). When the Web began heating up a couple of years ago, the Java language was introduced and attracted a lot of attention because of its capability for creating applets that could be interactively downloaded from the Web. The enormous surge of interest in Java made it clear to Microsoft that it had better join the parade before it missed out on the next big thing.
The response from Microsoft was something called ActiveX. In its first incarnation, ActiveX referred to software components that were created using OLE technology and designed specifically for use over the Web. If you first heard about ActiveX at that time, you would naturally assume that ActiveX and the Web are closely linked. But, as we all know, things change.
I cant tell you why, but I do know that over the past year or so, the term ActiveX has slowly grown to encompass everything that used to fall under the term OLE. In other words, ActiveX no longer refers to Web-specific tools, but to a wide range of technologies for sharing software capabilities. You saw some uses of ActiveX in Chapter 8, where I developed an ActiveX server that exposed certain software objects for use by clients on the same system. That is just one of many ways that a Visual Basic programmer can use ActiveX technology.
ActiveX Controls
An ActiveX control is the same as a standard Visual Basic control in that it provides a prepackaged, reusable software component. Many of Visual Basics intrinsic controls are, in fact, ActiveX controls (a few use the older technology called OCX controls). ActiveX controls usually provide some sort of visual interface element, but this is not a strict requirement.
An ActiveX control is unique in its ability to be contained within something else. A familiar example is a control contained within a Visual Basic form. ActiveX controls are not limited to Visual Basic, however. More and more Windows development tools support ActiveX; some well-known examples are Delphi, Visual C++, and PowerBuilder. Although these tools differ from Visual Basic in many respects, they share the ability to drop ActiveX controls onto a form, providing all of the controls functionality, with little or no programming.
Of course, as a programmer, you need to be able to create ActiveX controls, not just use them. Using ActiveX controls is not a major challenge: From the Visual Basic programmers perspective, they closely resemble non-ActiveX controls. In both cases, the control appears in the Visual Basic toolbox; it has properties, methods, events, and so on. For example, the Check Box control is an old-fashioned OCX control, while the TreeView control is an ActiveX control. ActiveX controls do have capabilities not found in the older OCX controls, but these features are not immediately obvious.
Creating an ActiveX control is a relatively simple task in Visual Basic. For the most part, the procedure is the same as creating a standard Visual Basic executable. You start with a form, place controls on it (including other ActiveX controls), and then write code to define properties and methods and to deal with events. When you compile the project to an OCX file, Visual Basic takes care of all the details. And yes, ActiveX controls are saved in files with an .OCX extension, just as the older OCX controls. The Windows registry makes information about the capabilities of a given OCX file available to potential container programs.
An ActiveX control does not have to contain other controls. You can draw the control using Visual Basics various graphics methods, such as Line and Circle (as covered in Chapter 12).
Creating An ActiveX Control
In this section, I will take you through the process of creating, testing, and using an ActiveX control. The control will be relatively simple, as my goal is to present the procedures that are specific for creating ActiveX controls. What goes in the control does not differ from regular Visual Basic programming. In other words, the functionality of an ActiveX control is created in essentially the same way as the functionality of a standard Visual Basic executableyou place controls on a form, write event procedures, manipulate properties, and so on. Youll also find some elements in common with creating other ActiveX objects (as you learned in Chapter 8), specifically the use of property procedures to define properties for your object (in this case, the control you are creating).
What will the demonstration control do? Its name, FancyCmdButton, describes it well. It will serve the same function as a regular Visual Basic Command Button, which the user can click on to trigger an action. It will have a slightly more appealing appearance: a colored background that changes to indicate that it has been clicked. Most ActiveX controls are significantly more complicated than this. However, our example is ideal for demonstrating the major parts of creating and testing an ActiveX control.
Many of the procedures involved in creating our ActiveX control could be performed using the Class Builder utility you learned about in Chapter 6. I am going to work through each step without using the utility, because it will be a better way for you to learn the nuts and bolts of creating an ActiveX control. Once you understand the procedure, then you can use the Class Builder utility for your future projects to save time and effort.
Start by firing up Visual Basic and selecting New Project from the File menu. Select ActiveX Control from the available project types. Visual Basic starts the new project and adds a UserControl designer to it. (A UserControl object is the foundation of all ActiveX controls you create in Visual Basic.) Your screen will look like Figure 17.1.
Figure 17.1 The Visual Basic screen after starting a new ActiveX control project.
You should note the following elements:
The UserControl Designer window displays the default project name (Project1) and control name (UserControl1) in its title bar. This will change once we assign meaningful names to the project and control.
The gray rectangle in the window represents the new control. It is similar to a standard Visual Basic form in some respects, but it does not have a border or title bar (although you can add a border).
The Form Layout window does not show the control. The controls display position is determined by its container, not by any properties you set during design.
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. Read EarthWeb's privacy statement.
Wyszukiwarka
Podobne podstrony:
17 01SEPA Selección de problemas Eladio Barreda, 17 01 2 01617 01 Identyfikacja zagrozenW 3 RUCHY WIELOSTAWOWE (17 01 2010)Hits Cocktail Vol 1 (17 01 2015) Tracklista17 01 S1 W Geom wykr17 01 S1 W Geom wykrczapelski SzNP 17 01wykład 12 17 01 2013TI 01 04 17 T B pl 05 01 17 praTI 01 05 17 T B pl(2)TI 01 04 17 T pl(1)więcej podobnych podstron