swt 자바 내 장 된 ActiveX 컨트롤

SWT / JFace 개발 애플 리 케 이 션 에서 SWT 가 자체 적 으로 가지 고 있 는 org. eclipse. swt. ole. win 32 패 키 지 를 사용 하여 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

좋은 웹페이지 즐겨찾기