Declaring where an add-in command bar item shows up

S

seacuke

I'm writing an add-in for Outlook 2003 using C#. I'm using the Outlook
PIA, microsoft.office.interop. whatever.

I'm working on adding a button to the 'new email' standard command bar.
I've got the functionality of the button operating, and have the basic
idea of how to add the button to the command bar, but I cannot figure
out how to add the button ONLY to the 'new email' command bar, instead
of the generic "ActiveExplorer.commandBar" command bar. I know this
has got to be easy, but not knowing specifically where to look I can't
seem to find out what to tweak.

Thanks in advance,
'cuke
 
S

seacuke

Helmut,

Thanks a bunch for the link. That works great!

I do have one question about this event handling code, and my add-ins
in general. I am having a hell of a time with the code that performs
the removal of the toolbar button/add-in. Seems like every time I
launch Outlook I get 3 or 4 "Unable to Perform Action" message boxes
popping up.

I've noticed this behavior with any type of add-in I've created for
Outlook - event handlers, toolbar buttons, whatever. I'm running
OLK2003 on 2000Pro, does that combination provide any funky behavior
with regards to add-ins?

Thanks again for the info! You're a life saver.

'cuke
 
H

Helmut Obertanner

Hello 'cuke,

i dont' beleive it's an problem with Win2k.

Have you installed Framework 1.1SP1 and Outlook SP1 ?
Can you be a liitle more specific and put a breakpoint into the OnConnect
event.
Singlestep through the code.
At wich point do you get the error ?

--
regards

Helmut Obertanner
Technical Consultant

Softwaredevelopment
DATALOG Software AG | Zschokkestr. 36 | D-80687 Munich
web: www.datalog.de


.... and IT works!
 
S

seacuke

Hi Helmut,

I believe I have it down to two specific isolated errors at this
point, each of which is causing the above mentioned error dialog.

One of them occurs when Outlook is first launched, AFTER it's been
closed with the add-in attached for the first time. (i.e. the add-in
is installed, everything is fine, close Outlook, on every subsequent
open of Outlook the error appears). Conveniently, I cannot re-create
this particular error when I'm in the debugger; Outlook seems to load
fine in the debugger. I'll try and research this more and maybe
address it later.

The other error that I'm experiencing I was able to get more
information on. It has to do with me adding the add-in button to the
standard toolbar. Here's some code, located from within my mailItem
class (basically the same class as your XMail class from the sample).

....
private CommandBarButton syncButton;

....


private void addUI()
{
CommandBars commandBars = null;

// First we'll try and get access to our synch button.
try
{
commandBars = activeInspector.CommandBars;
syncButton =
(CommandBarButton)commandBars["Standard"].Controls["sync"];
}
catch (System.Exception e)
{
// This means our button isn't in place yet.
syncButton =
(CommandBarButton)commandBars["Standard"].Controls.Add(
1,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value);
syncButton.Caption = "Synchronize";
syncButton.Style = MsoButtonStyle.msoButtonCaption;
}

syncButton.Tag = "Sync";
syncButton.Visible = true;
syncButton.Click += new
_CommandBarButtonEvents_ClickEventHandler(syncButtonClicked);
}


What happens is every time into the addUi (on each opening of a mail
message), the initial setting of syncButton fails and it falls into the
exception, creating a new syncButton. Unfortunately the old one is in
place, so with each new email message opened, I'm getting a new
syncButton.

Thanks again, if you're ever in Montana, I'll be happy to buy you a
beer!

Cheers,
'cuke
 
S

seacuke

I noticed the difference in case between the tag label (syncButton.Tag
= "Sync") and the label (I guess?) being searched for above
(CommandBarButton)commandBars[­"Standard"].Controls["sync"];), and
fixed the discrepency. No difference in functionality.

-cuke
 
H

Helmut Obertanner

Hello seacuke,

you have 2 problems.
1. you create your "Sync" Button as permanent. so it's not automatically
removed.
if you do so, you must manually remove the button and all controls in
inspector close event.

2. You try to get your Button and you get ann error, thats not a good
architecture.
Try to avoid the error, an error is always bad for an application.

try the following, loop over the commandbarcontrols and see if your button
is there.
if you find it, get it - no error.

there was a similar thread wich discuss this here:

one possible solution:

http://www.outlookcode.com/threads.aspx?forumid=5&messageid=10480

try
{
// try to find the CommandBar
foreach (MSO.CommandBar bar in myInspector.CommandBars)
{
if (bar.Name == "XConnect")
{
myCommandBar = bar; // foo, eyh ?
break;
}
}

// If we found our CommandBar, we can use it
if (myCommandBar == null)
{
// if not we create one
myCommandBar = myInspector.CommandBars.Add ("XConnect",
0 , myMissing, false);
}

myCommandBar.Position = MSO.MsoBarPosition.msoBarLeft ;
myCommandBar.Visible = true;

// try to find my button CommandBar
myButton = (MSO.CommandBarButton) myCommandBar.FindControl
(MSO.MsoControlType.msoControlButton ,myMissing, "XMail0.1", myMissing,
false);

// If we found our Button, we can use it
if (myButton == null)
{
// if not we create one
myButton = (MSO.CommandBarButton)
myCommandBar.Controls.Add (MSO.MsoControlType.msoControlButton, myMissing,
myMissing,myMissing, false);

myButton.Caption = "XMail";
myButton.Tag = "XMail0.1";
}

If i ever come to montana i will bring you a good bavarian beer ;-)

--
Freundliche Grüße / with regards

Helmut Obertanner
Technical Consultant

Softwaredevelopment
DATALOG Software AG | Zschokkestr. 36 | D-80687 Munich
web: www.datalog.de


.... and IT works!

I noticed the difference in case between the tag label (syncButton.Tag
= "Sync") and the label (I guess?) being searched for above
(CommandBarButton)commandBars[­"Standard"].Controls["sync"];), and
fixed the discrepency. No difference in functionality.

-cuke
 

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