![]() |
|
|
Published: Wednesday, September 16, 1998
Introduction:
You may have seen a number of ActiveX controls already being used on the Internet. MSNBC.com, The Zone (http://www.zone.com), and other (mostly Microsoft-run sites) employ ActiveX technology. ActiveX controls are "packaged" in CAB (cabinet) files, which are downloaded from the web site you are visiting if you do not already have the ActiveX control installed. Of course no one wants an executable automatically downloaded and run on their machine, so a number of prompts can be displayed. If the control has been "digitally signed" by a third-party signer, then you will see a prompt informing you that the control in question is safe for executing. If the control has not been signed, you will see a prompt informing you that the control may not be safe to run. To ensure your users see a "Safe to Download" prompt, you must "licence" the ActiveX control. I will fully explain this process later on in the article. As I said before, ActiveX controls are similar to Java Applets, but there are some distinct differences too. Java Applets are supported on more browsers than ActiveX controls. Java Applets also provide a more secure interface between the client and server. (For more information, read the Java Applet article.) Due to the increased security, however, Java Applets run noticably slower than ActiveX controls. In this article, I intend to step you through the process of creating an ActiveX control using VisualBASIC 5.0. We will create a simple control and implement it on a web page. Lastly, we will used a pre-signed ActiveX control, and I will demonstrate the "licenced" prompt.
Creating an ActiveX Control: Now we will drag and drop out controls onto our canvas, and write code to handle the events that these controls fire. This is very similar to placing controls on a standard form. I have chosen to implement the following ActiveX control for this example: I will create a listbox which will contain a series of first names. When the user clicks on one of the names, a message (depending upon the name clicked) will be printing below the listbox. You can see what my control looks like below.
Now we need to write the code behind the events. The code for this example is quite simple. Here is is in full:
Private Sub lstName_Click()
Private Sub UserControl_Initialize() To test the ActiveX control, we must first go to File / Make ActiveXControl.ocx... This will create the ActiveX control and record it in the registry. Next go to File / Add Project... Choose a Standard EXE Project and click OK. (Make sure this new project is set as the default project.) Next go to Project / Components... and choose to add the new control you made (it will be named the same as your ActiveX control project name). You should now see a new icon in the toolbar. It may be dimmed out; if it is, you need to first close the ActiveX control designer, and the icon should undim. Now, in your new Form for your Standard EXE project, you can create an instance of the new control you just created in the same fashion you create instances of the other, standard controls. You have the same IntelliSense you have with the other controls as well. In a more detailed discussion of ActiveX controls, one could discuss property pages, or ActiveX features (such as aggregation or containment), which must be handled programmatically. However, since we are only creating a very simple control for a simple web page, discussing these topics in depth would be off-topic. Now that you have your new control and .OCX file, let's put it in a web page. You only need to add the following HTML tag to your page to get this to work:
The
If you haven't guessed, this won't work on someone's machine who does not have the control already there and registered (which is everyone else in the world right now, since you just created this control, and assigned it a brand, spanking new class
ID). So, we will need to implement it so that if someone doesn't have the control, their browser will know how to get it. That is where the
will allow a net surfer to download our control. Of course since our control is unsigned, they will get a dialog box which will say something to the effect of, "This site contains an ActiveX control which could be unsafe to run. Do you want to run the c ontrol anyway?" Regardless, though, if nothing else, you have written and implemented your own simple ActiveX control. If you can not see by now, ActiveX controls hold an immense amount of potential in them. You can write very complex, compiled code, and have a visitor's browser execute that code and integrate it as if the functionality you provide is inherent in the web . In fact, we will next look at using a premade, professional ActiveX control, Microsoft's Chart Control 5.0. This control is somewhat bloated and slow, but delivers impressive-looking charts to a web site which can be created dynamically using JavaScri pt or Active Server Pages.
Using Microsoft's Chart Control 5.0: To view the code, please visit this link: MSChart Example. (Since we are not hosting this site on IIS / NT, we cannot run .ASP files. So you will have to imagine what, exactly this looks like. You can view this cont rol and its capabilities using VB. Just go to Projects / Components and add the Microsoft Chart Control 5.0 control.)
Licencing Your ActiveX Control: When software (code) is associated with a publisher's unique signature, distributing software on the Internet is no longer an anonymous activity. Digital signatures ensure accountability, just as a manufacturer's brand name does on packaged software. If an organization or individual wants to use the Internet to distribute software, they should be willing to take responsibility for that software. This is based on the premise that accountability is a deterrent to the distribution of harmful code.(Thank to alert 4Guys reader Spike for providing this quote and clarification on the signing process...)
Once you have this signed .OCX or .CAB file, you need to add a Licence file. You should add a licence file regardless, so let's add one to our listbox control example we did above. Slap the Visual Sudio '97 CD 1 into the ol' CD-ROM (or visit http://ww w.microsoft.com and search for LPKTool). Under the directory Vb5.0\Tools\Lpk_tool you will find a program called, not surprisingly, LPK_Tool.exe. Run this file. You should see something similar to the dialog on the right. Simply select the ActiveX con trol(s) you wish to create a licence file for (in this case choose the control you had just created), then click the Add button, and finally the Save and Exit button. You will be prompted to enter a file name.
Once you have this file (it will be about 900 bytes in length or so), you need to copy it to your web server and add these lines of HTML above your
The class ID here must be the class ID specified above. Any other class ID there will cause this not to work. Again, right under these three lines of HTML code should be your
Conclusion:
If you would like to learn more about ActiveX controls, there are many great web sites out there. The best place to start it http://www.microsoft.com/search. Happy Programming!
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
![]() |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||