【问题标题】:Visual Studio Addin - Cant Create Child Menu ItemsVisual Studio 插件 - 无法创建子菜单项
【发布时间】:2010-12-07 06:19:44
【问题描述】:

我正在尝试为 Visual Studio 2008 插件创建基本菜单结构。到目前为止,我可以创建第一个顶级菜单,在下面的示例中我称之为 TOPMENU。我正在努力弄清楚如何将子项目添加到 TOPMENU。我已经尝试了多种方法,但无法弄清楚。有人可以帮我完成下面的代码吗?当我尝试在下面创建对象“a2”时,我目前遇到了无效的强制转换异常。

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_UISetup)
 {
  object[] contextGUIDS = new object[] { };
  Commands2 commands = (Commands2)_ApplicationObject.Commands;
  CommandBar cbMainMenu = ((CommandBars)_ApplicationObject.CommandBars)["MenuBar"];

  try
  {
   // ROOT MENU
   Command cmdProjectManagement = commands.AddNamedCommand2(_AddInInstance, "TOPMENU", "TOPMENU", "",
    true, null, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
    (int)vsCommandStyle.vsCommandStyleText, vsCommandControlType.vsCommandControlTypeButton);

   if (cmdProjectManagement != null)
    cmdProjectManagement.AddControl(cbMainMenu, cbMainMenu.Controls.Count);

   // SUB ITEM
   Command cmdCompiledAssemblies = commands.AddNamedCommand2(_AddInInstance, "TOPMENU_CompiledAssemblies", "Compiled Assemblies", String.Empty,
    true, null, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
    (int)vsCommandStyle.vsCommandStyleText, vsCommandControlType.vsCommandControlTypeButton);

   CommandBarControl a1 = cbMainMenu.Controls["TOPMENU"];
   CommandBarPopup a2 = (CommandBarPopup)a1;

   if (cmdCompiledAssemblies != null)
    cmdCompiledAssemblies.AddControl(a2.CommandBar, 1);
  }
  catch (Exception ex)
  {
  }
 }
}

【问题讨论】:

  • 您是如何在 TopMenu 下方创建多个子菜单和分隔线的?

标签: visual-studio-2008 menu add-in


【解决方案1】:

关于如何创建各种菜单和工具栏的完整文档在这里..

http://www.mztools.com/articles/2005/mz2005003.aspx

【讨论】:

    猜你喜欢
    • 2011-05-21
    • 2012-08-28
    • 1970-01-01
    • 1970-01-01
    • 2013-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多