Gewusst wie: Steuern des Ausgabefensters

Aktualisiert: November 2007

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 T-SQL syntax in a stored procedure is checked against a target database. Certain IDE features, such as the external tools features or commands invoked in the Command window, deliver output to special Output Window panes. Output from external tools, such as .bat or .com files, normally displayed in the Windows Command window, can display in this window as well.

The Visual Studio automation model offers the following objects for controlling the Output window:

Object Name

Description

OutputWindow

Represents the Output window.

OutputWindowPanes

A collection containing all of the Output window panes.

OutputWindowPane

Represents a single pane in the Output window.

OutputWindowEvents

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

In addition to controlling the contents of the Output window, you can also control its characteristics such as width and height. For more information, see Gewusst wie: Ändern des Erscheinungsbilds eines Fensters.

The text inside the Output window panes can be manipulated with the Visual Studio editor automation model, just like code in the Code editor, by using the TextDocument object, EditPoint object, and similar objects. For more information, see Gewusst wie: Steuern des Code-Editors (Visual Basic).

Hinweis:

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, choose Import and ExportSettings on the Tools menu. For more information, see Visual Studio-Einstellungen.

Beispiel

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 Gewusst wie: Kompilieren und Ausführen der Codebeispiele für das Automatisierungsobjektmodell.

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

Siehe auch

Aufgaben

Gewusst wie: Ändern des Erscheinungsbilds eines Fensters

Gewusst wie: Erstellen von Add-Ins

Exemplarische Vorgehensweise: Erstellen eines Assistenten

Konzepte

Diagramm "Automationsobjektmodell"

Weitere Ressourcen

Erstellen und Steuern von Umgebungsfenstern

Erstellen von Add-Ins und Assistenten

Referenz zur Automatisierung und Erweiterbarkeit