List of usage examples for org.eclipse.swt.ole.win32 OleControlSite doVerb
public int doVerb(int verb)
From source file:org.eclipse.swt.snippets.Snippet305.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Excel Sheet Selection Example"); shell.setLayout(new FillLayout()); OleAutomation application;/*from www . jav a2 s. c om*/ try { OleFrame frame = new OleFrame(shell, SWT.NONE); OleControlSite controlSite = new OleControlSite(frame, SWT.NONE, "Excel.Sheet"); controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE); OleAutomation excelSheet = new OleAutomation(controlSite); int[] dispIDs = excelSheet.getIDsOfNames(new String[] { "Application" }); Variant pVarResult = excelSheet.getProperty(dispIDs[0]); application = pVarResult.getAutomation(); pVarResult.dispose(); excelSheet.dispose(); OleListener listener = new OleListener() { @Override public void handleEvent(OleEvent e) { // SheetSelectionChange(ByVal Sh As Object, ByVal Target As Excel.Range) Variant[] args = e.arguments; // OleAutomation sheet = args[1].getAutomation(); // Excel.Sheet OleAutomation range = args[0].getAutomation(); // Excel.Range int[] dispIDs = range.getIDsOfNames(new String[] { "Row" }); Variant pVarResult = range.getProperty(dispIDs[0]); int row = pVarResult.getInt(); dispIDs = range.getIDsOfNames(new String[] { "Column" }); pVarResult = range.getProperty(dispIDs[0]); int column = pVarResult.getInt(); range.dispose(); System.out.println("row=" + row + " column=" + column); } }; controlSite.addEventListener(application, IID_AppEvents, SheetSelectionChange, listener); } catch (SWTError e) { System.out.println("Unable to open activeX control"); display.dispose(); return; } shell.setSize(800, 600); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } if (application != null) application.dispose(); display.dispose(); }
From source file:MainClass.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setSize(600, 400);//from w ww . j a va 2s. c o m shell.setLayout(new FillLayout()); OleControlSite oleControlSite; OleFrame oleFrame = new OleFrame(shell, SWT.NONE); oleControlSite = new OleControlSite(oleFrame, SWT.NONE, "Shell.Explorer"); oleControlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE); shell.open(); final OleAutomation browser = new OleAutomation(oleControlSite); int[] browserIDs = browser.getIDsOfNames(new String[] { "Navigate", "URL" }); Variant[] address = new Variant[] { new Variant("http://www.java2s.com") }; browser.invoke(browserIDs[0], address, new int[] { browserIDs[1] }); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } browser.dispose(); display.dispose(); }
From source file:SWTOleFrame.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setSize(600, 400);// w ww . j av a2 s. com shell.setLayout(new FillLayout()); OleControlSite oleControlSite; OleFrame oleFrame = new OleFrame(shell, SWT.NONE); oleControlSite = new OleControlSite(oleFrame, SWT.NONE, "Shell.Explorer"); oleControlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE); shell.open(); final OleAutomation browser = new OleAutomation(oleControlSite); int[] browserIDs = browser.getIDsOfNames(new String[] { "Navigate", "URL" }); Variant[] address = new Variant[] { new Variant("http://www.oreilly.com") }; browser.invoke(browserIDs[0], address, new int[] { browserIDs[1] }); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } browser.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet199.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 199"); shell.setLayout(new FillLayout()); OleControlSite controlSite; try {//from ww w. j ava2 s . c o m OleFrame frame = new OleFrame(shell, SWT.NONE); controlSite = new OleControlSite(frame, SWT.NONE, "Excel.Sheet"); controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE); } catch (SWTError e) { System.out.println("Unable to open activeX control"); display.dispose(); return; } shell.open(); OleAutomation excelSheet = new OleAutomation(controlSite); int[] dispIDs = excelSheet.getIDsOfNames(new String[] { "Application" }); Variant pVarResult = excelSheet.getProperty(dispIDs[0]); OleAutomation application = pVarResult.getAutomation(); pVarResult.dispose(); excelSheet.dispose(); int eventID = SheetSelectionChange; OleListener listener = new OleListener() { @Override public void handleEvent(OleEvent e) { System.out.println("selection has changed"); Variant[] args = e.arguments; for (int i = 0; i < args.length; i++) { System.out.println(args[i]); } } }; controlSite.addEventListener(application, IID_AppEvents, eventID, listener); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } application.dispose(); display.dispose(); }
From source file:Snippet187.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); OleControlSite controlSite; try {/*from w w w . j a v a2 s . co m*/ OleFrame frame = new OleFrame(shell, SWT.NONE); controlSite = new OleControlSite(frame, SWT.NONE, "Shell.Explorer"); controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE); } catch (SWTError e) { System.out.println("Unable to open activeX control"); return; } // IWebBrowser final OleAutomation webBrowser = new OleAutomation(controlSite); // When the document is loaded, access the document object for the new // page // and evalute expression using Script. int DownloadComplete = 104; controlSite.addEventListener(DownloadComplete, new OleListener() { public void handleEvent(OleEvent event) { int[] htmlDocumentID = webBrowser.getIDsOfNames(new String[] { "Document" }); if (htmlDocumentID == null) return; Variant pVarResult = webBrowser.getProperty(htmlDocumentID[0]); if (pVarResult == null || pVarResult.getType() == 0) return; // IHTMLDocument2 OleAutomation htmlDocument = null; try { htmlDocument = pVarResult.getAutomation(); pVarResult.dispose(); int[] scriptID = htmlDocument.getIDsOfNames(new String[] { "Script" }); if (scriptID == null) return; pVarResult = htmlDocument.getProperty(scriptID[0]); if (pVarResult == null || pVarResult.getType() == 0) return; OleAutomation htmlWindow = null; try { // IHTMLWindow2 htmlWindow = pVarResult.getAutomation(); pVarResult.dispose(); int[] evaluateID = htmlWindow.getIDsOfNames(new String[] { "evaluate" }); if (evaluateID == null) return; String expression = "5+Math.sin(9)"; Variant[] rgvarg = new Variant[] { new Variant(expression) }; pVarResult = htmlWindow.invoke(evaluateID[0], rgvarg, null); if (pVarResult == null || pVarResult.getType() == 0) return; System.out.println(expression + " =" + pVarResult.getString()); } finally { htmlWindow.dispose(); } } finally { htmlDocument.dispose(); } } }); // Navigate to a web site int[] ids = webBrowser.getIDsOfNames(new String[] { "Navigate", "URL" }); Variant[] rgvarg = new Variant[] { new Variant( "http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet187.html") }; int[] rgdispidNamedArgs = new int[] { ids[1] }; webBrowser.invoke(ids[0], rgvarg, rgdispidNamedArgs); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } // Remember to release OleAutomation Object webBrowser.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet187.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 187"); shell.setLayout(new FillLayout()); OleControlSite controlSite; try {//ww w . j a v a 2 s . c o m OleFrame frame = new OleFrame(shell, SWT.NONE); controlSite = new OleControlSite(frame, SWT.NONE, "Shell.Explorer"); controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE); } catch (SWTError e) { System.out.println("Unable to open activeX control"); display.dispose(); return; } // IWebBrowser final OleAutomation webBrowser = new OleAutomation(controlSite); // When the document is loaded, access the document object for the new page // and evalute expression using Script. int DownloadComplete = 104; controlSite.addEventListener(DownloadComplete, new OleListener() { @Override public void handleEvent(OleEvent event) { int[] htmlDocumentID = webBrowser.getIDsOfNames(new String[] { "Document" }); if (htmlDocumentID == null) return; Variant pVarResult = webBrowser.getProperty(htmlDocumentID[0]); if (pVarResult == null || pVarResult.getType() == 0) return; //IHTMLDocument2 OleAutomation htmlDocument = null; try { htmlDocument = pVarResult.getAutomation(); pVarResult.dispose(); int[] scriptID = htmlDocument.getIDsOfNames(new String[] { "Script" }); if (scriptID == null) return; pVarResult = htmlDocument.getProperty(scriptID[0]); if (pVarResult == null || pVarResult.getType() == 0) return; OleAutomation htmlWindow = null; try { //IHTMLWindow2 htmlWindow = pVarResult.getAutomation(); pVarResult.dispose(); int[] evaluateID = htmlWindow.getIDsOfNames(new String[] { "evaluate" }); if (evaluateID == null) return; String expression = "5+Math.sin(9)"; Variant[] rgvarg = new Variant[] { new Variant(expression) }; pVarResult = htmlWindow.invoke(evaluateID[0], rgvarg, null); if (pVarResult == null || pVarResult.getType() == 0) return; System.out.println(expression + " =" + pVarResult.getString()); } finally { htmlWindow.dispose(); } } finally { htmlDocument.dispose(); } } }); // Navigate to a web site int[] ids = webBrowser.getIDsOfNames(new String[] { "Navigate", "URL" }); Variant[] rgvarg = new Variant[] { new Variant( "http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet187.html") }; int[] rgdispidNamedArgs = new int[] { ids[1] }; webBrowser.invoke(ids[0], rgvarg, rgdispidNamedArgs); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } //Remember to release OleAutomation Object webBrowser.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet186.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 186"); 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;/*from ww w . ja v a 2 s.com*/ 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() { @Override 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() { @Override 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(); }
From source file:Snippet186.java
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;/*from www .j a va2 s . c o m*/ try { controlSite = new OleControlSite(oleFrame, SWT.NONE, "Shell.Explorer"); automation = new OleAutomation(controlSite); controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE); } catch (SWTException ex) { 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(); }
From source file:Snippet123.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); OleControlSite controlSite; try {/*from w ww.java 2 s . c o m*/ OleFrame frame = new OleFrame(shell, SWT.NONE); controlSite = new OleControlSite(frame, SWT.NONE, "Shell.Explorer"); controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE); } catch (SWTError e) { System.out.println("Unable to open activeX control"); return; } shell.open(); // IWebBrowser final OleAutomation webBrowser = new OleAutomation(controlSite); // When a new document is loaded, access the document object for the new // page. int DownloadComplete = 104; controlSite.addEventListener(DownloadComplete, new OleListener() { public void handleEvent(OleEvent event) { int[] htmlDocumentID = webBrowser.getIDsOfNames(new String[] { "Document" }); if (htmlDocumentID == null) return; Variant pVarResult = webBrowser.getProperty(htmlDocumentID[0]); if (pVarResult == null || pVarResult.getType() == 0) return; // IHTMLDocument2 OleAutomation htmlDocument = pVarResult.getAutomation(); // Request to be notified of click, double click and key down // events EventDispatch myDispatch = new EventDispatch(EventDispatch.onclick); IDispatch idispatch = new IDispatch(myDispatch.getAddress()); Variant dispatch = new Variant(idispatch); htmlDocument.setProperty(EventDispatch.onclick, dispatch); myDispatch = new EventDispatch(EventDispatch.ondblclick); idispatch = new IDispatch(myDispatch.getAddress()); dispatch = new Variant(idispatch); htmlDocument.setProperty(EventDispatch.ondblclick, dispatch); myDispatch = new EventDispatch(EventDispatch.onkeydown); idispatch = new IDispatch(myDispatch.getAddress()); dispatch = new Variant(idispatch); htmlDocument.setProperty(EventDispatch.onkeydown, dispatch); // Remember to release OleAutomation Object htmlDocument.dispose(); } }); // Navigate to a web site int[] ids = webBrowser.getIDsOfNames(new String[] { "Navigate", "URL" }); Variant[] rgvarg = new Variant[] { new Variant("http://www.google.com") }; int[] rgdispidNamedArgs = new int[] { ids[1] }; webBrowser.invoke(ids[0], rgvarg, rgdispidNamedArgs); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } // Remember to release OleAutomation Object webBrowser.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet123.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 123"); shell.setLayout(new FillLayout()); OleControlSite controlSite; try {// ww w. j a va2 s.co m OleFrame frame = new OleFrame(shell, SWT.NONE); controlSite = new OleControlSite(frame, SWT.NONE, "Shell.Explorer"); controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE); } catch (SWTError e) { System.out.println("Unable to open activeX control"); display.dispose(); return; } shell.open(); // IWebBrowser final OleAutomation webBrowser = new OleAutomation(controlSite); // When a new document is loaded, access the document object for the new page. int DownloadComplete = 104; controlSite.addEventListener(DownloadComplete, new OleListener() { @Override public void handleEvent(OleEvent event) { int[] htmlDocumentID = webBrowser.getIDsOfNames(new String[] { "Document" }); if (htmlDocumentID == null) return; Variant pVarResult = webBrowser.getProperty(htmlDocumentID[0]); if (pVarResult == null || pVarResult.getType() == 0) return; //IHTMLDocument2 OleAutomation htmlDocument = pVarResult.getAutomation(); // Request to be notified of click, double click and key down events EventDispatch myDispatch = new EventDispatch(EventDispatch.onclick); IDispatch idispatch = new IDispatch(myDispatch.getAddress()); Variant dispatch = new Variant(idispatch); htmlDocument.setProperty(EventDispatch.onclick, dispatch); myDispatch = new EventDispatch(EventDispatch.ondblclick); idispatch = new IDispatch(myDispatch.getAddress()); dispatch = new Variant(idispatch); htmlDocument.setProperty(EventDispatch.ondblclick, dispatch); myDispatch = new EventDispatch(EventDispatch.onkeydown); idispatch = new IDispatch(myDispatch.getAddress()); dispatch = new Variant(idispatch); htmlDocument.setProperty(EventDispatch.onkeydown, dispatch); //Remember to release OleAutomation Object htmlDocument.dispose(); } }); // Navigate to a web site int[] ids = webBrowser.getIDsOfNames(new String[] { "Navigate", "URL" }); Variant[] rgvarg = new Variant[] { new Variant("http://www.google.com") }; int[] rgdispidNamedArgs = new int[] { ids[1] }; webBrowser.invoke(ids[0], rgvarg, rgdispidNamedArgs); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } //Remember to release OleAutomation Object webBrowser.dispose(); display.dispose(); }