Although previous chapters have demonstrated how to create a control using other controls and how to use constituent controls properties, events, and methods in your UserControl, a few issues remain.
You understand how to use constituent controls, but how do you know what controls are available? And if the controls provided by the Windows operating system and Visual Basic donÕt quite fit the bill, where can you turn to uncover more options? This chapter answers those questions.
Inherent controls are controls that exist as part of Windows.
These controls exist on every users machine and are generated
in Visual Basic by the VB run-time module you distribute with
every VB application you create. Consequently, inherent controls
do not have OCX files.
NOTE |
If youre a seasoned Visual Basic veteran but you havent used VB in a while, note that the number of inherent controls has increased since the release of Windows 95 and Windows NT 3.5. These controls are the ImageList, ListView, ProgressBar, RichTextBox, Slider, StatusBar, TabStrip, Toolbar, and TreeView controls. |
Here is a complete list of inherent controls in Visual Basic 5.0:
The OLE container control does not appear in this list because while you can use an OLE container control in an EXE project, you cant use the OLE container control as a constituent control in your application, so distributing it is not an issue.
In addition to using inherent controls, you can use OLE controls (known as OCX controls) that predate the current ActiveX specification as constituent controls in your control project. So you can draw on the large market of third-party Visual Basic control vendors to provide constituent controls for your control projects, whether or not the vendor has positioned their controls as being explicitly ActiveX or not. The rule is: if its a 32-bit OCX control, it should work in Visual Basic 5.0.
See Locating Commercial Controls later in this chapter for information on third-party control vendors.
Occasionally you may wish to perform an action on all the constituent controls in your UserControl. To do this, you can use a With block with the controls collection. Here is an example of how this works:
Figure 8.1 : Multilabel control designer.
Private Sub UserControl_Click() Dim c As Control For Each c In UserControl.Controls c.Caption = "Changed" c.BackColor = &H808000 Next End Sub
You can see from this demonstration that you can use a For Each block to iterate through all of the constituent controls in your UserControl. You can use this same technique to apply changes to all the controls in your UserControl no matter how many controls your control project contains.
The code for this example is on the CD-ROM that accompanies this book.
There is no reason why you cant take existing ActiveX controls and extend their functionality by making them constituent controls of your controls. The problem with doing this is the same problem you face when you use an ActiveX control to begin with: when you use a third-party custom control, you put yourself at the mercy of the developer who created it. Be sure to bear this in mind before adding dozens of third-party controls to your project.
For example, lets say your control project uses a third-party ActiveX control designed to handle a number of different graphic formats. If you design your project around this control only to discover late in the project that the control doesnt handle a particular graphic format subtype in quite the way you expected, youll be forced to work around the problem or compromise your projectÕs feature set.
Third-party controls represent project dependencies that you have
little or no control over. This is the case because with controls
you purchase, you usually dont have access to the controls
source code. And even if you had access to the controls
source code, theres no guarantee that the control is written
in a language you can deal with (many ActiveX controls are written
in C++).
NOTE |
If youre considering using a third-party control as a part of your control, you may want to instead consider writing your own code to provide the same functionality. Things that seem impossible to do in Visual Basic, such as multimedia and Internet access, can often be accomplished with calls to the Windows API. For more information on this, see Chapter 11, Making Windows API and DLL Calls. |
That said, using a third-party control can save you a great deal of development time, particularly if youre attempting to delve into a complex area of programming.
For example, in Chapter 14, youll see an example of how to create a control project that is capable of sending electronic mail over the Internet. In order to do this with code, youÕd need to know not only the Internet SMTP mail protocol, but the Winsock API that enables a Windows application to send and receive data using the TCP/IP networking protocol (an API that is very poorly documented and very difficult to call from a VB perspective).
Using a constituent control resolves all those problems by wrapping them up in a programming paradigm that is easy to understand and consistent.
Whenever you use a commercial, third-party control in your Visual Basic application, you must have a license to use it. In most cases, an improperly installed or unlicensed ActiveX control wont be usable in Visual Basic, because the IDE wont let you instantiate a control unless the appropriate licensing information has been inserted into your computers system registry.
But what happens when you purchase an off-the-shelf control from a software vendor, incorporate it into an ActiveX control project of your own, add a few enhancements to it, and redistribute the control to other programmers for their use? Are the other programmersthe users of your new, improved ActiveX controlalso required to have a license for the third-party constituent control?
The answer is yes. The reason is simple: when a software company
grants you a license to redistribute their ActiveX control, theyre
granting you a runtime license, not a design-time
license. If you had the right to redistribute a runtime license,
the control developer would be giving the control away. Thered
be nothing to stop you from writing a wafer-thin wrapper that
exposed 100% of the functionality of the constituent control,
adding nothing new of your own, and reselling the knockoff version
of the control on the street corners of America for $1.98.
NOTE |
Special considerations apply to the issue of licensing when youre sending a control over the Internet. In a nutshell, the license for a control you distribute resides on the Web server, and a temporary copy of the license is passed to each Web browser that encounters it. If your control supports licensing, then users who receive your control through a Web page do not have the ability to use your control at design time, unless they have purchased and installed a licensed copy of your control. For more information on licensing Web-distributed controls, see Chapter 13, Using Your Control On The Web. For information on how to add licensing to controls you create, see Chapter 12, ÒDistributing Your Control.Ó |
There are a number of companies that specialize in selling ActiveX components; many of these companies have been around for years, having built their businesses on the 16-bit VBX market, switching over to OCXes and ActiveX controls as Microsoft goes through its seemingly annual paradigm revisions.
There are also quite a number of free controls out there. The number of freeware and shareware controls available will undoubtedly increase dramatically now that Visual Basic can be used to create controls.
Many sites permit you to download versions of controls for evaluation before you purchase them. Some of these controls are fully functional, others are demo versions that stop working after a period of time or display a message when they arent fully licensed.
There are a number of Web sites that make information on ActiveX controls available for free. Here is a listing of the best among them, ranked in descending order of indispensability:
The Microsoft Web site, at http://www.microsoft .com/activex/gallery/, is the first place to look for ActiveX resources.
Figure 8.3 : Microsoft ActiveX Gallery.
As of this writing, the site has over 100 controls available for download. Many of them are geared toward use in Web pages, but theyll work in VB applications as well.
Found at http://www.activex.com, this site is the only ActiveX site to rival Microsofts in terms of completeness and ease of navigation. It features a library of downloadable ActiveX controls and Visual Basic utilities divided into categories. It is extremely well-maintained and well-organized.
The site uses ActiveX controls for navigation, and it serves as a good example of how to use ActiveX to enhance your Web site. (The site works perfectly fine with Netscape as well as Internet Explorer.)
CNETs activex.com also contains links to news articles on ActiveX technology from CNETs techie news site, news.com.
Found at http://www.techweb.com/activexpress/, this site has original articles and tutorials on how to use ActiveX technology on the Web, as well as a large download area with links to controls divided into categories. The full-text search feature is fast and easy to use, displaying only ActiveX-related information.
Figure 8.5 : TechWeb ActiveXpress.
Like the CNET site, this site has a link to a daily news section (http://www.techweb.com/activexpress/xnews/xnews.html), that has a new story on ActiveX-related issues every two or three days.
Who is this Dave person and why does he have a Web site (at http://www.davecentral.com/activex.html) devoted to Microsoft development tools? I couldnÕt figure out the answer to that question, but he does have a pretty decent site.
The layout isnt quite as nice as the CNET site, and the number of ActiveX resources isnt nearly as extensive, but the purpose is pretty much the same: provide a library of downloadable software, mainly focusing on Internet-related tools, including ActiveX controls.
The site lets you do keyword searches to look up information but doesnÕt let you search by category or product. This means that when you do a search on the keyword Òdatabase,Ó for example, you get a long list of database products (rather than a list of Visual Basic database products). This can be a bit inundating, but its not impossible to navigate around.
At the time I hit their page (at http://browserwatch.iworld.com/activex.html), their big list of ActiveX controls (at http://browserwatch.iworld.com/activex/activex-big.html) was formatted a little funny and hard to read in MS Internet Explorer. Also, their search engine is confusing and returned way too much information. I got a few crazy error messages when performing searches, and it never returned anything useful.
Figure 8.7 : BrowserWatch ActiveX Arena.
The site seems fairly comprehensive, though, containing capsule descriptions of controls broken into categories, so if you dont mind navigating with links instead of a search engine, this is a good resource.
There are a number of resellers that specialize in selling Visual Basic add-ons, including ActiveX controls, that can be used as constituent controls in your control projects. Here (in no particular order) is a list of some retailers specializing in VB components.
1163 Shrewsbury AvenueThe Programmers Paradise Web site offers online ordering. There are a few products that you can purchase online, then download immediately. They also have a fax-back server that can send information on products to your fax machine.
Shrewsbury, NJ 07702-4321
Voice: 800-445-7899
Fax: 908-389-9227
Fax-back (product information): 908-389-8173
Web: http://www.pparadise.com
1905 Powers Ferry Road, Suite 100The VBXtras Web site offers online ordering and downloading of controls. They have a great search engine that enables you to search for products by product name, keyword, category, or vendor. They also provide invariably flattering ÒevaluationsÓ of the controls they sell, which can be helpful, I guess, if youre good at translating from the native Marketingese.
Atlanta, GA 30339
Voice: 1-800-788-4794
Fax: 1-770-952-6388
Web: http://www.vbxtras.com, http://www.xtras.com/activex
1090 Kapp DriveThe VB only Tools Web site permits you to perform keyword searches to find information on products youre interested in. You can download demo versions of some controls, but as of this writing there was no way to order online. They seem a little too proud of the fact that their Web site is rather rudimentary.
Clearwater, FL 34625
Voice: 1-800-GO-BASIC
Fax: 813-461-2743
Web: http://www.zaccatalog.com/VBASIC/VBASIC.HTM
E-mail: sales@zaccatalog.com
This chapter delved deeper into the perils of including constituent controls in the controls you develop. The chapter also provided information resources that should help you locate ActiveX resources you can use in your control.
In the next chapter, youll look at controls you draw yourself, without any constituent controls.