How do I add an entry to the Menu in the Solution Explorer??
Jeries Shahin
Command solutionExplorerCommand = _applicationObject.Commands.AddNamedCommand(_addInInstance, "IDESolutionExplorerContextMenu", "IDE Solution Explorer Context Menu", "Executes IDE Solution Explorer Context Menu", true, 100, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled);
Microsoft.VisualStudio.CommandBars.CommandBar projectCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["Project"];
Microsoft.VisualStudio.CommandBars.CommandBarControl projectCommandBarControl = (Microsoft.VisualStudio.CommandBars.CommandBarControl)solutionExplorerCommand.AddControl(projectCommandBar, projectCommandBar.Controls.Count);
projectCommandBarControl.Caption = "IDE Solution Explorer Context Menu Caption";
BTW I have decided to add the context menu to the Object Browser, any idea how to get a handle to this window
Thanks.
alipunk
Creating a menu item and a wizard are two seperate concepts. Creating a menu item involves walking through the object model for command bars, locating the correct CommandBar object, and adding an item to it.
Creating a wizard involves creating a .vsz file and putting that vsz file into the correct location on disk so that it can be found by either the New Project or Add New Item dialog boxes. I am not familiar with the SQL tools, but running a wizard involves finding the directory on disk to put the vsz file, not modifying the menu. It is possible that the SQL tools do not allow you to show the Add New Item dialog box, in that case you will need to find a new method to show the .vsz file - like adding a menu item to show a custom dialog to allow you to start the wizard running.
Craig
Parag Kudtarkar
B o g d a n
learnerplates wrote:
Hi Sami,
Thanks for that but it doesn't seem to work for my implementation, which line of code in particulat is adding the command to the Solution Explorer
AravananRaman
{
Command cmd1;
Microsoft.VisualStudio.CommandBars.CommandBar cmdBar;
CommandBarControl cmdBarCtl1;
_addInInstance = (AddIn)addInInst;
{
try
{
object[] contextGUIDS = new object[] { };
cmdBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["Project"];
cmdBarCtl1 = (Microsoft.VisualStudio.CommandBars.CommandBarControl)cmd1.AddControl(cmdBar, cmdBar.Controls.Count);
cmdBarCtl1.Caption = "My new command";
}
catch
{
System.Windows.Forms.MessageBox.Show("Command could not be added to the menu context!");
}
}
}

How do I add an entry to the Menu in the Solution Explorer??
DocJames
Hi,
To add a menu entry to a context menu is the same that adding it to any VS menu or toolbar. All of them work with command bars (of 3 kinds: menu, toolbar, commandbar popup). So, you don’t use a handle at all. All you need to know is the name of the commandbar popup that a window is using as context menu. The Solution Explorer uses quite a few depending on the selected item(s) such as "Project", etc. To guess the name of the commandbar used by the Object Browser as context menu (if it is not internal to it, I am not sure) see if this helps:
HOWTO: Guessing the name of a command bar to add a custom menu entry in Visual Studio .NET add-ins
http://www.mztools.com/articles/2004/MZ002.htm
Atosecond
Thanks for that but it doesn't seem to work for my implementation, which line of code in particulat is adding the command to the Solution Explorer
Armageddon
I'm trying to do much the same thing but haven't succeeded, did the "Project" add a new menu item to the Solution Explorer for you, it didn't for me , just added it to the Menu Project and not the right click menu.
Here's what I'm using:
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 projectMenuName;
try
{
ResourceManager resourceManager = new ResourceManager("MyAddin.CommandBar", Assembly.GetExecutingAssembly());
CultureInfo cultureInfo = new System.Globalization.CultureInfo(_applicationObject.LocaleID);
string resourceName = String.Concat(cultureInfo.TwoLetterISOLanguageName, "Project");
projectMenuName = resourceManager.GetString(resourceName);
}
catch
{
//We tried to find a localized version of the word Tools, but one was not found.
// Default to the en-US word, which may work for the current culture.
projectMenuName = "Project";
}
try
{
Command solutionExplorerCommand = commands.AddNamedCommand2(_addInInstance, "MyContextMenu", "My Command", "Executes My command 1", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,(int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar2 = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["MenuBar"];
CommandBarControl projectControl = menuBarCommandBar2.Controls[projectMenuName];
CommandBarPopup projectPopup = (CommandBarPopup)projectControl;
if ((solutionExplorerCommand != null) && (projectPopup != null))
{
solutionExplorerCommand.AddControl(projectPopup.CommandBar, 1);
}
}
catch
{
}
}
}
Bill S
Devi48354