Commands Interface
Assembly: EnvDTE (in envdte.dll)
Imports Microsoft.VisualStudio.CommandBars Sub CommandsExample() ' Before running, you must add a reference to the Office ' typelib to gain access to the CommandBar object. Dim cmds As Commands Dim cmdobj As Command Dim customin, customout As Object Dim cmdbarobj As CommandBar Dim colAddins As AddIns ' Set references. colAddins = DTE.AddIns() cmds = DTE.Commands cmdobj = cmds.Item("File.NewFile") ' Execute the File.NewFile command. cmds.Raise(cmdobj.Guid, cmdobj.ID, customin, customout) ' Create a toolbar and add the File.NewFile command to it. cmdobj = cmds.Item("File.NewFile") cmdbarobj = cmds.AddCommandBar("Mycmdbar", _ vsCommandBarType.vsCommandBarTypeToolbar) cmdobj.AddControl(cmdbarobj) ' Show the command bar and its button. cmdbarobj.Visible = True End Sub
// Add a row for each keyboard shortcut
//EnvDTE80.DTE2.Commands
Commands cmds;
Command cmdobj;
cmds = DTE.Commands;
foreach (Command c in cmds) {
...
}
how can I get it: "cmds = DTE.Commands;" Commands not exists in DTE ?
TRY THIS:
public void ListShortcutsInHTML(){
//Declare a StreamWriter
System.IO.StreamWriter sw ;
sw = new StreamWriter("c:\\demo\\Shortcuts.html");
//Write the beginning HTML
WriteHTMLStart(sw);
// Add a row for each keyboard shortcut
//EnvDTE80.DTE2.Commands
try
{
Commands cmds;
EnvDTE.DTE mydte;
mydte = (EnvDTE.DTE)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.8.0");
cmds = mydte.Commands;
foreach (Command c in cmds)
{
if (c.Name != "")
{
System.Array bindings = (Array) c.Bindings;
//bindings.Initialize();
//bindings = (System.Array)c.Bindings;
for (int i = 0; i < bindings.Length - 1; i++)
{
sw.WriteLine("<tr>");
sw.WriteLine("<td>" + c.Name + "</td>");
sw.WriteLine("<td>" + "bindings[i].value" + "</td>");
sw.WriteLine("</tr>");
}//Next i
}
}//Next
} //try
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
- 11/12/2007
- tanzenderbiker
- 11/12/2007
- tanzenderbiker