java application中内嵌ActiveX控件
2014-05-25 22:28
351 查看
我这里用的是SWT/JFace开发application,SWT自带的org.eclipse.swt.ole.win32 包可以支
持内嵌OLE和ActiveX。
具体用法如下:
//创建一个OleFrame做为OLE(或ActiveX)的框架
OleFrame oleFrame = new OleFrame(this, SWT.NONE);
//创建ActiveX的容器,其中的classID是ActiveX的claid,在注册表中可以找到
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 geftest.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);
}
}
持内嵌OLE和ActiveX。
具体用法如下:
//创建一个OleFrame做为OLE(或ActiveX)的框架
OleFrame oleFrame = new OleFrame(this, SWT.NONE);
//创建ActiveX的容器,其中的classID是ActiveX的claid,在注册表中可以找到
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 geftest.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 java 内嵌activeX控件
- swt java 内嵌ActiveX控件
- swt java 内嵌ActiveX控件
- WebSphere Studio Application Developer 与 VisualAge for Java 共存
- ONJava: Designing a Fully Scalable Application
- 使用 WebSphere Studio Application Developer 开发 Java 程序: 与 VisualAge for Java 进行比较
- java application programing
- How to debug Java Web Application?
- Java Web Application的最新技术比较与体会
- java Application创建图形界面
- 使用Java Web Start部署java application
- 破解java Struts Web Application开发工具 scioworks Camino
- 使用java.io.*操作文件的拆分与合并,Application一例!
- Browser-based desktop application development with java
- 使用handleEvent()方法,action()方法和mouseDown()方法处理事件的JAVA Application程序.
- 使用 WebSphere Studio Application Developer 集成版,版本 4.1 开发 Java 消息服务应用程序
- ASE12.5数据库内嵌JAVA开发指南
- Remote Debug with Java Application Server
- Simplify Java Application Deployment
- Sun java studio creator+Sun java application server 8.2+ Jbuilder2005+Jboss4.0.4+Ms sql server2000开发部署要领