MFC based web ActiveX control development process record 2 (js and ActiveX control call each other)

1. ActiveX control part (JS to ActiveX control)

Continue with the new project in the previous blog, find DActiveXDemo, right-click to add - properties

Add the first parameter to pass the string as follows

You can see that a variable and a property modification event are created in the ActiveXDemoCtrl.h file

Later, I will write the code of parameter passing in the onparsrchanged event. Here we add a text box to the CActiveXDlg dialog box created earlier to display the parameters from js

Then add the corresponding member variable to the text box

Next, we can modify the onparsrchanged code as follows

void CActiveXDemoCtrl::OnparStrChanged(void)

	// TODO: add property handler code here


Then rebuild the project.

2. Web part

Next, modify the html code as follows:

    <TITLE>js Pass parameters to ActiveX control</TITLE>
    <meta http-equiv="Content-Type" content="text/html; charset=GBK" />
    <SCRIPT LANGUAGE="JavaScript">
        function SendToActiveX()
                  if (InputStr.value!="")
                       Test_js.parStr= InputStr.value;


    Please enter the string you want to pass: <INPUT TYPE="text" NAME="InputStr" VALUE="">
    <INPUT TYPE="button" NAME="Biography"
           VALUE="test js Passing parameters: " ONCLICK=SendToActiveX()>


    <OBJECT ID="Test_js" WIDTH=50% HEIGHT=35%
        <PARAM NAME="_Version" VALUE="65536">
        <PARAM NAME="_ExtentX" VALUE="2646">
        <PARAM NAME="_ExtentY" VALUE="1323">
        <PARAM NAME="_StockProps" VALUE="0">

Run html file with IE browser, input the corresponding string and click the button. The effect is as follows

3. Code download

The following is a link to the code (including source code and html file):


Tags: Javascript IE

Posted on Mon, 06 Jan 2020 10:46:26 -0800 by learning_php_mysql