Detecting whether a toolbar is and should be shown

  • Thread starter Thread starter Brunwin
  • Start date Start date
B

Brunwin

I have two toolbars I've implemented in Outlook using VSTO 2005 SE - one
inspector commandbar and one explorer commandbar. At the moment they both
launch when the relevant window is launched and add themselves to the
commandbars list.
The flaw with this is that when the user right clicks on the toolbar area
and unticks my commandbar, hiding it, then shuts Outlook and reopens it my
commandbar naively reloads itself into the toolbar area. Really it should
wait until the user re-ticks it's name before it appears. To be able to do
this I'd need to be able to either detect whether my commandbar is visible or
detect when my commandbar is hidden and when it is made visible. I can't
seem to identify within the VSTO 2005 API a way to do this. I presume though
that this is something that a commandbar should support so I expect I'm just
not finding the right way to do it.
Does anyone know how I should be doing this and what properties/events I
need to use for it?

Thanks in advance
 
When the window is closed, either Inspector or Explorer, check your
toolbar's Visible and Enabled properties and persist that information
somewhere. Use that the next time.
 
Thanks. There was an additional trick to it as follows. By using the
visible property from the most recently opened (still open) window's toolbar
and saving the visible property when a toolbar closes to use when no already
open window exists the standard Outlook toolbar behaviour can be replicated.

Thanks,
Nick
 
Ok. I think it's fairer to say this solution works on XP with Office 2003.

With Vista and Office 2003 the close event isn't fired on the inspector
window when the "Save and Close" button is pressed.
With Office 2007 there isn't the right click show/hide (tick/untick) toolbar
option with ribbons but instead an option to delete the custom toolbar. The
deleting of the custom toolbar I can't detect in the code so I can't record
it so that my toolbar launches hidden.

Does anyone know how to work around either of these problems?

Thanks,
Nick
 
1. Handle the item.Close() event in addition to the Inspector.Close() event.

2. No event when a custom toolbar is deleted in Outlook 2007's ribbon, but
in Outlook 2007 you should be using the ribbon and not CommandBars in an
Inspector anyway. And if the toolbar is deleted then when you iterate the
CommandBars collection of the Inspector you won't find it there, so you can
assume it was deleted.
 
Thanks.

1 worked. I don't think in VSTO 2005 SE I can do 2 though. I think it
points towards having to split the codebase for Office 2003 and Office 2007
in the future though.
 
Thanks.

1 worked. I don't think in VSTO 2005 SE I can do 2 though. I think it
points towards having to split the codebase for Office 2003 and Office 2007
in the future though.
 
VSTO or any other technology or language, Outlook 2003 or 2007:

Office.CommandBar bar = null;

int count = insp.CommandBars.Count;
for (int i = 1; i <= count; i++)
{
bar = (Office.CommandBar)insp.CommandBars;
if (bar.Name == myBar.Name)
{
bool barVisible = bar.Visible;
}
}

Of course if you are developing for Outlook 2003 in VSTO the point is moot,
since that won't support the ribbon unless you use something like the
PIA-less methods mentioned by Andrew Whitechapel of the VSTO team on his
blog. But access to the CommandBars collections is not a reason to fork any
code.
 
Back
Top