-
February 16th, 2012, 03:07 PM
#1
Visual Studio Add in Menu Not Showing Up
I am using the following code to add a menu to visual studio here is the complete function (see below)
it works fine; the problem is when i take it to a test station (I mean when I move the dll), when I first open visual studio it shows the menu, then when I close visual studio and open it back, the menu does not show up
if I change the code when I put the menu under the tools menu, there is not problem
is there a way to fix that. I know by default visual studio add add in command to the tools menu, there must be a way to fix that
PHP Code:
public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;
if(connectMode == ext_ConnectMode.ext_cm_UISetup)
{
object []contextGUIDS = new object[] { };
Commands2 commands = (Commands2)_applicationObject.Commands;
string testMenuName = "Test";
//Place the command on the tools menu.
//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 Test command bar on the MenuBar command bar. This is the "before" parameter to add new command bar:
CommandBarControl testControl = menuBarCommandBar.Controls[testMenuName];
//This try/catch block can be duplicated if you wish to add multiple commands to be handled by your Add-in,
// just make sure you also update the QueryStatus/Exec method to include the new command names.
try
{
//Create new MyAddin8 command bar
CommandBarControl myControl = (CommandBarControl)menuBarCommandBar.FindControl(MsoControlType.msoControlPopup, System.Type.Missing, "MyAddin8", true, true);
if (myControl == null)
{
//Create new MyAddin8 command bar
myControl = menuBarCommandBar.Controls.Add(Type: MsoControlType.msoControlPopup, Id: 1234567890, Before: testControl.Index);
myControl.Caption = "MyAddin8";
}
CommandBarPopup myControlPopup = (CommandBarPopup)myControl;
//Add a command to the Commands collection:
Command command = commands.AddNamedCommand2(_addInInstance, "MyCommand1", "MyCommand1", "Executes the command for MyCommand1", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported+(int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
//Add a control for the command to the tools menu:
if((command != null) && (myControl != null))
{
command.AddControl(myControlPopup.CommandBar);
}
//Add another command to the Commands collection:
Command command2 = commands.AddNamedCommand2(_addInInstance, "MyCommand2", "MyCommand2", "Executes the command for MyCommand2", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
//Add a control for the command to the tools menu:
if ((command2 != null) && (myControl != null))
{
command2.AddControl(myControlPopup.CommandBar, 2);
}
}
catch(System.ArgumentException)
{
//If we are here, then the exception is probably because a command with that name
// already exists. If so there is no need to recreate the command and we can
// safely ignore the exception.
}
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|