// Shows an example of accessing an ActiveX control in // a web page. import iexplorer.InternetExplorer; import iexplorer.IWebBrowserApp; import mshtml.IHTMLDocument; import mshtml.IHTMLElementCollection; import mshtml.IHTMLElement; import ezjcom.JComVariant; import ezjcom.JComObject; import java.io.BufferedReader; import java.io.InputStreamReader; public class ActiveXSample { static String url = TBD: specify your URL string here (in quotes); public static void main(String args[]) { IWebBrowserApp app = null; try { // Instantiate an InternetExplorer InternetExplorer ie = new InternetExplorer(); // Get IWebBrowserApp app = ie.getIWebBrowserApp(); app.setVisible( true ); // 1) Some ActiveX controls may not behave correctly when not visible. // 2) If still setting invisible, also add the following workaround // for Internet Explorer bug (http://support.microsoft.com/kb/259935) //app.setLeft( - app.getWidth()); // If IE is trying to load any default pages, stop it. app.Stop(); // Attach the events listener. WebLoadListener webLoadListener = new WebLoadListener(); ie.addJComEventListener( webLoadListener ); webLoadListener.initialize(); synchronized ( webLoadListener ) { app.Navigate( url ); webLoadListener.wait(); } System.out.println( "Searching URL for ActiveX object " + url ); // Now search the document for an OBJECT tag. IHTMLDocument2 doc = (IHTMLDocument2) app.getDocument().JComCoerceObjectToAnotherType( IHTMLDocument2.class ); IHTMLElementCollection all = doc.getAll(); for ( int i = 0; i < all.getLength(); i++ ) { JComObject object = all.item( new JComVariant( i )); IHTMLElement elem = (IHTMLElement) object.JComCoerceObjectToAnotherType( IHTMLElement.class ); if ( "OBJECT".equalsIgnoreCase( elem.getTagName())) { // This is our ActiveX element! // Now we can use JComGetProperty, JComSetProperty and JComCallMethod // on the object. For instance, JComVariant result = object.JComGetProperty( "MyProperty", null ); System.out.println( "Result = " + result.toString()); result = object.JComCallMethod( "MyMethod", new JComVariant[]{ new JComVariant( 1 ), new JComVariant( 3.3 ), new JComVariant( "etc" ) } ); System.out.println( "Result = " + result.toString()); } } System.out.print( "Press ENTER to quit program" ); BufferedReader in = new BufferedReader( new InputStreamReader( System.in )); in.readLine(); } catch (Exception ex) { ex.printStackTrace(); } finally { if ( app != null ) try { app.Quit(); } catch (Exception ex) {} } System.exit( 0 ); } }