web中调用ActiveX方法

手动为ACTIVEX添加可用于JS调用函数或参数

首先、在ODL文件中添加以下:

  [ uuid(68F8EAFF-2E62-4964-8B1B-413B21F4342D),

      helpstring("Dispatch interface for MyActiveX Control"), hidden ]

    dispinterface _DMyActiveX

    {

         properties:

              // NOTE - ClassWizard will maintain property information here.

              //    Use extreme caution when editing this section.

              //{{AFX_ODL_PROP(CMyActiveXCtrl)

             

              //}}AFX_ODL_PROP

 

         methods:

              // NOTE - ClassWizard will maintain method information here.

              //    Use extreme caution when editing this section.

              //{{AFX_ODL_METHOD(CMyActiveXCtrl)

             

              //}}AFX_ODL_METHOD

              //{{AFX_ODL_METHOD(CMyActiveXCtrl)

              [id(3)] void exit();

 [id(4)] void startShare();

              //}}AFX_ODL_METHOD

             

    };

第二、在CMyActiveXCtrl.h文件中添加以下代码:

   // Message maps

    //{{AFX_MSG(CMyActiveXCtrl)

         // NOTE - ClassWizard will add and remove member functions here.

         //    DO NOT EDIT what you see in these blocks of generated code !

    //}}AFX_MSG

    DECLARE_MESSAGE_MAP()

 

// Dispatch maps

    //{{AFX_DISPATCH(CMyActiveXCtrl)

         // NOTE - ClassWizard will add and remove member functions here.

         //    DO NOT EDIT what you see in these blocks of generated code !

         afx_msg void exit();

         afx_msg void startShare();

    //}}AFX_DISPATCH

    DECLARE_DISPATCH_MAP()

第三、在CMyActiveXCtrl.cpp中添加

   

 

BEGIN_DISPATCH_MAP(CMyActiveXCtrl, COleControl)

    //{{AFX_DISPATCH_MAP(CMyActiveXCtrl)

    // NOTE - ClassWizard will add and remove dispatch map entries

    //    DO NOT EDIT what you see in these blocks of generated code !

    DISP_FUNCTION(CMyActiveXCtrl, "exit", exit, VT_EMPTY, VTS_NONE)

    DISP_FUNCTION(CMyActiveXCtrl, "startShare", startShare, VT_EMPTY, VTS_NONE)

    //}}AFX_DISPATCH_MAP

END_DISPATCH_MAP()

 

第四、在CMyActiveXCtrl.cpp中添加函数实现代码

    void CMyActiveXCtrl::exit(){

              m_MainDlg.exit();//调用 主对话框中的exit函数

}

 

void CMyActiveXCtrl::startShare(){

           m_MainDlg.startShare();//调用主对话框中的函数

}

 

第五、在htm文件中添加以下代码实现:

   <HTML>

<HEAD>

<TITLE>共享</TITLE>

</HEAD>

<BODY >

<script language="javascript">

      function document.body.onunload()

      {

          //alert("退出吗?");

         try{

             document.getElementByIdx("MyActiveX1").exit();

          }catch(e){

            alert(e.toString());

          }

      }

      function document.body.onload()

      {

          try{

             document.getElementByIdx("MyActiveX1").startShare();

          }catch(e){

            alert(e.toString());

          }

       }

</script>

 

<OBJECT ID="MyActiveX1" WIDTH=1280 HEIGHT=1074

 CLASSID="CLSID:ABAD1B64-CD91-4839-ABE6-BAE82CC3E6F7" codebase="Release/MyActiveX.ocx#version=1,0,0,5"VIEWASTEXT>

    <PARAM NAME="_Version" VALUE="65536">

    <PARAM NAME="_ExtentX" VALUE="24871">

    <PARAM NAME="_ExtentY" VALUE="18486">

    <PARAM NAME="_StockProps" VALUE="0">

</OBJECT>

 

</BODY>

</HTML>

来源:http://blog.sina.com.cn/s/blog_4b05c7150100exxl.html

粗浅理解,还望同学们指正。

欢迎阅读相关文章:http://hi.csdn.net/linchengzhi

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值