千家信息网

java内嵌activeX控件怎么使用

发表于:2025-12-03 作者:千家信息网编辑
千家信息网最后更新 2025年12月03日,本篇内容主要讲解"java内嵌activeX控件怎么使用",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"java内嵌activeX控件怎么使用"吧!这里用的
千家信息网最后更新 2025年12月03日java内嵌activeX控件怎么使用

本篇内容主要讲解"java内嵌activeX控件怎么使用",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"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[] { "MethodName" });
int dispIdMember = regspid[0];
//方法调用
oleAutomation.invoke(dispIdMember);

2、带参数的方法调用
//获取Method Name的ID,Method Name为ActiveX中具体的方法名
int[] regspid = oleAutomation.getIDsOfNames(new String[] { "MethodName" });
int dispIdMember = regspid[0];
//设置方法的具体参数。Variant数组的长度为MethodName方法参数的个数
//假设有四个参数
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;ivr[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);
}
}

到此,相信大家对"java内嵌activeX控件怎么使用"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

方法 参数 控件 内容 程序 学习 实用 更深 个数 兴趣 实用性 实际 容器 应用程序 操作简单 数组 更多 朋友 框架 注册表 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 请写出数据库管理系统的概念 河北通用软件开发规定 徐州网络技术开发介绍 南岸区一站式软件开发服务特点 成都金苍地软件开发工作室 数据库原理及应用属于什么专业 深圳软件开发公司新排行榜 腾讯游戏服务器有哪些 网络安全法 日志留存 开机有服务器管理工具 网络技术公司包括电商吗 三级能考网络技术吗 网络技术有限公司收费吗 中国大百科全书数据库在线查询 北京大田物联嵌入式软件开发 黑龙江运营网络技术服务怎么样 服务器管理源码php 解密中国网络安全 期刊数据库文献检索报告 GO数据库与NR数据 哪里的数据库云 乌班图服务器怎么远程桌面 软件开发使用的知识 浙江信息化软件开发服务参考价格 短视频服务器哪个配置好 深圳圣玺网络技术有限公司 cel人脸数据库 数据库忘记密码怎么找回来 商务部芯片软件开发 要想加工或使用数据库中的数据
0