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 ...
随机推荐
- 解决spring boot中普通类中使用service为null 的方法
我使用的是springboot+mybatisplus +mysql1.创建一个SpringUtil工具类 import org.springframework.beans.BeansExceptio ...
- 16. Jmeter-监听器
jmeter-监听器介绍与使用 察看结果树 Summary Report 聚合报告 Backend Listener Aggregate Graph 断言结果 Comparison Assertion ...
- C++的模板
1. 模板形参表 模板形参表,里面可以是typename T/ class T这种形式的,代表里面被泛化的是一种类型: 也可以使用Type value这种形式的,代表里面被泛化的是一个某种类型的值. ...
- 剑指offer第二版面试题11:旋转数组的最小数字(JAVA版)
题目:把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转.输入一个递增排序的数组的一个旋转,输出旋转数组的最小元素.例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转,该数 ...
- Codeforces 1173A Nauuo and Votes
题目链接:http://codeforces.com/problemset/problem/1173/A 思路:模拟. AC代码: #include<bits/stdc++.h> usin ...
- PXE装机
支持 centOS 6 支持 PXE 装机的网卡必须自带 ROM(非意识性存储器)存储内容包括:DHCP 客户端,TFTP 客户端,PXE 协议客户端,将网卡设置第一启动项. DHCP:自动分配 IP ...
- Java 设计模式之 装饰者模式
装饰者模式(Decorator Pattern): 概述:装饰模式是在不必改变原类文件和使用继承的情况下,动态地扩展一个对象的功能.它是通过创建一个包装对象,也就是装饰来包裹真实的对象 特点: (1) ...
- 图像处理_Image
1. 安装 输入 pip install PIL报错: ERROR: Could not find a version that satisfies the requirement PI ...
- (数据科学学习手札59)从抓取数据到生成shp文件并展示
一.简介 shp格式的文件是地理信息领域最常见的文件格式之一,很好的结合了矢量数据与对应的标量数据,而在Python中我们可以使用pyshp来完成创建shp文件的过程,本文将从如何从高德地图获取矢量信 ...
- Mac OS X终端的常用操作命令(UNIX指令)
用了十多年windows,终于换了个高配Mac,俗话说 无论前端还是后端最终还是走向了linux,无论是换了多少台PC最终都会走向Mac.不学习命令行用什么Mac? 干就完了~ pwd 显示现在的文件 ...