Aleks Kleyn
unread,Mar 18, 2012, 4:53:03 PM3/18/12You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
I want to create add in in visual studio 11 which uses menu like
tools->mnu1->mnu11. After some trials I wrote following code
CommandBarControl toolsControl =
menuBarCommandBar.Controls[toolsMenuName];
CommandBarPopup toolsPopup = (CommandBarPopup)toolsControl;
//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.
Command commandMnu1;
Command commandMnu11;
try
{
//Add a command to the Commands collection:
commandMnu1 = commands.AddNamedCommand2(_addInInstance,
"Mnu1", "Mnu1",
"Executes the command for Addin Mnu1", 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((commandLaTeX != null) && (toolsPopup != null))
{
commandLaTeX.AddControl(toolsPopup.CommandBar, 1);
}
}
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.
commandMnu1 = (Command)toolsControl;
}
Microsoft.VisualStudio.CommandBars.CommandBar menuBarTools
= ((Microsoft.VisualStudio.CommandBars.CommandBars)
_applicationObject.CommandBars)[toolsMenuName];
string toolsMnu1 = "Mnu1";
CommandBarControl toolsControlMnu1
= (CommandBarControl)(menuBarTools.Controls[toolsMnu1]);
//CommandBarPopup toolsMnu1 =
(CommandBarPopup)toolsControlMnu1;
commandMnu11 = commands.AddNamedCommand2(_addInInstance,
"Mnu11", "Mnu11",
"Executes the theorem for Mnu11", true, 59,
ref contextGUIDS,
(int)vsCommandStatus.vsCommandStatusSupported
+ (int)vsCommandStatus.vsCommandStatusEnabled,
(int)vsCommandStyle.vsCommandStylePictAndText,
vsCommandControlType.vsCommandControlTypeButton);
try
{
//Add a command to the Commands collection:
//Add a control for the command to the tools menu:
if ((commandMnu11 != null) && (toolsControlLaTeX !=
null))
{
commandMnu11.AddControl(toolsControlMnu1.CommandBar,
1);
}
}
catch (System.ArgumentException /*anErr*/)
{
//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.
commandMnu11.AddControl(toolsPopup.CommandBar, 1);
}
However when I debugged I discovered that toolsControlMnu1 is different
object then toolsPopup and does not have property CommandBar. What I should
change in this code?
Thank you