更新:2007 年 11 月
CommandWindow 对象表示 Visual Studio 自动化模型中的“命令”窗口。您可以使用 CommandWindow 对象来:
- 将命令插入到“命令”窗口并选择使用 SendInput 方法执行该命令。 
- 使用 OutputString 方法将信息性文本插入到“命令”窗口。 
- 使用 Clear 方法清除“命令”窗口中的所有文本。 
除了控制“命令”窗口的内容以外,还可以控制其特性(如宽度和高度)。有关更多信息,请参见 如何:更改窗口特性。
| .gif) 说明: | 
|---|
| 显示的对话框和菜单命令可能会与“帮助”中的描述不同,具体取决于您的当前设置或版本。这些过程是使用现用的常规开发设置开发的。若要更改设置,请在“工具”菜单上选择“导入和导出设置”。有关更多信息,请参见 Visual Studio 设置。 | 
示例
本示例演示如何引用和使用“命令”窗口自动化模型的各种成员。有关如何运行本示例的更多信息,请参见 如何:编译和运行自动化对象模型代码示例。
Public Sub OnConnection(ByVal application As Object, ByVal _
  connectMode As ext_ConnectMode, ByVal addInInst As Object, _
  ByRef custom As Array) Implements IDTExtensibility2.OnConnection
    _applicationObject = CType(application, DTE2)
    _addInInstance = CType(addInInst, AddIn)
    ' Pass the applicationObject member variable to the code example.
    CommandWinExample(_applicationObject)
End Sub
Sub CommandWinExample(ByVal dte As DTE2)
    Try
        ' Get a reference to the Command window.
        Dim CW As CommandWindow = dte.ToolWindows.CommandWindow
        ' Insert informative text into the Command window.
        CW.OutputString("This takes you to the Microsoft Web site.")
        ' Add a command to the Command window and execute it.
        CW.SendInput("nav https://www.microsoft.com", True)
        ' Clear the contents of the Command window.
        MsgBox("Clearing the Command window...")
        CW.Clear()
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Sub
public void OnConnection(object application, ext_ConnectMode 
  connectMode, object addInInst, ref Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;
    // Pass the applicationObject member variable to the code example.
    CommandWinExample(_applicationObject);
}
public void CommandWinExample(DTE2 dte)
{
    try
    {
        // Get a reference to the Command window.
        CommandWindow CW = dte.ToolWindows.CommandWindow;
        // Insert informative text into the Command window.
        CW.OutputString("This takes you to the Microsoft Web site.");
        // Add a command to the Command window and execute it.
        CW.SendInput("nav https://www.microsoft.com", true);
        // Clear the contents of the Command window.
        System.Windows.Forms.MessageBox.Show("Clearing the Command 
          window...");
        CW.Clear();
    }
    catch (Exception ex)
    {
        System.Windows.Forms.MessageBox.Show(ex.Message);
    }
}