public static void main(String[] args) { // if (args.length == 0) { // System.out.println("Usage: java Main <program id>"); // return; // } // // String progID = args[0]; String progID = "WMPlayer.OCX"; // String progID = "RealPlayX.OCX"; Display display = new Display(); Shell shell = new Shell(display); OleFrame frame = new OleFrame(shell, SWT.NONE); OleControlSite site = null; OleAutomation auto = null; try { site = new OleControlSite(frame, SWT.NONE, progID); auto = new OleAutomation(site); } catch (SWTException ex) { System.out.println("Unable to open type library for " + progID); display.dispose(); return; } printTypeInfo(auto); auto.dispose(); shell.dispose(); display.dispose(); }
/** * Launch the application * * @param args */ public static void main(String args[]) { Display display = Display.getDefault(); IETest shell = new IETest(display); shell.setMaximized(true); shell.setLayout(new FillLayout()); Menu bar = new Menu(shell, SWT.BAR); shell.setMenuBar(bar); OleFrame frame = new OleFrame(shell, SWT.NONE); OleControlSite clientsite = null; OleAutomation browser = null; try { clientsite = new OleControlSite(frame, SWT.NONE, "Shell.Explorer"); browser = new OleAutomation(clientsite); clientsite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE); shell.open(); int[] browserIDs = browser.getIDsOfNames(new String[] {"Navigate", "URL"}); Variant[] address = new Variant[] {new Variant("http://blog.csdn.net/bovy")}; browser.invoke(browserIDs[0], address, new int[] {browserIDs[1]}); } catch (Exception ex) { System.out.println("Failed to create IE! " + ex.getMessage()); return; } while (shell != null && !shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } browser.dispose(); display.dispose(); }
private static void printTypeInfo(OleAutomation auto) { TYPEATTR typeattr = auto.getTypeInfoAttributes(); if (typeattr != null) { if (typeattr.cFuncs > 0) System.out.println("Functions :\n"); for (int i = 0; i < typeattr.cFuncs; i++) { OleFunctionDescription data = auto.getFunctionDescription(i); String argList = ""; int firstOptionalArgIndex = data.args.length - data.optionalArgCount; for (int j = 0; j < data.args.length; j++) { argList += "["; if (j >= firstOptionalArgIndex) argList += "optional, "; argList += getDirection(data.args[j].flags) + "] " + getTypeName(data.args[j].type) + " " + data.args[j].name; if (j < data.args.length - 1) argList += ", "; } System.out.println( getInvokeKind(data.invokeKind) + " (id = " + data.id + ") : " + "\n\tSignature : " + getTypeName(data.returnType) + " " + data.name + "(" + argList + ")" + "\n\tDescription : " + data.documentation + "\n\tHelp File : " + data.helpFile + "\n"); } if (typeattr.cVars > 0) System.out.println("\n\nVariables :\n"); for (int i = 0; i < typeattr.cVars; i++) { OlePropertyDescription data = auto.getPropertyDescription(i); System.out.println( "PROPERTY (id = " + data.id + ") :" + "\n\tName : " + data.name + "\n\tType : " + getTypeName(data.type) + "\n"); } } }
/* [id(0x000007d2), propget, helpcontext(0x0007bc7a)] HRESULT Parent([out, retval] IDispatch** Parent) */ public Variant getParent() { return auto.getProperty(0x000007d2); }
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new GridLayout(2, false)); final Text text = new Text(shell, SWT.BORDER); text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); Button go = new Button(shell, SWT.PUSH); go.setText("Go"); OleFrame oleFrame = new OleFrame(shell, SWT.NONE); oleFrame.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); OleControlSite controlSite; OleAutomation automation; try { controlSite = new OleControlSite(oleFrame, SWT.NONE, "Shell.Explorer"); automation = new OleAutomation(controlSite); controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE); } catch (SWTException ex) { System.out.println("Unable to open activeX control"); display.dispose(); return; } final OleAutomation auto = automation; go.addListener( SWT.Selection, new Listener() { public void handleEvent(Event e) { String url = text.getText(); int[] rgdispid = auto.getIDsOfNames(new String[] {"Navigate", "URL"}); int dispIdMember = rgdispid[0]; Variant[] rgvarg = new Variant[1]; rgvarg[0] = new Variant(url); int[] rgdispidNamedArgs = new int[1]; rgdispidNamedArgs[0] = rgdispid[1]; auto.invoke(dispIdMember, rgvarg, rgdispidNamedArgs); } }); // Read PostData whenever we navigate to a site that uses it int BeforeNavigate2 = 0xfa; controlSite.addEventListener( BeforeNavigate2, new OleListener() { public void handleEvent(OleEvent event) { Variant url = event.arguments[1]; Variant postData = event.arguments[4]; if (postData != null) { System.out.println( "PostData = " + readSafeArray(postData) + ", URL = " + url.getString()); } } }); // Navigate to this web site which uses post data to fill in the text field // and put the string "hello world" into the text box text.setText("file://" + Snippet186.class.getResource("Snippet186.html").getFile()); int[] rgdispid = automation.getIDsOfNames(new String[] {"Navigate", "URL", "PostData"}); int dispIdMember = rgdispid[0]; Variant[] rgvarg = new Variant[2]; rgvarg[0] = new Variant(text.getText()); rgvarg[1] = writeSafeArray("hello world"); int[] rgdispidNamedArgs = new int[2]; rgdispidNamedArgs[0] = rgdispid[1]; rgdispidNamedArgs[1] = rgdispid[2]; automation.invoke(dispIdMember, rgvarg, rgdispidNamedArgs); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
/* [id(0x000007d7), propget, helpcontext(0x0007bc7f)] HRESULT Top([out, retval] single* Top) */ public Variant getTop() { return auto.getProperty(0x000007d7); }
/* [id(0x000007d6), propput, helpcontext(0x0007bc7e)] HRESULT Left([in] single Left) */ public boolean setLeft(Variant val) { return auto.setProperty(0x000007d6, val); }
/* [id(0x000007d6), propget, helpcontext(0x0007bc7e)] HRESULT Left([out, retval] single* Left) */ public Variant getLeft() { return auto.getProperty(0x000007d6); }
/* [id(0x000007d5), propget, helpcontext(0x0007bc7d)] HRESULT IsFullScreen([out, retval] MsoTriState* IsFullScreen) */ public Variant getIsFullScreen() { return auto.getProperty(0x000007d5); }
/* [id(0x000007d4), propget, helpcontext(0x0007bc7c)] HRESULT Presentation([out, retval] Presentation** Presentation) */ public Variant getPresentation() { return auto.getProperty(0x000007d4); }
/* [id(0x000007d8), propget, helpcontext(0x0007bc80)] HRESULT Width([out, retval] single* Width) */ public Variant getWidth() { return auto.getProperty(0x000007d8); }
public void dispose() { if (auto != null) auto.dispose(); }
/* [id(0x000007d1), propget, helpcontext(0x0007bc79)] HRESULT Application([out, retval] Application** Application) */ public Variant getApplication() { return auto.getProperty(0x000007d1); }
/* [id(0x000007dc), helpcontext(0x0007bc84)] HRESULT Activate() */ public Variant Activate() { int id = 0x000007dc; return auto.invoke(id); }
/* [id(0x000007db), propget, helpcontext(0x0007bc83)] HRESULT Active([out, retval] MsoTriState* Active) */ public Variant getActive() { return auto.getProperty(0x000007db); }
/* [id(0x000007d9), propput, helpcontext(0x0007bc81)] HRESULT Height([in] single Height) */ public boolean setHeight(Variant val) { return auto.setProperty(0x000007d9, val); }
/* [id(0x000007d9), propget, helpcontext(0x0007bc81)] HRESULT Height([out, retval] single* Height) */ public Variant getHeight() { return auto.getProperty(0x000007d9); }
/* [id(0x000007d8), propput, helpcontext(0x0007bc80)] HRESULT Width([in] single Width) */ public boolean setWidth(Variant val) { return auto.setProperty(0x000007d8, val); }
/* [id(0x000007d3), propget, helpcontext(0x0007bc7b)] HRESULT View([out, retval] SlideShowView** View) */ public Variant getView() { return auto.getProperty(0x000007d3); }
/* [id(0x000007d7), propput, helpcontext(0x0007bc7f)] HRESULT Top([in] single Top) */ public boolean setTop(Variant val) { return auto.setProperty(0x000007d7, val); }