更新:2007 年 11 月
“输出”窗口在集成开发环境 (IDE) 中显示各种功能的状态消息。这些消息包括在编译项目时发生的生成错误和依据目标数据库检查存储过程中的 T-SQL 语法时的结果。某些 IDE 功能(如外部工具功能或“命令”窗口中调用的命令)将输出传递到特殊的“输出”窗口窗格。来自外部工具(如 .bat 或 .com 文件)的输出通常在“Windows 命令”窗口中显示,也可以在此窗口中显示。
Visual Studio 自动化模型提供以下对象,用于控制“输出”窗口:
| 对象名 | 说明 | 
|---|---|
| 表示“输出”窗口。 | |
| 包含所有“输出”窗口窗格的集合。 | |
| 表示“输出”窗口中的单个窗格。 | |
| 使您可以响应“输出”窗口中发生的事件。 | 
除了控制“输出”窗口的内容之外,还可以控制其特性(如宽度和高度)。有关更多信息,请参见 如何:更改窗口特性。
通过使用 TextDocument 对象、EditPoint 对象和类似的对象,可以用 Visual Studio 编辑器自动化模型操作“输出”窗口窗格中的文本,正如在代码编辑器中操作代码一样。有关更多信息,请参见 如何:控制代码编辑器 (Visual Basic)。
| .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.
    OutputWindowTest(_applicationObject)
End Sub
Sub OutputWindowTest(ByVal dte As DTE2)
    ' Create a tool window reference for the Output window
    ' and window pane.
    Dim ow As OutputWindow = dte.ToolWindows.OutputWindow
    Dim owP As OutputWindowPane
    ' Add a new pane to the Output window.
    owP = ow.OutputWindowPanes.Add("A New Pane")
    ' Add a line of text to the new pane.
    owP.OutputString("Some Text")
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.
    OutputWindowTest(_applicationObject);
}
public void OutputWindowTest(DTE2 dte)
{
    // Create a tool window reference for the Output window
    // and window pane.
    OutputWindow ow = dte.ToolWindows.OutputWindow;
    OutputWindowPane owP;
    // Add a new pane to the Output window.
    owP = ow.OutputWindowPanes.Add("A New Pane");
    // Add a line of text to the new pane.
    owP.OutputString("Some Text");
}
此示例向“输出”窗口的“生成”窗格添加文本,然后检索此文本。
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.
    writeReadOW(_applicationObject)
End Sub
Sub writeReadOW(ByVal dte As DTE2)
    ' Add-in code.
    ' Create a reference to the Output window.
    ' Create a tool window reference for the Output window
    ' and window pane.
    Dim ow As OutputWindow = dte.ToolWindows.OutputWindow
    Dim owP As OutputWindowPane
    ' Create a reference to the pane contents.
    Dim owPTxtDoc As TextDocument
    ' Select the Build pane in the Output window.
    owP = ow.OutputWindowPanes.Item("Build")
    owP.Activate()
    owPTxtDoc = owP.TextDocument
    ' Put some text in the pane.
    owP.OutputString("Testing 123.")
    ' Retrieve the text contents of the pane.
    MsgBox("Startpoint: " & owPTxtDoc.StartPoint.DisplayColumn)
    MsgBox(owPTxtDoc.StartPoint.CreateEditPoint. _
      GetText(owPTxtDoc.EndPoint))
End Sub
using System.Windows.Forms;
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.
    writeReadOW(_applicationObject);
}
public void writeReadOW(DTE2 dte)
{
    // Add-in code.
    // Create a reference to the Output window.
    // Create a tool window reference for the Output window
    // and window pane.
    OutputWindow ow = dte.ToolWindows.OutputWindow;
    OutputWindowPane owP;
    // Create a reference to the pane contents.
    TextDocument owPTxtDoc;
    EditPoint2 strtPt;
    // Select the Build pane in the Output window.
    owP = ow.OutputWindowPanes.Item("Build");
    owP.Activate();
    owPTxtDoc = owP.TextDocument;
            
    // Put some text in the pane.
    owP.OutputString("Testing 123.");
    // Retrieve the text contents of the pane.
    System.Windows.Forms.MessageBox.Show("Startpoint: " + 
      owPTxtDoc.StartPoint.DisplayColumn);
    strtPt = (EditPoint2)owPTxtDoc.StartPoint.CreateEditPoint();
    System.Windows.Forms.MessageBox.Show
      (strtPt.GetText(owPTxtDoc.EndPoint));
}