| Topic: Creation of User Defined ActiveX Control So far we have been using the ActiveX Controls which come along with the Professional Edition of VB-6. We have said that the greatest power if VB-6 is its capacity to create user defined ActiveX controls which can be used for building complex applications. We have also pointed out that one can visualize a scenario, when every complex application will be encapsuled in a single ActiveX control. In this lesson we will see how one can go about building one’s own ActiveX control. Building a Picture ActiveX Control: The Picture ActiveX Control is intended to print pictures in a Picture box selecting bmp or ico or gif files by searching the directories.
Private Sub File1_DblClick() Private Sub Dir1_Change() Private Sub Drive1_Change() Figure 2a
Containers for placing ActiveX Controls: ActiveX controls can be placed in any of the following four containers.
1. ActiveX control placed in VB Design Form: Open the Standard EXE Design Form. At the bottom of the Toolbox, you must be able to find the icon by name rform for the new ActiveX control you have created.. If you don’t find it, open the component menu by clicking component from project menu. You will find the ocx file by name rproj as shown in the figure 3. Select it and click OK. The icon by name rform will appear at the bottom of the toolbox. Drag the new ActiveX control in the design form and size it so that all its components are clearly visible as shown in the figure 4. Save the form as rrform and the project as rrproj. Select start from the Run menu. Now you can vary the drive, the directory and the files in the Run Mode.. Select a gif file and double click it. You will get the corresponding image loaded in the picture box as shown in the figure 5.
2. ActiveX Control placed in ActiveX Control Pad: Open the Microsoft ActiveX Control Pad from the Program List. It will present a blank HTML form . Select ‘insert’ from the Edit menu. You will get the list of ActiveX Controls in the alphabetical order as shown in the figure 6. Click the control rproj.rform. The control window and the property window will appear on the screen as shown in the figure 7. Close the two windows. You will find the code for the ActiveX control written between two object tags as shown in the figure 8. Save the html file as rr.htm in the desktop directory. Close the ActiveX control pad. Click the icon rr which you see in the opening window. Immediately Internet Explorer will be opened and give a warning message ‘An ActiveX object on this page may be unsafe. Do you want to allow it to be initialize and be accessed by script’. Press Yes. The ActiveX control in dynamic mode will be displayed in it. You can now play with the directories and files and display an image in the picture box as shown in the figure 9.
3. Placing the ActiveX Control in the Microsoft Excel 97: . Open Microsoft Excel Worksheet. From the View menu select Toolbars item. Then select Control Toolbox option. The control box will appear, floating over the spreadsheet. At the bottom of the control box, you will see an icon with a crossed hammer and wrench. If you click this icon the ActiveX component Menu will appear. Select the item rproj.rform. The menu will disappear and the cursor becomes a crosshair and will allow you to draw the ActiveX control on the Spreadsheet. Exit from the design mode by clicking on the Design Mode Icon which appears in the beginning of the control box. The ActiveX control becomes dynamic. You can select a gif file and display it in the picture box as shown in the figure 10
4. Placing the ActiveX control in the Microsoft Word 97 Document: Open Microsoft Word and open a blank document. From the view menu select Toolbars and then Control Toolbox. You will get a menu of ActiveX controls. Select the Control ‘rproj.rform’. Exit Design mode by clicking on the design mode icon from the tool box. The ActiveX control form appears in the dynamic mode. Now you can change the directories, drives and files. Select a bmp file or gif file and display it as shown in the figure 11
1.Microsoft ActiveX Control Test Container: A new utility called the ActiveX Control Test Container has been included in VB-6. This tool allows you to load an ActiveX control that you have created in order to test. From the start up menu select Microsoft Visual studio->Microsoft Visual Studio 6.0 Tools->ActiveX Control Test Container as shown in the figure 12. You will be presented with a blank ActiveX Test Container window as shown in the figure 13. Select Edit->Insert New Control. You will get a list of ActiveX Controls as shown in the figure 14. Select rproj.rform. The ActiveX control becomes active and you can select a gif file for display as shown in the figure 15. You can insert the Calendar Control and you will find that the calendar becomes dynamic.
|