I received an answer from another newgroup and thought I would include it
here for the sake of completion:
=================================================
Perhaps not the most elegant solution but the working example below
does do what you expect - Steve.
namespace MyAddin1
{
using System;
using Microsoft.Office.Core;
using Extensibility;
using System.Runtime.InteropServices;
using EnvDTE;
[GuidAttribute("12795A44-2D50-448D-8A4B-7829E5E38BED"), ProgId
("MyAddin1.Connect")]
public class Connect : Object,
Extensibility.IDTExtensibility2, IDTCommandTarget
{
public Connect() {}
public void OnConnection(object application,
Extensibility.ext_ConnectMode connectMode, object addInInst, ref
System.Array custom)
{
applicationObject = (_DTE)application;
addInInstance = (AddIn)addInInst;
object []contextGUIDS = new object[] { };
Commands commands =
applicationObject.Commands;
_CommandBars commandBars =
applicationObject.CommandBars;
try
{
Command command =
commands.AddNamedCommand
(addInInstance, "MyAddin1", "MyAddin1", "Executes the command for
MyAddin1", true, 59, ref contextGUIDS, (int)
vsCommandStatus.vsCommandStatusSupported+(int)
vsCommandStatus.vsCommandStatusEnabled);
Command command2 =
commands.AddNamedCommand
(addInInstance, "MyAddin2", "MyAddin2", "Executes the command for
MyAddin2", true, 59, ref contextGUIDS, (int)
vsCommandStatus.vsCommandStatusSupported+(int)
vsCommandStatus.vsCommandStatusEnabled);
CommandBar commandBar = (CommandBar)
commandBars["Tools"];
CommandBarControl commandBarControl =
command.AddControl(commandBar, 1);
CommandBarControl commandBarControl2
= command2.AddControl(commandBar, 2);
}
catch(System.Exception /*e*/)
{
}
}
public void OnDisconnection
(Extensibility.ext_DisconnectMode disconnectMode, ref System.Array
custom) {}
public void OnAddInsUpdate(ref System.Array custom) {}
public void OnStartupComplete(ref System.Array
custom) {}
public void OnBeginShutdown(ref System.Array custom)
{}
public void QueryStatus(string commandName,
EnvDTE.vsCommandStatusTextWanted neededText, ref
EnvDTE.vsCommandStatus status, ref object commandText)
{
if(neededText ==
EnvDTE.vsCommandStatusTextWanted.vsCommandStatusTextWantedNone)
{
if(commandName.StartsWith
("MyAddin1.Connect"))
{
status = (vsCommandStatus)
vsCommandStatus.vsCommandStatusSupported|vsCommandStatus.vsCommandStat
usEnabled;
if (commandName ==
_justLatched)
status |=
vsCommandStatus.vsCommandStatusLatched;
}
}
}
public void Exec(string commandName,
EnvDTE.vsCommandExecOption executeOption, ref object varIn, ref
object varOut, ref bool handled)
{
handled = false;
if(executeOption ==
EnvDTE.vsCommandExecOption.vsCommandExecOptionDoDefault)
{
if(commandName.StartsWith
("MyAddin1.Connect"))
{
_justLatched = commandName;
handled = true;
return;
}
}
}
private _DTE applicationObject;
private AddIn addInInstance;
private string _justLatched = string.Empty;
}
}
> I'm creating an Add-in and have a top-level menu item (command popup) next to
> the Tools menu item in VS IDE. Under that top-level menu, I have a few more
[quoted text clipped - 11 lines]
> TIA,
> RR