Partager via


How Do I Script an ActiveX Control on a Web Page?

An easy way to get started with scripting is by using an HTML authoring tool like Microsoft ActiveX Control Pad. This topic shows how to use ActiveX Control Pad to script CIRC, an MFC control sample.

The ActiveX Control Pad is an authoring tool that lets you add ActiveX controls and scripting (such as JScript and VB Script) to your HTML pages with point-and-click ease. The ActiveX Control Pad also includes the Microsoft HTML Layout Control, which supports windowless controls and provides new layout capabilities based on the HTML extensions proposed by the World Wide Web Consortium (W3C).

To install and run ActiveX Control Pad

To insert CIRC

  1. Download the CIRC sample files from MSDN and build the DLL (Circ31.dll).

  2. Start ActiveX Control Pad. It opens with a default HTML document, including head and body tags.

  3. On the Edit menu, click Insert ActiveX Control.

  4. In the Insert ActiveX Control dialog box, click the CIRC control to add it to the page.

    The control will be displayed in the Edit ActiveX Control window. You should see a rectangular control containing Circ31. Its properties can be set by changing values in the Properties window.

  5. Close the Edit ActiveX Control window.

    The OBJECT tag will be displayed on your HTML page, including the control's class ID and other parameters used to instantiate the control at run time.

Now you are ready to script the control.

To use VBScript to invoke properties and methods on CIRC

  1. Start ActiveX Control Pad and open the file created in the procedure To Insert CIRC, if it is not already open.

  2. On the Tools menu, click Options, and then click Script.

  3. In the Script Options dialog box, select Visual Basic Scripting Edition as the Default Script Language and click OK.

  4. From the Tools menu, click Script Wizard.

    Steps 5 and 6 are performed in the Script Wizard dialog box.

  5. In the Select an Event list, click Window, and then click Load to add code to run when the control is loaded.

  6. In the Insert Actions list, click AboutBox, and click Insert Action. The following code to invoke the AboutBox method is inserted into the HTML file:

    <SCRIPT LANGUAGE="VBScript">
    <!--
    Sub window_onLoad()
    call Circ31.AboutBox()
    end sub
    -->
    
  7. Save the file and open it in a browser. You should see the About box displayed.

To use JScript to invoke properties and methods on CIRC

  1. Start ActiveX Control Pad and open the file created in the procedure To Insert CIRC, if it is not already open.

  2. On the Tools menu, click Options, and then click Script.

  3. In the Script Options dialog box, select JScript as the Default Script Language and click OK.

  4. From the Tools menu, click Script Wizard.

    Steps 5 and 6 are performed in the Script Wizard dialog box.

  5. In the Select an Event list, click Window, and then click Load to add code to run when the control is loaded.

  6. In the Insert Actions list, click AboutBox, and click Insert Action. The following code to invoke the AboutBox method is inserted into the HTML file:

    <SCRIPT LANGUAGE="jscript" FOR="window" EVENT="onLoad()">
    <!--
    Circ31.AboutBox()
    -->
    
  7. Save the file and open it in a browser. You should see the About box displayed.

Using an authoring tool, it is simple to add a control to a Web page and to use scripting to invoke its properties and methods. You can easily attach JScript or VBScript code to buttons on your HTML pages.

See Also

Concepts

Internet Programming Frequently Asked Questions