Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Not getting Ole events from Word
Not getting Ole events from Word [message #439981] Mon, 19 July 2004 22:53 Go to next message
Devon Berry is currently offline Devon BerryFriend
Messages: 9
Registered: July 2009
Junior Member
I am trying to catch when a document is saved in Word 2000. I have tried
the following with no luck:

OleFrame frame = new OleFrame(this, SWT.NONE);
OleControlSite site = new OleControlSite(frame, SWT.NONE,
"Word.Document");
OleAutomation auto = new OleAutomation(site);

int[] propIDs = auto.getIDsOfNames(new String[] {"Saved"});
if (propIDs != null) {
int dispIdMember = propIDs[0];
site.addEventListener(dispIdMember, new OleListener () {
public void handleEvent(OleEvent event) {
System.out.println("Received event!");
}
});
}
int propertyID = 0x00000028; // Saved (obtained from type library)28
site.addPropertyListener(propertyID, new OleListener() {
public void handleEvent(OleEvent event) {
System.out.println("Saved state changed!");
}
});

int eventID = 0x00000028; //
site.addEventListener(eventID, new OleListener() {
public void handleEvent(OleEvent event) {
System.out.println("ole event!");
}
});

// Setup resize and displose listeners
addListener(SWT.Dispose, new Listener() {
public void handleEvent(Event e) {
if (auto != null)
auto.dispose();
auto = null;
}
});

site.doVerb(OLE.OLEIVERB_OPEN);

Any suggestions?

Devon
Re: Not getting Ole events from Word [message #440008 is a reply to message #439981] Tue, 20 July 2004 15:53 Go to previous messageGo to next message
Tiberiu Caprita is currently offline Tiberiu CapritaFriend
Messages: 68
Registered: July 2009
Member
Hi Devon,
Your question is related with Word, so maybe is better to search on
microsoft msdn library infos.

Anyway, firstly take a look on your machine for a file as VBAWDX.chm (X is
a number, I guess 9 for Word2000). If you don't have it, install it from
Word setup CD. The idea is that theoretically everything you can do it in
VBA, you can do (with some effort) also with swt.jar Oles. Is good to read
the Word help in order to understand what a Property/Method means/does.

Speaking about your code "Saved" is a Document property, not a event.
For document Events, you have to look in "dispinterface DocumentEvents"
from Word type library. As you'll see, there is no event there to catch
Document Saving.
A solution may be to catch the ApplicationEvents2.DocumentBeforeSave
(listner to be put on Application).

Regards,
Tiberiu
PS About your previous Question: Word has many problems using it as
ActiveX (in a SWT Window; my advice is to try to change your app, making a
addin in Word.


Devon Berry wrote:

> I am trying to catch when a document is saved in Word 2000. I have tried
> the following with no luck:

> OleFrame frame = new OleFrame(this, SWT.NONE);
> OleControlSite site = new OleControlSite(frame, SWT.NONE,
> "Word.Document");
> OleAutomation auto = new OleAutomation(site);

> int[] propIDs = auto.getIDsOfNames(new String[] {"Saved"});
> if (propIDs != null) {
> int dispIdMember = propIDs[0];
> site.addEventListener(dispIdMember, new OleListener () {
> public void handleEvent(OleEvent event) {
> System.out.println("Received event!");
> }
> });
> }
> int propertyID = 0x00000028; // Saved (obtained from type library)28
> site.addPropertyListener(propertyID, new OleListener() {
> public void handleEvent(OleEvent event) {
> System.out.println("Saved state changed!");
> }
> });

> int eventID = 0x00000028; //
> site.addEventListener(eventID, new OleListener() {
> public void handleEvent(OleEvent event) {
> System.out.println("ole event!");
> }
> });

> // Setup resize and displose listeners
> addListener(SWT.Dispose, new Listener() {
> public void handleEvent(Event e) {
> if (auto != null)
> auto.dispose();
> auto = null;
> }
> });

> site.doVerb(OLE.OLEIVERB_OPEN);

> Any suggestions?

> Devon
Re: Not getting Ole events from Word [message #440010 is a reply to message #440008] Tue, 20 July 2004 16:57 Go to previous messageGo to next message
Devon Berry is currently offline Devon BerryFriend
Messages: 9
Registered: July 2009
Junior Member
Thanks for the advice, I will take a look at the Word VB Help file.

Besides Word's unruliness as an OLE Document or ActiveX Control, I think my
major problem is figuring out how to properly hook a given interface or
event I find in the type library. I have tried to hook
ApplicationEvents2.DocumentBeforeSave with no success. Would you be able to
show me with a couple lines of code to demonstrate how this is done? I am
new to working with OLE at this level and would love an example to get me
started so that I can begin hooking into all the different IDispatch
interfaces. As my snippet demonstrates, I understand how to add the
listener on the Java end, but I think I misunderstand the process of
grabbing the correct event ID from the type library, since I never seem to
get a callback for the events I go after.

As for redesigning the app to be a Word addin, unless I am misunderstanding
you, I don't think it is an option. OLE documents are just one feature.
This app is deployed on the Rich Client Platform as a feature consisting of
about 14 plugins.

Thanks!

Devon

"Tiberiu Caprita" <capritat@hotmail.com> wrote in message
news:cdjf58$q1a$1@eclipse.org...
> Hi Devon,
> Your question is related with Word, so maybe is better to search on
> microsoft msdn library infos.
>
> Anyway, firstly take a look on your machine for a file as VBAWDX.chm (X is
> a number, I guess 9 for Word2000). If you don't have it, install it from
> Word setup CD. The idea is that theoretically everything you can do it in
> VBA, you can do (with some effort) also with swt.jar Oles. Is good to read
> the Word help in order to understand what a Property/Method means/does.
>
> Speaking about your code "Saved" is a Document property, not a event.
> For document Events, you have to look in "dispinterface DocumentEvents"
> from Word type library. As you'll see, there is no event there to catch
> Document Saving.
> A solution may be to catch the ApplicationEvents2.DocumentBeforeSave
> (listner to be put on Application).
>
> Regards,
> Tiberiu
> PS About your previous Question: Word has many problems using it as
> ActiveX (in a SWT Window; my advice is to try to change your app, making a
> addin in Word.
>
>
> Devon Berry wrote:
>
> > I am trying to catch when a document is saved in Word 2000. I have
tried
> > the following with no luck:
>
> > OleFrame frame = new OleFrame(this, SWT.NONE);
> > OleControlSite site = new OleControlSite(frame, SWT.NONE,
> > "Word.Document");
> > OleAutomation auto = new OleAutomation(site);
>
> > int[] propIDs = auto.getIDsOfNames(new String[] {"Saved"});
> > if (propIDs != null) {
> > int dispIdMember = propIDs[0];
> > site.addEventListener(dispIdMember, new OleListener () {
> > public void handleEvent(OleEvent event) {
> > System.out.println("Received event!");
> > }
> > });
> > }
> > int propertyID = 0x00000028; // Saved (obtained from type library)28
> > site.addPropertyListener(propertyID, new OleListener() {
> > public void handleEvent(OleEvent event) {
> > System.out.println("Saved state changed!");
> > }
> > });
>
> > int eventID = 0x00000028; //
> > site.addEventListener(eventID, new OleListener() {
> > public void handleEvent(OleEvent event) {
> > System.out.println("ole event!");
> > }
> > });
>
> > // Setup resize and displose listeners
> > addListener(SWT.Dispose, new Listener() {
> > public void handleEvent(Event e) {
> > if (auto != null)
> > auto.dispose();
> > auto = null;
> > }
> > });
>
> > site.doVerb(OLE.OLEIVERB_OPEN);
>
> > Any suggestions?
>
> > Devon
>
>
Re: Not getting Ole events from Word [message #440023 is a reply to message #440010] Wed, 21 July 2004 09:14 Go to previous message
Tiberiu Caprita is currently offline Tiberiu CapritaFriend
Messages: 68
Registered: July 2009
Member
1. For Ole Event Code sample, take a look on available snippets on Eclipse
site
( http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/plat form-swt-home/dev.html#snippets).
Always it is good to see if is not already available a snippet, before to
put questions.
2. If you don't run a Stand alone Word, you have to create a File Menu and
to implement Save (see ActiveX help doc in Eclipse).
3. About Word Addin, I mean to consider just the communication with Word,
not your whole application.
4. Here is a sample (not very nice) just showing you that
DocumentsBeforeSave Event is catched:

Good luck,
Tiberiu

public class WordMain {

final static int DocumentBeforeSaveEvent = 0x00000008;

public static void main(String[] args) {
Display display = new Display();

Shell shell = new Shell(display);
OleFrame frame = new OleFrame(shell,SWT.NONE);
shell.setLayout(new GridLayout());
frame.setLayoutData(new GridData(GridData.FILL_HORIZONTAL |
GridData.FILL_VERTICAL));

OleControlSite site = new OleControlSite(frame,SWT.NONE,
"Word.Document");
OleAutomation doc = new OleAutomation(site);
int [] dispInfo = doc.getIDsOfNames(new String[] {"Application"});
Variant variant = doc.getProperty(dispInfo[0]);
OleAutomation app = variant.getAutomation();
variant.dispose();

OleListener listener = new OleListener() {

public void handleEvent(OleEvent event) {
System.out.println("DocumentBeforeSave Event, no. params:" +
event.arguments.length);
}
};

site.addEventListener(app,DocumentBeforeSaveEvent,listener);

site.doVerb(OLE.OLEIVERB_OPEN);
shell.open();

while(!shell.isDisposed()) {
if(!display.readAndDispatch())
display.sleep();
}

app.dispose();

}
}





Devon Berry wrote:

> Thanks for the advice, I will take a look at the Word VB Help file.

> Besides Word's unruliness as an OLE Document or ActiveX Control, I think my
> major problem is figuring out how to properly hook a given interface or
> event I find in the type library. I have tried to hook
> ApplicationEvents2.DocumentBeforeSave with no success. Would you be able to
> show me with a couple lines of code to demonstrate how this is done? I am
> new to working with OLE at this level and would love an example to get me
> started so that I can begin hooking into all the different IDispatch
> interfaces. As my snippet demonstrates, I understand how to add the
> listener on the Java end, but I think I misunderstand the process of
> grabbing the correct event ID from the type library, since I never seem to
> get a callback for the events I go after.

> As for redesigning the app to be a Word addin, unless I am misunderstanding
> you, I don't think it is an option. OLE documents are just one feature.
> This app is deployed on the Rich Client Platform as a feature consisting of
> about 14 plugins.

> Thanks!

> Devon

> "Tiberiu Caprita" <capritat@hotmail.com> wrote in message
> news:cdjf58$q1a$1@eclipse.org...
> > Hi Devon,
> > Your question is related with Word, so maybe is better to search on
> > microsoft msdn library infos.
> >
> > Anyway, firstly take a look on your machine for a file as VBAWDX.chm (X is
> > a number, I guess 9 for Word2000). If you don't have it, install it from
> > Word setup CD. The idea is that theoretically everything you can do it in
> > VBA, you can do (with some effort) also with swt.jar Oles. Is good to read
> > the Word help in order to understand what a Property/Method means/does.
> >
> > Speaking about your code "Saved" is a Document property, not a event.
> > For document Events, you have to look in "dispinterface DocumentEvents"
> > from Word type library. As you'll see, there is no event there to catch
> > Document Saving.
> > A solution may be to catch the ApplicationEvents2.DocumentBeforeSave
> > (listner to be put on Application).
> >
> > Regards,
> > Tiberiu
> > PS About your previous Question: Word has many problems using it as
> > ActiveX (in a SWT Window; my advice is to try to change your app, making a
> > addin in Word.
> >
> >
> > Devon Berry wrote:
> >
> > > I am trying to catch when a document is saved in Word 2000. I have
> tried
> > > the following with no luck:
> >
> > > OleFrame frame = new OleFrame(this, SWT.NONE);
> > > OleControlSite site = new OleControlSite(frame, SWT.NONE,
> > > "Word.Document");
> > > OleAutomation auto = new OleAutomation(site);
> >
> > > int[] propIDs = auto.getIDsOfNames(new String[] {"Saved"});
> > > if (propIDs != null) {
> > > int dispIdMember = propIDs[0];
> > > site.addEventListener(dispIdMember, new OleListener () {
> > > public void handleEvent(OleEvent event) {
> > > System.out.println("Received event!");
> > > }
> > > });
> > > }
> > > int propertyID = 0x00000028; // Saved (obtained from type library)28
> > > site.addPropertyListener(propertyID, new OleListener() {
> > > public void handleEvent(OleEvent event) {
> > > System.out.println("Saved state changed!");
> > > }
> > > });
> >
> > > int eventID = 0x00000028; //
> > > site.addEventListener(eventID, new OleListener() {
> > > public void handleEvent(OleEvent event) {
> > > System.out.println("ole event!");
> > > }
> > > });
> >
> > > // Setup resize and displose listeners
> > > addListener(SWT.Dispose, new Listener() {
> > > public void handleEvent(Event e) {
> > > if (auto != null)
> > > auto.dispose();
> > > auto = null;
> > > }
> > > });
> >
> > > site.doVerb(OLE.OLEIVERB_OPEN);
> >
> > > Any suggestions?
> >
> > > Devon
> >
> >
Previous Topic:[Styled Text] Layout problem
Next Topic:Table Column - color and other properties
Goto Forum:
  


Current Time: Thu Apr 25 08:29:28 GMT 2024

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

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

Back to the top