Visual Studio Addin - 子菜单项未出现
已成功创建顶部菜单项,尝试创建第一个子项,但没有出现,也没有抛出异常...
void IDTExtensibility2.OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
_ApplicationObject = (DTE2)application;
_AddInInstance = (AddIn)addInInst;
if (connectMode == ext_ConnectMode.ext_cm_Startup)
{
object[] contextGUIDS = new object[] { };
Commands2 commands = (Commands2)_ApplicationObject.Commands;
CommandBars commandBars = (CommandBars)_ApplicationObject.CommandBars;
CommandBar cbMainMenu = commandBars["MenuBar"];
try
{
// ROOT MENU
CommandBarPopup cbpProjectManagement = (CommandBarPopup)cbMainMenu.Controls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, cbMainMenu.Controls.Count, true);
cbpProjectManagement.Caption = "ROOTMENU";
// SUB ITEM
Command cmdCompiledAssemblies = _ApplicationObject.DTE.Commands.AddNamedCommand(_AddInInstance, "VSPM_CA", "CA",
String.Empty, true, 0, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled);
CommandBarControl cbcCompiledAssemblies = (CommandBarControl)cmdCompiledAssemblies.AddControl(cbpProjectManagement.CommandBar, 1);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.ToString());
}
}
}
Have successfully created the top menu item, trying to create first child item but is not appearing and no exception is being thrown...
void IDTExtensibility2.OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
_ApplicationObject = (DTE2)application;
_AddInInstance = (AddIn)addInInst;
if (connectMode == ext_ConnectMode.ext_cm_Startup)
{
object[] contextGUIDS = new object[] { };
Commands2 commands = (Commands2)_ApplicationObject.Commands;
CommandBars commandBars = (CommandBars)_ApplicationObject.CommandBars;
CommandBar cbMainMenu = commandBars["MenuBar"];
try
{
// ROOT MENU
CommandBarPopup cbpProjectManagement = (CommandBarPopup)cbMainMenu.Controls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, cbMainMenu.Controls.Count, true);
cbpProjectManagement.Caption = "ROOTMENU";
// SUB ITEM
Command cmdCompiledAssemblies = _ApplicationObject.DTE.Commands.AddNamedCommand(_AddInInstance, "VSPM_CA", "CA",
String.Empty, true, 0, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled);
CommandBarControl cbcCompiledAssemblies = (CommandBarControl)cmdCompiledAssemblies.AddControl(cbpProjectManagement.CommandBar, 1);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.ToString());
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有关如何创建各种菜单和工具栏的完整文档位于此处
。 mztools.com/articles/2005/mz2005003.aspx
Full documentation on how to create all sorts of menu's and toolbar's here..
http://www.mztools.com/articles/2005/mz2005003.aspx
我知道这个主题确实很老 - 但我遇到了同样的问题并最终找到了解决方案:
在 QueryStatusMethod 中,您必须检查您的命令(您在上面构建的)并返回有效的状态,例如:
I know this topic is really old - but I had the same problem and finally found the solution:
In the QueryStatusMethod you have to check your command (which you built above) and return a valid status, for example: