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)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	// TODO: add property handler code here
	m_MyDlg.m_parStr.Format("%s",m_parStr);
	m_MyDlg.UpdateData(FALSE);

	SetModifiedFlag();
}

Then rebuild the project.

2. Web part

Next, modify the html code as follows:

<HTML>
<HEAD>
    <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;
                  }
	
             }


    </SCRIPT>
</HEAD>
<BODY>

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

    <p></p>


    <OBJECT ID="Test_js" WIDTH=50% HEIGHT=35%
            CLASSID="CLSID:B852A7D3-3356-400E-A2BF-A15F7D0F99CB">
        <PARAM NAME="_Version" VALUE="65536">
        <PARAM NAME="_ExtentX" VALUE="2646">
        <PARAM NAME="_ExtentY" VALUE="1323">
        <PARAM NAME="_StockProps" VALUE="0">
    </OBJECT>
    
    
</BODY>
</HTML>

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): https://download.csdn.net/download/qianbin3200896/10586112

 

Tags: Javascript IE

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