New Message Window Problem (word as editor)

G

Guest

Hi,

I have rather a strange problem that only happens when Word is used as the
editor with the new message window AND when a second new message window is
opened. I am using Outlook 2003.

I am adding a command be to the new message window. When I get a new
inspector event I create a new COM object which will create a command bar for
the new message window. I setup me button events and everything works
perfectly. However if I open a new message window when the original window is
open every thing falls to pieces in the new message window. This ONLY happens
when word is the editor. I have several odd symptoms that maybe someone can
help me diagnose the problem or tell me what I am doing wrong.

First clue is when I open the second new message window (new inspector event
generated) in my COM component I check for the existence of my command bar
and if it exists I setup an advise of the button. If I click on the button
nothing happens. If I set break points in my code the event is not getting
fired for that button even though the advise was setup without errors.

Second clue is when I open the second message window and DO NOT check for
the existence of our command bar and just create the command bar; the command
bar is then created in the first message window. Again this happens even
thought there are two separate instances of the Inspector. This is bazaar I
think.

Again I have verified that each time I open a new message window using Word
that I get a new inspector event and a new mail item. Also this does not
happen when word is not the editor. Everything works great if I do not have
word selected as the preferred editor.

So my question is how do I add command bars to the new message window when
Word is the editor and multiple instances of the new message window are open?
I have tried many experiments and it seems once the second new message window
is open Word only will recognize the first inspector.
 
K

Ken Slovak - [MVP - Outlook]

Handle Word object model events in your code. When WindowActivate fires
check to see if any toolbar exists for that Inspector, using an ID for each
open Inspector. Disable and make invisible any existing toolbars that don't
have that ID as part of their unique Tag property. Enable and make visible
or create the toolbar if the ID is part of the Tag for that toolbar. I
usually use a unique string and append the ID to that to get a unique Tag
for each Inspector I'm tracking in my Inspector wrappers.
 
G

Guest

Thanks Ken - I will give that a try tomorrow.



Ken Slovak - said:
Handle Word object model events in your code. When WindowActivate fires
check to see if any toolbar exists for that Inspector, using an ID for each
open Inspector. Disable and make invisible any existing toolbars that don't
have that ID as part of their unique Tag property. Enable and make visible
or create the toolbar if the ID is part of the Tag for that toolbar. I
usually use a unique string and append the ID to that to get a unique Tag
for each Inspector I'm tracking in my Inspector wrappers.
 
G

Guest

Hi Ken,

I put the logic that you suggested into my add-in and it now works perfectly
with the word editor.

Thank you for the suggestion!
 
T

tommy_bergstrand

Hi, I have the same problem, but I am not that familiar with the Word
Object model. Does anyone have some example code?

Best Regards
Tommy
 
G

Guest

This is how to get the word object model programatically.

#import "C:\Program Files\Microsoft Office\OFFICE11\MSWORD.olb" \
rename("ExitWindows","MyExitWindows"), named_guids,
rename_namespace("MSWord")
using namespace MSWord;


CComQIPtr<MSWord::_Document> spDoc = m_pInspector->GetWordEditor();
m_spApp = spDoc->GetApplication();
if(m_spApp)
{
AtlAdvise(m_spApp, GetUnknown(), DIID_ApplicationEvents2, &m_dwCookieWord);
}
 
T

tommy_bergstrand

Thanks, I got the Word Application object, but I get the WindowActivate
message in all of my wrappers when I activate one though.
And if I try to access anything in the word objects I get
a warning from Outlook "A program is trying to access e-mail
addresses...." . Using vb6 by the way.

Regards
Tommy
 
G

Guest

Hi Tommy,

I do not access any of the word objects other than to set an advise. I only
use the activate event as a signal to access the command bars. I do not know
what your implementation is but you should not need to access the word object
other than setting an advise. Perhaps a VB person out there can help you out
a little more?
 
K

Ken Slovak - [MVP - Outlook]

Are you using an Inspector wrapper class? Each open Inspector should be
wrapped in a class that handles the events for that Inspector, including any
WordMail events. In the Inspector wrapper class is a Key property that
uniquely identifies each class. As you add buttons and toolbars to an
Inspector you use a unique Tag property for each one you create, I usually
use a unique string based on the addin, then I append the Key to that.

In WindowActivate I get which Inspector has been activated and by iterating
the various toolbars/buttons I can get the Tag properties and see which ones
relate to that Inspector. I check for Window.EnvelopeVisible = True to see
if the window being activated is an email window. If false I disable any
buttons/toolbars, if true I enable them.

If you aren't using an Inspector wrapper class and a collection to hold the
classes already you can use the code at
http://www.slovaktech.com/code_samples.htm#InspectorWrapper to set one up.
The Inspector wrapper there is in VB 6.
 

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