Hello,
see here (nearly end of thread):
http://www.outlookcode.com/threads.aspx?forumid=5&messageid=10480
when create the Bar loop over the buttons and cleanup.
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";
}
--
greets,
Helmut Obertanner
Technical Consultant
Softwaredevelopment
DATALOG Software AG | Zschokkestr. 36 | D-80687 Munich
web:
www.datalog.de
... and IT works!
Hi Helmut,
I tried placing the syncButton.delete inside the active inspector's
close event, and while it had no effect on OLK2003 (this is good), it
has resulted in very strange behavior on OLK2002. For any given
session the behavior is good (new buttons are not added).
However, when Outlook closes and then is opened again, various things
seem to happen:
1) A new Sync button is added on the first email opened.
2) Sometimes the Outlook session is closed down behind the email
opened. (?)
3) I received a COM error one time (not readily reproducable) that
says that the synchButton could not be deleted.
The flakiness leads me to believe there's a problem in the
surrounding code, let me explain the basic process and see if it makes
sense:
AddIn.onConnect:
Grab instance of the Outlook object.
AddIn.OnStartUpComplete:
Grab an instance of the Application Object's inspector.
Add an event handler to the inspector to be fired when a
"NewInspectorEvent" happens.
AddIn.NewInspectorEventHandler:
Check inspector.currentItem. If it's a mail item, launch a new
'SynchMail' object.
AddIn.Disconnect
if the Inspector isn't null, Release it.
if the Application Object isn't null, Release it.
Garbage Collect
SynchMail.constructor
Get active mail item.
Add event handler to active mail item.open
SynchMail.activeMailItemOpenHandler
Remove event
grab the mail item's active inspector
Add a close event handler to activeMailItem.
Call addUI
SynchMail.AddUI
Create a button on the standard task bar
Add event handler to the button
SynchMail.HandleButtonPressed
Do my functionality
SynchMail.CloseEventHandler
Remove the CloseEventHandler from the active inspectors events
delete the button.
release the active inspector
release the active mail item
In a little more testing I've discovered much to my chagrin that the
'outlook closing itself' issue happens on both OLK2003 and OLK2002 at
this point. I'm suspicious of my logic flow, but really am in the dark
about what I could be doing wrong.
As an aside, do you know how to reset the toolbar on OLK2002? When I
am in a mail message (where all the spurrious synch buttons are), the
'add or remove buttons' menu items are both greyed out.
Cheers,
'cuke
Helmut Obertanner wrote:
Hello seacuke,
remove the button in InspectorClose event.
just syncButton.Delete(false);
--
regards
Helmut Obertanner
Technical Consultant
Softwaredevelopment
DATALOG Software AG | Zschokkestr. 36 | D-80687 Munich
web:
www.datalog.de
... and IT works!
I've created an add-in that I've been testing on Outlook 2003.
Basically the add-in creates a button on the standard toolbar for
an
email; the call to add the button is below:
syncButton =
(CommandBarButton)commandBars["Standard"].Controls.Add(
Microsoft.Office.Core.MsoControlType.msoControlButton,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value,
4,
true);
The last value (true) is indicating whether the button is temporary
or
not.
On OLK2003, the button functions just fine - It's created on
launching
an email, and disappears when the email is closed.
On OLK2002, the temporary flag is seemingly ignored, for each email
I
open, a new 'synchronize' button appears (so soon my toolbar is
full of
them).
I'm using the PIA "Microsoft Outlook 11.0 Object Library" version
9.2.
Thanks in advance,
'cuke