Word as e-mail editor

K

Ken Slovak - [MVP - Outlook]

Yes, but can't control where the toolbar would be placed. Just add the
toolbar in your code as you would for an Outlook editor Inspector.

This will only work for Outlook 2002 and later since you don't get a
NewInspector event for Outlook 2000 with WordMail.

Also, when your Inspector is closing you must delete your toolbar or it will
persist. Word has no notion of temporary toolbars or buttons. You have to
trap the Close events for both the email item in the Inspector and the
Inspector and call a KillWordMailButtons procedure in both since some cases
fire one or the other or both events and others only fire one or the other.

Another thing to look out for is if you need to access any of the button
properties in its Click event handler. You might get errors that the
property (or method such as PasteFace) isn't available. You would have to
get the button instance all over again and instantiate it again in your
Click event handler to access the properties. I use FindControl with a
unique Tag to locate the button in those conditions so I can access the
properties or methods. The problem is due to how the COM wrapper for
WordMail is implemented.
 
M

Mark Smith

I do get a NewInspector event for Outlook 2000 SP3 with WordMail. However,
when I call CommandBars::Add, I get an exception and the toolbar doesn't
show up.

When I try it in Outlook 2002 SP3, the button gets added, but no caption
shows up.

Any ideas?

Mark
 
K

Ken Slovak - [MVP - Outlook]

I wouldn't even attempt to support WordMail using code for Outlook 2000 at
all. Just too funky even if you do get a NewInspector event. Without seeing
your code I have idea why no caption is showing up. Usually if you just get
the CommandBarControls collection of the CommandBar object you want to work
with you just use the Add method of the CommandBarControls collection and
get a handle to a CommandBarButton object in return. The button object has a
property to set Caption. So does the CommandBarControl object and all the
other objects you can add.
 
M

Mark Smith

Well, I'm using C++. Here's the relevant code (with unnecessary code
removed):

CComQIPtr<Office::_CommandBarButton> m_pSaveButton;
CComPtr<Office::_CommandBars> m_pCommandBars;
CComPtr<Office::CommandBar> m_pCommandBar;

{
m_pCommandBar = m_pCommandBars->Add(CComVariant(toolBarName),
CComVariant(msoBarTop), CComVariant(VARIANT_FALSE),
CComVariant(VARIANT_TRUE));

// Now get the tool bar's CommandBarControls
CComPtr<Office::CommandBarControls>
pBarControls(m_pCommandBar->GetControls());

// Add save button
m_pSaveButton = pBarControls->Add(CComVariant(msoControlButton),
vEmpty, vEmpty, vEmpty, CComVariant(VARIANT_TRUE));

// Set properties
m_pSaveButton->PutStyle(Office::msoButtonIconAndCaption);
m_pSaveButton->PutFaceId(1677);
m_pSaveButton->PutVisible(VARIANT_TRUE);
m_pSaveButton->PutEnabled(VARIANT_TRUE);

// Set caption

m_pSaveButton->put_Caption(caption);
}


I figured out that later on, when I get the OnClick notification, I can set
the caption just fine using the interface that is passed in to the function:

void __stdcall ToolBar::OnClickButton(IDispatch* Ctrl, VARIANT_BOOL *
CancelDefault)
{
CComQIPtr<Office::_CommandBarButton> pButton(Ctrl);
pButton->put_Caption(caption);
}

The funny thing is that the icon and the tooltip text work just fine. So
I'm confused...

Mark
 
K

Ken Slovak - [MVP - Outlook]

It looks like when you're getting the NewInspector event things with Word
just aren't completely set up yet. What you can do is set a Boolean module
level variable that you set True when the buttons have been created. Then
you can handle the Activate event for the Inspector and in that event
handler check the Boolean. If it's true the buttons have been set up. If not
then set them up. That way your init code doesn't run until the first
activation of the Inspector.
 
M

Mark Smith

I got it working. I hadn't been setting a tag name. Since in your previous
post you said something about looking up the control by id or tag name I
figured I'd set a tag name and go from there. Apparently, setting the tag
name was all that I needed for my caption to start working properly.
Strange...

Also, I am able to set the position of the toolbar just fine.

None of this has yet been tested with Office 2003 yet, but it seems to be
working great with Office 2002, so I am anticipating no problems with 2003
*fingers crossed*.

Now we would really like to support Office 2000. Do you think there is any
chance we could get this working?

Thanks for all of your help,
Mark
 
M

Mark Smith

Let me rephrase - I can set the position of the toolbar ALMOST correctly.
It works in most cases, but doesn't for some others.

Is there any reason I have to delete the toolbar? I did some testing to see
what the behavior would be. If I don't delete it, Outlook and Word still
close just fine. The toolbar persists between new WordMail instances within
the same Outlook session. But when I close Outlook and restart it, the
toolbar needs to be recreated again, unlike Outlook toolbars that are not
temporary.

Mark
 
K

Ken Slovak - [MVP - Outlook]

Leaving orphan toolbars and buttons around is never a very good idea. For
one thing if the user uninstalls your code the debris you created will still
be there.

Positioning a toolbar in Outlook usually mostly works, although your
position can be affected by other custom toolbars that are created by other
code and that are instantiated after your code runs. You can't guarantee
what addin will be instantiated before others, so you have no control over
that. Positioning in Word is much more of a problem and usually doesn't work
very well at all.

Outlook toolbars can also be created permanently, they live in Outcmd.dat.
If your buttons/bars have unique tags you can connect with them again on the
next startup, but again it's not at all a best practice.
 

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