手动为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