Importing ActiveX Controls

See Also

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:

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

  1. Click the Start button, and then click Run.

  2. 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

  3. 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

  1. On the File menu, click New Project.

  2. On the New tab, expand the Visual J++ Projects folder, click Applications, and then click the Windows Application icon.

  3. In the Name box, type a name for your project.

  4. In the Location box, type the path where you want to save your project, or click Browse to navigate to the folder.

  5. Click Open.

    A collapsed view of your project appears in Project Explorer. (If Project Explorer is not visible, click Project Explorer on the View menu.)

  6. In Project Explorer, expand the project node.

    A file with the default name of Form1.java has been added to your project.

  7. 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 Customize Toolbox 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

  1. In the Toolbox, click the General tab. (If the Toolbox is not displayed, click Toolbox on the View menu.)

  2. Right-click the Toolbox, and then click Customize Toolbox.

  3. In the Customize Toolbox dialog box, click the ActiveX Controls tab.

  4. In the list of ActiveX controls, select the control that you want to import. You can select multiple controls.

    For this scenario, select ActiveMovieControl Object.

  5. 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

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

  1. In the Forms Designer, select the ActiveMovie control.

  2. In the Properties window, select the filename property.

  3. 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

  1. On the Build menu, click Build.

    If you receive any compilation errors or messages, correct the errors and rebuild your project.

  2. To run the form, on the Debug menu, click Start.

  3. When the form appears, click the play button on the control.

    The movie that you specified in the filename property is displayed.