2010-12-08 29 views
0

已成功創建頂級菜單項,試圖創建的第一個孩子項目,但沒有出現,沒有異常被拋出...如何Visual Studio的外接程序 - 子菜單項未出現

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()); 
     } 
    } 
} 
+0

任何有關它的解決方案嗎? – Kiquenet 2011-08-16 12:14:28

回答

0

我知道這個題目是真的老了 - 但我有同樣的問題,終於找到了解決辦法:

在你要檢查你的命令(你在上面建),並返回一個有效的狀態,例如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; 
      } 
     } 
    } 
相關問題