Share via


How to: Control the Output Window

The Output window displays status messages for various features in the integrated development environment (IDE). These include build errors that occur when a project is compiled, and the results when Transact-SQL syntax in a stored procedure is checked against a target database. Certain IDE features, for example, the external tools features or commands that are invoked in the Command window, deliver output to special Output window panes. Output from external tools, for example, .bat files or .com files, which is typically displayed in the Windows Command Prompt window, can also be displayed in the Output window.

The Visual Studio automation model offers the following objects that you can use to control the Output window.

Object Name

Description

OutputWindow

Represents the Output window.

OutputWindowPanes

A collection that contains all the Output window panes.

OutputWindowPane

Represents just one pane in the Output window.

OutputWindowEvents

Lets you respond to events that occur in the Output window.

In addition to controlling the contents of the Output window, you can also control characteristics such as its width and height. For more information, see How to: Change Window Characteristics.

The text inside the Output window panes can be manipulated by using the Visual Studio editor automation model, just as code in the Code editor can be manipulated, by using the TextDocument object, EditPoint object, or similar objects. For more information, see How to: Control the Code Editor (Visual Basic).

Note

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. These procedures were developed with the General Development Settings active. To change your settings, click Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

Example

This example demonstrates how to add a new window pane to the Output window and how to add some text to it. For more information about how to run the example, see How to: Compile and Run the Automation Object Model Code Examples.

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");
}

This example adds text to the Build pane in the Output window and then retrieves it.

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));
}

See Also

Tasks

How to: Change Window Characteristics

How to: Create an Add-In

Walkthrough: Creating a Wizard

Concepts

Automation Object Model Chart

Other Resources

Creating and Controlling Environment Windows

Creating Add-ins and Wizards

Automation and Extensibility Reference