Question addin in Outlook failing at PutVisible

M

Maneesh S

I have created a Outlook addin in C++, that works fine except when Word is
the emaileditor. The addin shows up in Word as well as Outlook. I do not want
to show the addin in Word. For a workaround I have added the following code
(In outlook code where addin is added) which seem to have solved the issue of
showing the addin toolbar in Word but this have caused another glitch in the
addin. In Outlook, the addin toolbar is not visible by default, I have to
select the toolbar from the right click menu to make it visible on the email
editor(When Word is the mail editor). On more investigation I have found out
that it is failing at pdoc->putVisible(VARIANT_TRUE);

my code below.

CComQIPtr<Outlook::_Inspector> pOlInspector(pOutlook_Inspector);

if (pOlInspector->IsWordMail())
{
CComPtr<Word::_Document> pDoc = NULL;
pDoc = (Word::_DocumentPtr) pOlInspector->WordEditor;
pDoc->Application->CustomizationContext = pDoc;
pWordDoc->Save();
}

//Add my toolbar here and make the toolbar visible

pMyToolbar->putVisible(VARIANT_TRUE); //failing at this, get an E_FAIL error.

I also found out that when Word is not my editor for outlook, in my New
email my custom Addin menu item is added under Actions instead of Tools. But
when I close the compose window and compose a new email this time the same
addin menu item is created under Tools.

Any suggestion will be higly appreciated.

Thanks
Maneesh Singh
 
K

Ken Slovak - [MVP - Outlook]

You will need to handle the Word.WindowActivate() event. In that event you
are passed "wn" which is the Word window object that's being activated. If
wn.Envelope.Visible == true it's a WordMail window, if false it's a Word
document window. Use that information to enable/disable your toolbar
appropriately.

In addition, if you have more than one Inspector opened at a time you will
need a way to distinguish which WordMail window is active and which aren't
so you don't have multiple copies of your UI. Most of us do that using a
collection of open Inspectors with a key value assigned to each Inspector
handler. If the key is added to the unique Tag property assigned to each UI
you create you can tell which WordMail window's UI to enable and which to
disable.

As far as placement of your UI I can't tell why it's happening with the
available information, but you need to add the UI to Tools. To do so get the
Tools menu as a CommandBarPopup object and get its CommandBar object
property. You can then add your CommandBarPopup UI to that CommandBar
object.
 

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