这里用的是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);
}

}

SWT调用ActiveX简单总结

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控件的更多相关文章

  1. WPF内嵌CEF控件,与JS交互

    1)安装cefsharp.winform包 打开VS2017,打开nuget,找到cefsharp.winform,安装 问:为什么wpf程序不使用cefsharp.wpf? 答:因为cefwpf 4 ...

  2. Web网页中内嵌Activex的Activex插件开发 .

    转载自: http://blog.csdn.net/tttyd/article/details/5258096 源代码下载 http://files.cnblogs.com/tttyd/Activex ...

  3. ActiveX 控件漏洞挖掘之方法

    ActiveX是微软公司提出,并在1996年被正式命名的组件技术.该技术提供了一种通用的开放程序接口,使用这种技术开发的ActiveX控件可以直接集成到IE浏览器或第三方应用程序中,但由于第三方编程等 ...

  4. PluginOK中间件高级版-支持在Chrome、Edge、Firefox等浏览器网页中真正内嵌ActiveX等控件运行的版本已获多家上市公司采购

    PluginOK(牛插)中间件(原名:本网通WebRunLocal)是一个实现WEB浏览器(Web Browser)与本地程序(Local Application)之间进行双向调用的低成本.强兼容.安 ...

  5. ActiveX控件开发

    VC2005从开发MFC ActiveX ocx控件到发布到.net网站的全部过程 开篇语:最近在弄ocx控件发布到asp.net网站上使用,就是用户在使用过程中,自动下载安装ocx控件.(此文章也是 ...

  6. ActiveX控件dsoFramer的使用(word、excel、PPT)

    dsoframer是微软提供一款开源的用于在线编辑.调用Word. Excel .PowerPoint等的ActiveX控件.国内很多著名的OA中间件,电子印章,签名留痕等大多数是依此改进而来的. 一 ...

  7. 浏览器使用ActiveX控件

    在IE中使用ActiveX控件,需要使用HTML中的标志是<OBJECT>,该标记几个重要的参数特性有:1.ID:为控件提供一个标识名称,为HTML代码提供一种访问该控件的入口.2.CLA ...

  8. 常用的Activex 控件

    1. Flash Player  ActiveX Control 6.0.47.0 与FLASH 6.0配套的浏览器端动画播放插件                  download.pchome.n ...

  9. ActiveX控件是什么?

    一.ActiveX的由来 ActiveX最初只不过是一个商标名称而已,它所涵盖的技术并不是各自孤立的,其中多数都与Internet和Web有一定的关联.更重要的是,ActiveX的整体技术是由Micr ...

随机推荐

  1. flutter 小知识

    隐藏控件,占空间 new Offstage( offstage: true, //这里控制 child: Container(color: Colors.blue,height: 100.0,), ) ...

  2. PowerDesigner(数据库迁移)

    PowerDesigner:导出SQL脚本以及问题解决在PowerDesigner中点击DataBase -----------> Generate Datebase -----(可以点击Pre ...

  3. centos7部署汉化版gitlab

    =============================================== 2018/6/5_第7次修改                       ccb_warlock 更新说 ...

  4. CSS:Stacking Context

    通常情况下,HTML页面可以被认为是二维的,因为文本,图像和其他元素被排列在页面上而不重叠.在这种情况下,只有一个渲染进程,所有元素都知道其他元素所占用的空间.z-index属性可让你在渲染内容时调整 ...

  5. 三(2)、springcloud之Eureka集群配置

    1)原理说明** 服务启动后向Eureka注册,Eureka Server会将注册信息向其他Eureka Server进行同步,当服务消费者要调用服务提供者,则向服务注册中心获取服务提供者地址,然后会 ...

  6. 7_springboot2.x开发热部署

    概述:在开发中我们修改一个Java文件后想看到效果不得不重启应用,这导致大量时间花费,我们希望不重启应用的情况下,程序可以自动部署(热部署).有以下四种情况,如何能实现热部署. 1.模板引擎 在Spr ...

  7. ArcGis 字段计算器表达式(Field calculator expression).cal文件与标注表达式(label expression).lxp的实质及其编码方式、解析方法

    ArcGis 字段计算器表达式可以保存为一个扩展名为.cal的文件,该文件的实质是一个文本文件,编码方式为 UTF-16-LE. 官方的说明是“ArcGIS 应用程序使用 UTF-16-LE 编码读写 ...

  8. kindEditor富文本编辑器的工具栏设置

    如何配置kindeditor的工具栏 kindeditor编辑器的工具栏主要是指编辑器输入框上方的那些可以操作的菜单,默认情况下编辑器是给予了所有的工具栏.针对不同的用户,不同的项目,不同的环境,可能 ...

  9. Keepalived+LVS+nginx搭建nginx高可用集群

    1. 环境准备 1. VMware; 2. 4台CentOs7虚拟主机:192.168.122.248,192.168.122.68, 192.168.122.110, 192.168.122.167 ...

  10. vue+elementui 中 @keyup 键盘上下左右移动聚焦

    <template> <el-table :data="CreditUnclearOutlineList" border style="width: 1 ...