Ejemplo n.º 1
0
  /**
   * 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();
  }
Ejemplo n.º 2
0
  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();
  }