2010-12-07 8 views
0

私はVisual Studio 2008アドインの基本的なメニュー構造を作成しようとしています。これまで私は、私の例では、私はTOPMENUと呼ばれている最初のトップレベルメニューを作成することができます。 TOPMENUに子アイテムを追加する方法を理解するのには苦労しています。私は様々な方法を試してみて、それを理解することはできません。誰かが下のコードを完成させる助けになることができますか?私は現在、以下のオブジェクト "a2"を作成しようとすると、無効なキャスト例外が発生しています。Visual Studio Addin - Cantは子メニュー項目を作成します

メニューのすべての種類を作成する方法について
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) 
    { 
    } 
} 
} 
+0

どのようにして、トップメニュー以下、いくつかのサブメニューおよびセパレータ行を作成しましたか? – Kiquenet

答えて

関連する問題