swt java 内嵌ActiveX控件
这里用的是SWT/JFace开发application中SWT自带的org.eclipse.swt.ole.win32 包可以支持内嵌OLE和ActiveX。
具体用法如下:
//创建一个OleFrame做为OLE(或ActiveX)的框架
OleFrame oleFrame = new OleFrame(this, SWT.NONE);
//创建ActiveX的容器,其中的classID是ActiveX的classid,在注册表中可以找到
OleControlSite oleControl = new OleControlSite(oleFrame, SWT.NONE, “classID”);
//OleAutomation类用来执行ActiveX中的方法
OleAutomation oleAutomation = new OleAutomation(oleControl);
//将ActiveX显示在application中
oleControl.doVerb(OLE.OLEIVERB_SHOW);
调用AcitveX中方法的具体过程:
1、不带参数的方法调用
//获取Method Name的ID,Method Name为ActiveX中具体的方法名
int[] regspid = oleAutomation.getIDsOfNames(new String[] { "Method
Name" });
int dispIdMember = regspid[0];
//方法调用
oleAutomation.invoke(dispIdMember);
2、带参数的方法调用
//获取Method Name的ID,Method Name为ActiveX中具体的方法名
int[] regspid = oleAutomation.getIDsOfNames(new String[] { "Method
Name" });
int dispIdMember = regspid[0];
//设置方法的具体参数。Variant数组的长度为Method
Name方法参数的个数
//假设有四个参数
Variant[] rgvarg = new Variant[4];
rgvarg[0] = new Variant(fileID);
rgvarg[1] = new Variant(itdsURL);
rgvarg[2] = new Variant(idType);
rgvarg[3] = new Variant(reportURL);
//方法调用
oleAutomation.invoke(dispIdMember, rgvarg);
调用OLE Exemple:Java程序内嵌Word应用程序
package test.swt;
import java.io.File;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.ole.win32.OLE;
import org.eclipse.swt.ole.win32.OleClientSite;
import org.eclipse.swt.ole.win32.OleFrame;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Composite;
public class ActiveXTest
{
private Shell sShell = null;
private Button button = null;
private OleClientSite clientSite;
public static void main(String[] args)
{
Display display =
Display.getDefault();
ActiveXTest thisClass = new ActiveXTest();
thisClass.createSShell();
thisClass.sShell.open();
while (!thisClass.sShell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
/**
* This method initializes sShell
*/
private void createSShell()
{
GridData gridData = new GridData();
gridData.horizontalSpan = 2;
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 3;
sShell = new Shell();
sShell.setText("Shell");
sShell.setLayout(gridLayout);
sShell.setSize(new Point(800, 600));
OleFrame frame = new OleFrame(sShell, SWT.NONE);
button = new Button(sShell, SWT.NONE);
button.setLayoutData(gridData);
button.setText("Save");
button.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e)
{
clientSite.save(new File("d:/test.docx"),true);
}
});
frame.setSize(800,600);
clientSite = new OleClientSite(frame, SWT.NONE,"Word.Document.8");
clientSite.setSize(400,400);
clientSite.doVerb(OLE.OLEIVERB_SHOW);
}
}
public class SWT_ActivexUtil {
private OleFrame _frame;
private OleControlSite _site;
private OleAutomation _auto;
SWT_ActivexUtil(String activexId, OleControlSite site){
if(site == null){
Shell shell = new Shell();
_frame = new OleFrame(shell, SWT.NONE);
_site = new OleControlSite(_frame, SWT.NONE, activexId);
_auto = new OleAutomation(_site);
}else{
_site = site;
_auto = new OleAutomation(site);;
}
}
public int getID(String name){
try {
int[] ids = _auto.getIDsOfNames(new String[]{name});
if(ids.length>=0)
return ids[0];
} catch (RuntimeException e) {
e.printStackTrace();
}
return -1;
}
public Variant[] createVariants(String[] paras){
Variant[] vr = new Variant[paras.length];
for(int i=0;i<paras.length;i++){
vr[i] = new Variant(paras[i]);
}
return vr;
}
public Variant getProperty(String prop){
int propId = getID(prop);
Variant v = null;
try {
v = _auto.getProperty(propId);
} catch (Exception e) {
e.printStackTrace();
}
return v;
}
public void setProperty(String name, String... params){
int propId = getID(name);
if(propId < 0)
return;
if(params.length==1)
_auto.setProperty(propId, new Variant(params[0]));
else{
Variant[] vs = new Variant[params.length];
int i=0;
for(String param:params){
vs[i] = new Variant(param);
i++;
}
_auto.setProperty(propId, vs);
}
}
public void setProperty(String name, Variant... params){
int propId = getID(name);
if(propId < 0)
return;
_auto.setProperty(propId, params);
}
public Variant execute(String methodName, Variant... params){
int mid = getID(methodName);
if(mid<0)
return null;
Variant rtnv;
if(params == null)
rtnv = _auto.invoke(mid);
else
rtnv = _auto.invoke(mid, params);
return rtnv;
}
public Variant execute(String methodName){
int mid = getID(methodName);
if(mid<0)
return null;
Variant rtnv = _auto.invoke(mid);
return rtnv;
}
public void addEventListener(int eventID, OleListener listener){
_site.addEventListener(eventID, listener);
}
public void removeEventListener(int eventID, OleListener listener){
_site.removeEventListener(eventID, listener);
}
}

swt java 内嵌ActiveX控件的更多相关文章
- WPF内嵌CEF控件,与JS交互
1)安装cefsharp.winform包 打开VS2017,打开nuget,找到cefsharp.winform,安装 问:为什么wpf程序不使用cefsharp.wpf? 答:因为cefwpf 4 ...
- Web网页中内嵌Activex的Activex插件开发 .
转载自: http://blog.csdn.net/tttyd/article/details/5258096 源代码下载 http://files.cnblogs.com/tttyd/Activex ...
- ActiveX 控件漏洞挖掘之方法
ActiveX是微软公司提出,并在1996年被正式命名的组件技术.该技术提供了一种通用的开放程序接口,使用这种技术开发的ActiveX控件可以直接集成到IE浏览器或第三方应用程序中,但由于第三方编程等 ...
- PluginOK中间件高级版-支持在Chrome、Edge、Firefox等浏览器网页中真正内嵌ActiveX等控件运行的版本已获多家上市公司采购
PluginOK(牛插)中间件(原名:本网通WebRunLocal)是一个实现WEB浏览器(Web Browser)与本地程序(Local Application)之间进行双向调用的低成本.强兼容.安 ...
- ActiveX控件开发
VC2005从开发MFC ActiveX ocx控件到发布到.net网站的全部过程 开篇语:最近在弄ocx控件发布到asp.net网站上使用,就是用户在使用过程中,自动下载安装ocx控件.(此文章也是 ...
- ActiveX控件dsoFramer的使用(word、excel、PPT)
dsoframer是微软提供一款开源的用于在线编辑.调用Word. Excel .PowerPoint等的ActiveX控件.国内很多著名的OA中间件,电子印章,签名留痕等大多数是依此改进而来的. 一 ...
- 浏览器使用ActiveX控件
在IE中使用ActiveX控件,需要使用HTML中的标志是<OBJECT>,该标记几个重要的参数特性有:1.ID:为控件提供一个标识名称,为HTML代码提供一种访问该控件的入口.2.CLA ...
- 常用的Activex 控件
1. Flash Player ActiveX Control 6.0.47.0 与FLASH 6.0配套的浏览器端动画播放插件 download.pchome.n ...
- ActiveX控件是什么?
一.ActiveX的由来 ActiveX最初只不过是一个商标名称而已,它所涵盖的技术并不是各自孤立的,其中多数都与Internet和Web有一定的关联.更重要的是,ActiveX的整体技术是由Micr ...
随机推荐
- git分布式版本控制系统权威指南学习笔记(五):git checkout
文章目录 分离头指针 通过cat可以查看当前的分支 通过branch查看当前分支 checkout commitId(真正的
- XML XPATH simpleXML
XPath 通过DOM结构定位节点,在数据量很大的情况下速度下降的很厉害.解决方法是XPath.Xpath的作用:用于快速定位节点 position()是节点的位置,节点的位置是从1开始 simple ...
- MarkDown 快速开始 上手
*:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...
- 在Windows上安装部署Cuckoo
1. Cuckoo使用的第三方工具及库 Yara:http://plusvic.github.io/yara/ Pydeep:https://github.com/kbandla/pydeep Yar ...
- Linux内核代码布局
上文参考:http://www.cnblogs.com/long123king/p/3545991.html 先分析一下linker script的语法. #ifdef CONFIG_X86_32#d ...
- 自己写Linux module来收集buddy info
1 编写代码pslist.c 1: #include<linux/init.h> 2: #include<linux/module.h> 3: #include<linu ...
- 【AI图像识别一】人脸识别测试探索
****************************************************************************** 本文主要介绍AI能力平台的人脸识别技术的测 ...
- 时间同步服务器NTP搭建
NTP服务器 NTP(Network Time Protocol)[网络时间协议],它是用来同步网络中各个计算机的时间的协议,它可以提供高精准度的时间校正(LAN上与标准间差小于1毫秒, ...
- Spring事务详细解释
前言 Spring在TransactionDefinition接口中规定了7种类型的事务传播行为.事务传播行为是Spring框架独有的事务增强特性,他不属于的事务实际提供方数据库行为.这是Spring ...
- <python基础>python继承机制
子类在调用某个方法或变量的时候,首先在自己内部查找,如果没有找到,则开始根据继承机制在父类里查找. 根据父类定义中的顺序,以深度优先的方式逐一查找父类! class D: def show(self) ...