Outlook Commandbar keeps reappearing after restarting Outlook

Add-in Express™ Support Service
That's what is more important than anything else

Outlook Commandbar keeps reappearing after restarting Outlook
Outlook Commandbar keeps reappearing after restarting Outlook 
Wolfgang Denz




Posts: 18
Joined: 2011-08-05
My Outlook-plugin shows an Outlook-2007 commandbar and works pretty well.
But when a user disables/hides my custom commandbar and restarts Outlook, the commandbar is enabled/visble again.

I set my commandbar to "temporary = true", but no change so far

What am I doing wrong?

Thansk
Wolfgang Denz
Posted 08 Nov, 2012 01:40:03 Top
Andrei Smolin


Add-in Express team


Posts: 18825
Joined: 2006-05-11
Hello Wolfgang,

I assume you use an ADXOlCommandBar component to create your toolbar. If so, please check http://www.add-in-express.com/forum/read.php?FID=5&TID=3639.

Wolfgang Denz writes:
I set my commandbar to "temporary = true"


Outlook commandbars should always have "temporary = true", see the section How Command Bars and Their Controls Are Created and Removed? in the manual.


Andrei Smolin
Add-in Express Team Leader
Posted 08 Nov, 2012 01:49:42 Top
Wolfgang Denz




Posts: 18
Joined: 2011-08-05
Hello Andrei,

thanks for your fast response, but I already found the above post and it's not my problem.
My commandbar is not dynamic, but is visible all the time.
Still the user can deactivate ribbons or commandbars with the standard contextmenu of outlook to show or hide them.
If a user decides to hide my commandbar it disappears until the next restart of Outlook 2007.
After the restart my commandbar is shown again automatically.

Best regards
Wolfgang
Posted 08 Nov, 2012 01:57:26 Top
Andrei Smolin


Add-in Express team


Posts: 18825
Joined: 2006-05-11
Wolfgang,

Here's some code demonstrating another approach: you intercept CommnadbarsUpdate to get notified when the user turns your commandbar off.

        private void adxOutlookEvents_NewExplorer(object sender, object explorer)
        {
            System.Diagnostics.Debug.WriteLine("!!! NewExplorer. Toolbar.Visible = " + 
                adxOlExplorerCommandBar1.Visible.ToString());
        }

        private void AddinModule_AddinStartupComplete(object sender, EventArgs e)
        {
            Outlook.Explorers explorers = OutlookApp.Explorers;
            if (explorers.Count != 0)
            {
                System.Diagnostics.Debug.WriteLine("!!! AddinStartupComplete. Explorers.Count != 0");
                System.Diagnostics.Debug.WriteLine("!!! AddinStartupComplete. Toolbar.Visible = " + adxOlExplorerCommandBar1.Visible.ToString());
            }
            else
                System.Diagnostics.Debug.WriteLine("!!! AddinStartupComplete. Explorers.Count == 0");
            Marshal.ReleaseComObject(explorers);
        }

        private void AddinModule_AddinBeginShutdown(object sender, EventArgs e)
        {
            // At this time, the command bar component is already disconnected, 
            // and adxOlExplorerCommandBar1.IsConnected is false,
            // so the Visible property returns its design-time settings.
            // To write a correct value to the registry, you need to trace the 
            // toolbar visibility at run-time. See adxOutlookEvents_CommandBarsUpdate.
            System.Diagnostics.Debug.WriteLine("!!! AddinBeginShutdown. Writing 'Visible = " + 
                adxOlExplorerCommandBar1.Visible.ToString() + 
                "' to the registry");
            Microsoft.Win32.Registry.SetValue(myKey, "CommandBarVisible", lastVisible, Microsoft.Win32.RegistryValueKind.DWord);
        }

        private void AddinModule_AddinInitialize(object sender, EventArgs e)
        {
            string rootKey = "";
            if (this.RegisterForAllUsers)
                rootKey = "HKEY_LOCAL_MACHINE";
            else
                rootKey = "HKEY_CURRENT_USER";
            myKey = rootKey + "\" + this.RegistryKey + "\My";

            System.Diagnostics.Debug.WriteLine("!!! AddinInitialize. Toolbar.Visible = " +
    adxOlExplorerCommandBar1.Visible.ToString());

            // At this time, the command bar component isn't connected yet, 
            // and adxOlExplorerCommandBar1.IsConnected is false,
            // so the Visible property returns its design-time settings            
            
            bool visible = Convert.ToBoolean(
                Microsoft.Win32.Registry.GetValue(
                    myKey, "CommandBarVisible", adxOlExplorerCommandBar1.Visible)
                    );
            System.Diagnostics.Debug.WriteLine("!!! AddinInitialize. The initial setting is 'Visible = " + visible.ToString() + "'");
            if (!visible)
                this.adxOlExplorerCommandBar1.ItemTypes = AddinExpress.MSO.ADXOlExplorerItemTypes.olUnknownItem;
        }

        private void adxCommandBarButton2_Click(object sender)
        {
            this.adxOlExplorerCommandBar1.ItemTypes = AddinExpress.MSO.ADXOlExplorerItemTypes.olMailItem;
            this.adxOlExplorerCommandBar1.Enabled = true;
            this.adxOlExplorerCommandBar1.Visible = true;
        }

        private void adxOutlookEvents_CommandBarsUpdate(object sender, EventArgs e)
        {
            // At this time, the command bar component is connected, 
            // and adxOlExplorerCommandBar1.IsConnected is true,
            // so the Visible property reflects the actual state of the toolbar
            lastVisible = adxOlExplorerCommandBar1.Visible;
            System.Diagnostics.Debug.WriteLine("!!! CommandBarsUpdate. 'lastVisible = " + lastVisible.ToString() + "'");
            //if (!lastVisible)
            //    if (!adxOlExplorerCommandBar1.Enabled)
            //        adxOlExplorerCommandBar1.Enabled = true;
        }


If you use VB.NET, you can use any free CSharp to VB.NET converter available online e.g. http://www.developerfusion.com/tools/convert/csharp-to-vb/.


Andrei Smolin
Add-in Express Team Leader
Posted 08 Nov, 2012 02:25:01 Top