Share via


How to: Access ActiveX Controls and Objects

You can use any ActiveX control that is available on your computer. To use an ActiveX control, you add it to a form, then set its properties, write handlers for its events, or call its methods. You can add an ActiveX control to a form using the Form Controls toolbar or the OLE Container Control, or by using code. For details about adding an ActiveX control in the Form Designer, see Sharing Information and Adding OLE.

You can create an ActiveX control in code in much the same way you would create any Visual FoxPro control. However, before creating the control you must determine the name of the control's class library, which is stored in the Windows registry. If you have no other way to determine the class library name, use the Form Designer to create the control (as described in the previous section), and then get the control's OLEClass property.

ActiveX objects can be created directly with CREATEOBJECT( ), and don't require an instance of a form.

To create an ActiveX control in code

  1. Call CREATEOBJECT( ) Function to create a form.

  2. Call the new form's AddObject Method to add the control, specifying olecontrol as the class. You must pass the control's class library name as the third parameter of the AddObject method.

For example, the following program creates a new form and adds a listview control to it:

oMyForm = CREATEOBJECT("form")
oMyForm.AddObject("oleListview","olecontrol", ;
   "MSComctlLib.ListViewCtrl")

After you've created the form and control, you can display the form by calling its Show method, and display the control by setting its Visible property to true:

oMyForm.oleListview.Visible = .T.
oMyForm.Show

Some ActiveX controls aren't designed primarily to be used interactively by a user. For example, a timer control doesn't support methods for user interaction. Even then, you can still create the control on a form because the control will usually make available a default visible component, such as an icon. Frequently you will not be able to change or resize the icon.

If you don't want your application to display the icon for non-interactive controls, you can hide the control by setting the Visible property of its OLE container control to false, or set its Left property to a negative value (such as –100) that moves it off the visible portion of the screen. Alternatively, you can place the control on a form that's never made visible (that is, for which the Show method is never called). In all cases, you can still call the control's methods as if the control were visible.

See Also

Tasks

How to: Access Dynamic-Link Libraries

How to: Access a Visual FoxPro Library

Concepts

Accessing External Libraries

Reference

CREATEOBJECT( ) Function

Other Resources

Extending Visual FoxPro with External Libraries

Accessing the Visual FoxPro API

Sharing Information and Adding OLE