If you have ever added Acrobat (the full version) to you system, it has a toolbar that no matter what you do - the next time you start Word it pops back up in the same start location. Personally I find this very annoying.
So if you have a toolbar in your Word Add-in, here is how you have it come back up in the state that the user last put it in.
Part 1:
public void OnBeginShutdown(ref Array custom)
{
CommandBars bars = (CommandBars) ThisApplication.GetType().InvokeMember("CommandBars",
System.Reflection.BindingFlags.GetProperty, null, ThisApplication, null);
foreach (CommandBar barOn in bars)
{
if(barOn.Name == "AutoTag")
{
RegistryKey key = Registry.LocalMachine.CreateSubKey(Util.regBase);
if (key != null)
{
key.SetValue("toolbar_visible", barOn.Visible);
key.SetValue("toolbar_position", barOn.Position);
key.SetValue("toolbar_left", barOn.Left);
key.SetValue("toolbar_top", barOn.Top);
key.SetValue("toolbar_row", barOn.RowIndex);
key.SetValue("toolbar_width", barOn.Width);
key.SetValue("toolbar_height", barOn.Height);
key.Close();
}
}
}
}
Part 2 - in your startup code:
CommandBars bars = (CommandBars) ThisApplication.GetType().InvokeMember("CommandBars",
System.Reflection.BindingFlags.GetProperty, null, ThisApplication, null);
toolbar = bars.Add("AutoTag", MsoBarPosition.msoBarTop, false, true);
for (int ind=0; ind<toolItems.Length; ind++)
InitToolbar(ind, toolItems[ind]);
RegistryKey key = Registry.LocalMachine.OpenSubKey(Util.regBase);
if (key != null)
{
String pos = (string) key.GetValue("toolbar_position", MsoBarPosition.msoBarTop);
toolbar.Position = (MsoBarPosition) MsoBarPosition.Parse(typeof(MsoBarPosition), pos);
int num = (int) key.GetValue("toolbar_left", -1);
if (num != -1)
toolbar.Left = num;
if (toolbar.Position == MsoBarPosition.msoBarFloating)
{
num = (int) key.GetValue("toolbar_top", -1);
if (num != -1)
toolbar.Top = num;
num = (int) key.GetValue("toolbar_width", -1);
if (num != -1)
toolbar.Width = num;
num = (int) key.GetValue("toolbar_height", -1);
if (num != -1)
toolbar.Height = num;
} else
{
num = (int) key.GetValue("toolbar_row", -1);
if (num != -1)
toolbar.RowIndex = num;
num = (int) key.GetValue("toolbar_top", -1);
if (num != -1)
toolbar.Top = num;
}
toolbar.Visible = ((String)key.GetValue("toolbar_visible", "true")).ToLower() == "true";
key.Close();
} else
toolbar.Visible = true;
Do you find this useful? If so please check out Windward Reports.