How can I detect that a Word document is hosted in IE?

S

ssissa

Hi,

I am building a plugin for Word, and am experiencing many problems when the
user opens a Word document in Internet Explorer. For example, (1) setting the
visibility and position a toolbar seems to have no effect, I suppose because
IE is doing something above me to turn off all the toolbars; (2) some
functions result in a COM exception, particularly the Documents.Add() and
"The X method or property is not available because this document is in
another application"; and (3) some events that normally fire, such as
Application.DocumentChange, do not.

It may be natural for my plugin to behave differently when in such a
"hosted" mode, but I am not sure how I can correctly detect such a mode.

I have previously used the "custom" property passed to
IDTExtensibility2.OnConnection. Checking that custom[1] == 1 seems to be a
good test as to whether Word was loaded through automation or not. The
problem is that there are cases where word is loaded through automation but
my plugin can behave normally. In particular, if I first open a Word document
in IE, then I manually launch a new instance of Word, I seem to be in the
same process and same IDTExtensibility2.OnConnection scope. If I don't load
my plugin when custom[1] == 1, then it won't be available in the subsuquent
new instances. Even if I do load it, my toolbar does not even show in the new
instance (was it was set invisible in the IE instance?). I suppose I need
some way to know that the first window was "hosted" and the new is normal so
my plugin can behave appropriatly in each window.

Is there some per-document or per-window way to know if the document/window
is hosted? Is this something special in the context of IE, or can I expect
other "hosted" environments when building my plugin?

Similar answers in the context of PowerPoint and/or Excel can also be helpful.

Thanks,
Bret
 
P

Peter Huang [MSFT]

Hi Bret,

Currently I am researching the issue and we will reply here with more
information as soon as possible.
If you have any more concerns on it, please feel free to post here.

Thanks for your understanding!

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter Huang [MSFT]

Hi Bret,

Sorry for delay response.

Based on my research, as you said, we can check the custom[1], one of the
parameters passed to OnConnection is an array with first element being how
you started (by user, by automation, by OLE). In IE case you'll be started
by OLE.(The value should be 2) If instance is made visible, you'll get a
WindowActivate event and the App.Visible property will be True, and thats
how you can tell.

That is to say, you can add an event handler to the WindowsActivate event.
Inside the event ,we can check Document.Container property.
We need to check the property after the document is ready.

So I think you may try to check the custom[1] to see if the document is
hosted in IE. After that when we open the document in another Word window
without starting a new word instance, the windowactivate event will fire
for you check the container and customized toolbar.


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

ssissa

Hi Peter,

Thanks for your reponse.

In fact, the Document.Container property was exactly what I needed. On each
DocumentChange event (seems more reliable in Word than WindowActivate), I
check the Document.Container property to know if the document is embedded in
another application, in which case I can change the behavior as needed to
avoid certain problems.

Thanks,
Bret
 
P

Peter Huang [MSFT]

Hi Bret,

Thanks for your quickly reply!


Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top