Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
ActiveX controls can provide a number of enhancements to your Windows Foundation Classes (WFC) applications. A number of third-party ActiveX controls are available to add features, such as custom button shapes, telephony technology, charting, graphing, and spreadsheets. You can use Visual J++ to import ActiveX controls using a process similar to importing COM objects.
In this scenario, you import the Microsoft ActiveMovie control that is installed with Microsoft Internet Explorer version 4.0. You will learn:
How to register an ActiveX control in the system registry.
How to create a project to use when importing an ActiveX control.
How to import the ActiveX control into a project.
How to add an ActiveX control to a form and set its properties.
How to build and run the project to test the ActiveX control.
Registering a Control
So that your ActiveX control is available to Visual J++, you must register it in the system registry.
Note In this scenario, you do not need to register the ActiveMovie control because it is registered when Internet Explorer is installed.
To register an ActiveX control
Click the Start button, and then click Run.
In the Open box, type:
Regsvr32.exe <control path and filename>
where <control path and filename> is the path and file name of your control. For this scenario, type:
Regsvr32 C:\Windows\System\AMOVIE.OCX
Click OK.
If you receive a message that the registration failed, ensure that the path to the control is correct and that the file exists.
Creating a WFC Project
When importing an ActiveX control, Visual J++ creates package directories in your project and adds the class wrappers used to access the ActiveX control in those package directories. Therefore, you must have a valid WFC project to import an ActiveX control.
To create a WFC project
On the File menu, click New Project.
On the New tab, expand the Visual J++ Projects folder, click Applications, and then click the Windows Application icon.
In the Name box, type a name for your project.
In the Location box, type the path where you want to save your project, or click Browse to navigate to the folder.
Click Open.
A collapsed view of your project appears in . (If Project Explorer is not visible, click Project Explorer on the View menu.)
In Project Explorer, expand the project node.
A file with the default name of Form1.java has been added to your project.
To open your form in the Forms Designer, double-click Form1.java in Project Explorer.
Importing an ActiveX Control
After you have created the project, you can then import the ActiveX control into the project. Use the dialog box to select the ActiveX control from a list of ActiveX controls that are installed on your system.
Note Once you have added an ActiveX control to the Toolbox, the control remains in the Toolbox for all other projects until you remove it.
To import an ActiveX control
In the Toolbox, click the General tab. (If the Toolbox is not displayed, click Toolbox on the View menu.)
Right-click the Toolbox, and then click Customize Toolbox.
In the Customize Toolbox dialog box, click the ActiveX Controls tab.
In the list of ActiveX controls, select the control that you want to import. You can select multiple controls.
For this scenario, select ActiveMovieControlObject.
Click OK.
The controls that you selected are added to the Toolbox.
Adding the Control to a Form
When you add the ActiveX control to a form, Visual J++ creates one or more packages in your project directory and adds class wrappers for the control. The class wrappers are used by Visual J++ to access the classes and members of the ActiveX control. If the ActiveX control you are importing is contained in a file that contains multiple ActiveX controls, Visual J++ will provide class wrappers for all controls in the file but adds only the specified control to the Toolbox.
To add the ActiveX control to a form
With a form displayed in the Forms Designer, double-click the control that you want to add.
For this scenario, double-click the ActiveMovie control. The control is added to the center of the form.
Setting the Control's Properties
After you have added the ActiveX control to a form, you can use the Properties window to set properties and create event handlers.
To set the properties for the ActiveMovie control
In the Forms Designer, select the ActiveMovie control.
In the Properties window, select the filename property.
Type the path and file name of an .avi file to display in the control.
–or–
Click the ellipsis button in the value section of the filename property to display a dialog box to browse for a file on your computer.
Building the Project
After you have added the ActiveX control to a form and set its properties, you build and run the project to test the control's functionality.
To build and run the form
On the Build menu, click Build.
If you receive any compilation errors or messages, correct the errors and rebuild your project.
To run the form, on the Debug menu, click Start.
When the form appears, click the play button on the control.
The movie that you specified in the filename property is displayed.