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
- The ActiveX Control Pad is freely available for downloading from the authoring tools section in the MSDN Online Web Workshop at https://msdn.microsoft.com/workshop/misc/cpad/default.asp. Follow the online instructions for installation.
To insert CIRC
Download the CIRC sample files from MSDN and build the DLL (Circ31.dll).
Start ActiveX Control Pad. It opens with a default HTML document, including head and body tags.
On the Edit menu, click Insert ActiveX Control.
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.
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
Start ActiveX Control Pad and open the file created in the procedure To Insert CIRC, if it is not already open.
On the Tools menu, click Options, and then click Script.
In the Script Options dialog box, select Visual Basic Scripting Edition as the Default Script Language and click OK.
From the Tools menu, click Script Wizard.
Steps 5 and 6 are performed in the Script Wizard dialog box.
In the Select an Event list, click Window, and then click Load to add code to run when the control is loaded.
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 -->
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
Start ActiveX Control Pad and open the file created in the procedure To Insert CIRC, if it is not already open.
On the Tools menu, click Options, and then click Script.
In the Script Options dialog box, select JScript as the Default Script Language and click OK.
From the Tools menu, click Script Wizard.
Steps 5 and 6 are performed in the Script Wizard dialog box.
In the Select an Event list, click Window, and then click Load to add code to run when the control is loaded.
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() -->
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.