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(); }
public void dispose() { if (auto != null) auto.dispose(); }