SWT中使用ActiveX控件示例

package geftest.swt;

import java.io.File;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.ole.win32.OLE;
import org.eclipse.swt.ole.win32.OleClientSite;
import org.eclipse.swt.ole.win32.OleFrame;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class ActiveXTest
{

 private Shell sShell = null;
 private Button button = null;
 private OleClientSite clientSite;
 public static void main(String[] args)
 {

  Display display = Display.getDefault();
  ActiveXTest thisClass = new ActiveXTest();
  thisClass.createSShell();
  thisClass.sShell.open();

  while (!thisClass.sShell.isDisposed())
  {
   if (!display.readAndDispatch())
    display.sleep();
  }
  display.dispose();
 }

 /**
  * This method initializes sShell
  */
 private void createSShell()
 {
  GridData gridData = new GridData();
  gridData.horizontalSpan = 2;
  GridLayout gridLayout = new GridLayout();
  gridLayout.numColumns = 3;
  sShell = new Shell();
  sShell.setText("Shell");
  sShell.setLayout(gridLayout);
  sShell.setSize(new Point(300, 200));
  OleFrame frame = new OleFrame(sShell, SWT.NONE);
  button = new Button(sShell, SWT.NONE);
  button.setLayoutData(gridData);
  button.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
   public void widgetSelected(org.eclipse.swt.events.SelectionEvent e)
   {
    clientSite.save(new File("c:/test.doc"),true);
   }
  });
  frame.setSize(200,200);
  clientSite = new OleClientSite(frame, SWT.NONE,"Word.Document");
  clientSite.setSize(200,200);
  clientSite.doVerb(OLE.OLEIVERB_SHOW);

 }

}
 

你可能感兴趣的:(eclipse,C++,c,C#)