Problem adding a menu to Visio on startup

S

sh856531

Hi Guys,

Can anyone tell me why the following code doesn't work. I've spent 2 hours
trying various permutations and it's driving me mad. I don't know if it makes
any difference but I'm using VSTO (Visual Studio 2008) and I run it just by
pressing F5.

Visio pops up but no matter what I try, no menu appears! :-(

Thanks to anyone who can help me with this!

Simon

// All variables are declared at the class level
private void ThisAddIn_Startup(object sender, System.EventArgs e) {

// Base the new menu structure off of the current built in menu
structure. We need to keep a reference to this object to update the UI later
customMenuStructure = Application.BuiltInMenus;

UIObject customMenus = Application.CustomMenus;

// Get the menu set for the drawing window and add a new menu
primaryMenuSet =
Application.BuiltInMenus.MenuSets.get_ItemAtID((short)VisUIObjSets.visUIObjSetDrawing);
customMenu = primaryMenuSet.Menus.AddAt(2);

customMenu.Caption = "This is my new menu";

menuItem = customMenu.MenuItems.Add();

menuItem.Caption = "Import XML";
menuItem.AddOnName = "Whatever";
menuItem.AddOnArgs = "Whatever";

Application.SetCustomMenus(customMenuStructure);

// Apparently this is required to update the menus with our
changes
customMenuStructure.UpdateUI();

}
 

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

Similar Threads


Top