JS调用ActiveX方法
2014-09-16 10:13
141 查看
手动为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>
首先、在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>
相关文章推荐
- 用js调用ActiveX发outlook的meeting request的方法
- C# ActiveX调用JS函数的便捷方法与思路
- js调用ActiveX(ocx)控件方法
- asp.net中js调用activex的方法提示“该对象不支持此属性或方法”
- js调用activeX插件 报异常:TypeError:对象不支持 属性方法
- 简单ASP.NET AJAX 客户端应用:用JS直接调用WebServices方法
- Js文件中调用其它Js函数的方法
- 学习Altas 笔记[js调用重载的方法出错,如何处理]
- 学习Altas 笔记[js调用重载的方法出错,如何处理]
- vs2005调用js脚本方法总结
- 不用AJAX实现前台JS调用后台C#方法(小技巧)
- 简单ASP.NET AJAX 客户端应用:用JS直接调用WebServices方法
- asp.net 调用JS的方法
- javascript中iframe里面的页面调用父窗口js函数的方法。
- 在使用JS调用Window.close()方法关闭一个窗口是,如何禁止弹出对话窗口?
- 不用AJAX实现前台JS调用后台C#方法(小技巧)
- javascript 如何调用activex的方法和属性
- 学习Altas 笔记[JS简单调用服务端方法]
- .Net中调用Js方法问题归类.
- js入门实例の构造函数\方法的定义和调用\原型对象