Here we develop a simple ActiveX EXE with just one form. The name of the ActiveX component is clsActivexEx. The example is chosen to demonstrate the use of
ActiveX EXE in conjunction with Standard EXE. We will develop a Standard EXE later.
The example provided is simple. It works like this: You select either numbers or alphabets in the Main (Standard EXE). The selection (number/alphabet but not
both) is passed on to the ActiveX EXE. Now, in the ActiveX EXE, you select specific number (say "2") or alphabet (say "A"). That specific number or
alphabet is again passed back to the Standard EXE. It is similar to, say, the Standard EXE selects either birds or animals. If the Standard EXE chooses
birds, then the ActiveX EXE can choose any one of a given set of birds. It doesn't have the option to choose any animal (because the Standard EXE already
chosen birds). The selected bird is passed back to the Standard EXE. The example makes it clear as you read on.
1. Open Visual Basic 6.0 - it should be on your start menu if you have just installed it Programs -> Microsoft Visual Basic 6.0 -> Microsoft Visual Basic 6.0
Open an instance of Visual Basic Choose ActiveX EXE and select Open.
Fig: activex-1,Dialog Box showing the type of project to open
Go to the properties of class and change its name property to clsActivexEx.
Add a new Form by using Add Form menu item in the project menu.
Change the name property of form to frmActivexEx and the caption to "Form From ActiveX Exe".
Include the following controls on the form:
cmdSelAndClose Select and close
Open the project properties dialog box by going to Project -> ActivexEx Properties.
Fig. ActiveX-2 Project Properties Dialog Box
In the above figure Project type specifies the type of project that is being developed, in this case the project is of type ActiveX Exe, other project types
can be seen by clicking on the combo box.
"Project Name" specifies the name of the component type library.
You include the ActiveX reference at a later stage in to the Standard EXE. Note that the "Project Description" is the one that appears in "Add Reference" dialog box when it's corresponding component is added.
In this case, startup object is set to "None", as there is no initialization required for this project.
Go to the component tab and check for the following:
"Version Compatibility" by default is of type "Project Compatibility" for all ActiveX Project types.
"Start Mode" is of type "ActiveX Component" by default. Select the "Standalone" option button, only if you intend to start the application as a standalone,
Fig:ActiveX-3, Project Properties Dialog Box
Now, you write the required code. We have added a new Module for placing our code.
Go to Project -> Add Module.
Fig: ActiveX-4; Project menu that used for adding a new Module
Refer to appendix-A for code to be included in Class Module.
Refer to appendix-B for code to be included in Form.
Refer to appendix-C for code to be included in Standard Module.
Use ctrl-F5 to compile and make sure that there are no compilation errors.
From the file menu select Make Activex_ex.exe to make an exe file of this project (which is called reference executable) as shown below: