Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Embedding MSWord with OLE
Embedding MSWord with OLE [message #441632] Wed, 18 August 2004 06:26 Go to next message
Eclipse UserFriend
Originally posted by: schroeer.technotrans.de

Hi folks,

I am having some trouble getting this to work:

I am trying to embed a Word application with the SWT OLE classes.
Generally, I need to open Word, modify some document (or just viewing it),
close Word. At this point, when Word is closed, I need to know whether the
document was changed. If so, I open some dialog to create a change log and
other stuff.
As you can see in the code below I was trying to solve this with a Dispose
Listener on the OleClientSite. I also have tried other listeners on any
possible object, but none have worked. I always had one of those problems:

1. I opened Word in an own window (OLE.OLEIVERB_OPEN verb) and have all
the Word functionalities but I don't know how to attach the Listener in a
way that it works.
2. I opened Word in a SWT widget (OLE.OLEIVERB_UIACTIVATE or
OLE.OLEIVERB_SHOW verb) and can attach the Listener but I'm missing a lot
of Word functionalities, at least even the Word File menu. Many others are
simply disabled.

Below see the relevant code I have implemented so far. I am using SWT 3.0
and Java 1.4.2_02 on a Win2000 SP2 machine with Word 2000 SR1.

Thanks for help or even another solution,
Tobias

import java.io.File;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
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.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Shell;

public class MSWordOLE {

/** The ClientSite */
private OleClientSite clientSite;
/**
* Create a new OLE connection with Word
* @param shell parent shell or <code>null</code> if standalone
* @param file a Wordfile to be opened or <code>null</code> for new file
*/
public MSWordOLE(Shell shell, File file) {
//setting up the Shell
if (shell == null) {
Display display = Display.getCurrent();
shell = new Shell(display, SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM);
shell.setLayout(new FillLayout());
Menu menu = new Menu(shell, SWT.BAR);
shell.setMenuBar(menu);
}
//Creating OLEFrame
OleFrame frame = new OleFrame(shell, SWT.NONE);
GridData gd = new GridData(GridData.FILL_BOTH);
frame.setLayoutData(gd);

//Creating OLEClientSite
if (file==null) {
//create empty document
this.clientSite =
new OleClientSite(frame, SWT.NONE, "Word.Document");
} else {
//open document
this.clientSite = new OleClientSite(frame, SWT.NONE, file);
}

//aktivate OLE

this.clientSite.doVerb(OLE.OLEIVERB_UIACTIVATE);
//this.clientSite.doVerb(OLE.OLEIVERB_SHOW);

//this.clientSite.doVerb(OLE.OLEIVERB_OPEN);

//a listener to tell when we're closing
shell.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
System.out.println("Word closed");
}
});

shell.pack();
shell.setVisible(true);
shell.setBounds(100, 100, 500, 500);
while (!shell.isDisposed()) {
if (!shell.getDisplay().readAndDispatch()) {
shell.getDisplay().sleep();
}
}
shell.dispose();
}

public static void main(String[] args) {
new MSWordOLE(null, null);
}
}
Re: Embedding MSWord with OLE [message #441639 is a reply to message #441632] Wed, 18 August 2004 08:55 Go to previous message
Tiberiu Caprita is currently offline Tiberiu CapritaFriend
Messages: 68
Registered: July 2009
Member
You should use OleControlSite and listen the Word Event DocumentBeforeSave.
Look in newsgroup, there are already code samples.

Regards,
Tiberiu
Previous Topic:carbon event handling
Next Topic:Text controls
Goto Forum:
  


Current Time: Thu Apr 25 13:25:55 GMT 2024

Powered by FUDForum. Page generated in 0.02532 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top