views:

25

answers:

1

Is it possible to create an add a custom menu to the main menu bar in Visual Studio within an Add-In?

I want the Add-In to create a company specific menu if it does not already exist and then add its own specific command to that menu. That way if multiple Add-Ins are supplied then they can all add the commands to the same menu.

I have found an msdn link for a walkthrough in creating a VSPackage which does this but not from within an Add-In and it requires its own specific installation/registration.

A: 
    public static CommandBarControl GetCustomMenu(DTE2 applicationObject)
    {
        //Find the MenuBar command bar, which is the top-level command bar holding all the main menu items
        CommandBar menuBarCommandBar = ((CommandBars)applicationObject.CommandBars)["MenuBar"];

        //Find the Tools command bar on the MenuBar command bar as we want to add it before it
        CommandBarControl toolsControl = menuBarCommandBar.Controls["Tools"];

        CommandBarControl myMenu;

        try
        {
            // Get the menu bar if it already exists
            myMenu = menuBarCommandBar.Controls["My Menu"];
        }
        catch (Exception)
        {
            // Doesnt exist so crate a new one.
            myMenu = menuBarCommandBar.Controls.Add(Type: MsoControlType.msoControlPopup, Id: 1234567890, Before: toolsControl.Index - 1);
            myMenu.Caption = "My Menu"];;
        }
        return myMenu;
    }
gouldos