Visual Studio Addin - 子菜单项未出现

发布于 2024-10-06 17:04:20 字数 1459 浏览 0 评论 0原文

已成功创建顶部菜单项,尝试创建第一个子项,但没有出现,也没有抛出异常...

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

愁杀 2024-10-13 17:04:21

有关如何创建各种菜单和工具栏的完整文档位于此处

。 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

dawn曙光 2024-10-13 17:04:21

我知道这个主题确实很老 - 但我遇到了同样的问题并最终找到了解决方案:

在 QueryStatusMethod 中,您必须检查您的命令(您在上面构建的)并返回有效的状态,例如:

    public void QueryStatus(string commandName, vsCommandStatusTextWanted neededText, ref vsCommandStatus status, ref object commandText)
    {
        if(neededText == vsCommandStatusTextWanted.vsCommandStatusTextWantedNone)
        {
            if (commandName == "MetatoolVSAddin.Connect.AddInAboutButton")
            {
                status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported|vsCommandStatus.vsCommandStatusEnabled;
                return;
            }
        }
    }

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:

    public void QueryStatus(string commandName, vsCommandStatusTextWanted neededText, ref vsCommandStatus status, ref object commandText)
    {
        if(neededText == vsCommandStatusTextWanted.vsCommandStatusTextWantedNone)
        {
            if (commandName == "MetatoolVSAddin.Connect.AddInAboutButton")
            {
                status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported|vsCommandStatus.vsCommandStatusEnabled;
                return;
            }
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文