Accessing 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 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( ) 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 an outline control to it:

oMyForm = CREATEOBJECT("form")
oMyForm.AddObject("oleOutline","olecontrol", ;
   "MSOutl.Outline")

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

Access to External Libraries | Accessing Dynamic-Link Libraries | Accessing a Visual FoxPro Library | Extending Visual FoxPro with External Libraries | Accessing the Visual FoxPro API | Adding OLE | CREATEOBJECT( )