摘要:數(shù)組的長度為方法參數(shù)的個數(shù)假設(shè)有四個參數(shù)方法調(diào)用調(diào)用程序內(nèi)嵌應(yīng)用程序調(diào)用簡單總結(jié)
這里用的是SWT/JFace開發(fā)application中SWT自帶的org.eclipse.swt.ole.win32 包可以支持內(nèi)嵌OLE和ActiveX。
具體用法如下:
//創(chuàng)建一個OleFrame做為OLE(或ActiveX)的框架 OleFrame oleFrame = new OleFrame(this, SWT.NONE); //創(chuàng)建ActiveX的容器,其中的classID是ActiveX的classid,在注冊表中可以找到 OleControlSite oleControl = new OleControlSite(oleFrame, SWT.NONE, “classID”); //OleAutomation類用來執(zhí)行ActiveX中的方法 OleAutomation oleAutomation = new OleAutomation(oleControl); //將ActiveX顯示在application中 oleControl.doVerb(OLE.OLEIVERB_SHOW);
調(diào)用AcitveX中方法的具體過程:
1、不帶參數(shù)的方法調(diào)用
//獲取Method Name的ID,Method Name為ActiveX中具體的方法名 int[] regspid = oleAutomation.getIDsOfNames(new String[] { "Method Name" }); int dispIdMember = regspid[0]; //方法調(diào)用 oleAutomation.invoke(dispIdMember);
2、帶參數(shù)的方法調(diào)用
//獲取Method Name的ID,Method Name為ActiveX中具體的方法名 int[] regspid = oleAutomation.getIDsOfNames(new String[] { "Method Name" }); int dispIdMember = regspid[0]; //設(shè)置方法的具體參數(shù)。Variant數(shù)組的長度為Method Name方法參數(shù)的個數(shù) //假設(shè)有四個參數(shù) 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); //方法調(diào)用 oleAutomation.invoke(dispIdMember, rgvarg);
調(diào)用OLE Exemple:Java程序內(nèi)嵌Word應(yīng)用程序
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調(diào)用ActiveX簡單總結(jié)
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
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/68161.html
摘要:實現(xiàn)打印的方式方式一會彈出打印對話框,打印的是中的內(nèi)容,下面是從網(wǎng)上摘到的一個局部打印的例子,該例子的不足是打印會修改頁面的內(nèi)容。 目前正在做瀏覽器端采用js方式實現(xiàn)打印這么一個功能,JS打印實現(xiàn)的方法很多,但是兼容各個瀏覽器實現(xiàn)打印預(yù)覽的功能有些棘手,現(xiàn)將實現(xiàn)的內(nèi)容及遇到的問題記錄下來,希望有大??吹剿岬膯栴}后可以給予解答,在此感謝啦。 1.JS實現(xiàn)打印的方式 方式一:window...
摘要:的企業(yè)安全平臺會將有關(guān)此攻擊的警報顯示為可疑文件執(zhí)行。微軟研究人員在上重現(xiàn)了對最新的攻擊。 .markdown-body{word-break:break-word;line-height:1.75;font-weight:400;font-size:15px;overflow-x:hidden;color:#333}.markdown-body h1,.markdown-body h2,...
摘要:條件格式可包含多個規(guī)則,每一個規(guī)則可自定義條件與格式。通過簡單的規(guī)則設(shè)置,可對表單中的大量數(shù)據(jù)進(jìn)行篩選并進(jìn)行直觀地表示和顯示。下面我們來看看在條件格式中,使用不同內(nèi)置條件規(guī)則的表單最終效果。 上一講中,在數(shù)據(jù)的呈現(xiàn)方面,首先為大家介紹了迷你圖,通過一句函數(shù)調(diào)用語句即可直觀顯示數(shù)據(jù)。那么,除了迷你圖,SpreadJS還提供了哪些數(shù)據(jù)的可視化支持呢?今天將繼續(xù)為大家介紹條件格式。 第四講:...
閱讀 3056·2021-09-03 10:33
閱讀 1284·2019-08-30 15:53
閱讀 2633·2019-08-30 15:45
閱讀 3393·2019-08-30 14:11
閱讀 546·2019-08-30 13:55
閱讀 2595·2019-08-29 15:24
閱讀 1926·2019-08-26 18:26
閱讀 3578·2019-08-26 13:41