Export (0) Print
Expand All

Output Window (Visual Studio SDK)

[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

The Output window is a set of text panes that you can write to and read from. Visual Studio defines two built-in panes: Build, through which projects communicate build messages, and General, through which Visual Studio communicates messages related to the integrated development environment (IDE). Projects receive a reference to the Build pane automatically through the IVsBuildableProjectCfg interface methods, and Visual Studio offers direct access to the General pane through the SVsGeneralOutputWindowPane service. In addition to the built-in panes, you can create and manage your own custom panes.

You can control the Output window directly through the IVsOutputWindow and IVsOutputWindowPane interfaces. The IVsOutputWindow interface, which is offered by the SVsOutputWindow service, defines methods for creating, retrieving, and destroying Output window panes. The IVsOutputWindow interface defines methods for showing panes, hiding panes, and manipulating their text. An alternative way of controlling the Output window is through the Visual Studio Automation object model's OutputWindow and OutputWindowPane objects. These objects encapsulate nearly all of the functionality of the IVsOutputWindow and IVsOutputWindowPane interfaces. In addition, the OutputWindow and OutputWindowPane objects add some higher-level functionality to make it easier to enumerate the Output window panes and to retrieve text from the panes.

Example

This example shows how to create a new Output window pane by using the IVsOutputWindow interface.

IVsOutputWindowPane CreatePane(Guid paneGuid, string title, 
    bool visible, bool clearWithSolution)
{
    IVsOutputWindow output = 
        (IVsOutputWindow)GetService(typeof(SVsOutputWindow));
    IVsOutputWindowPane pane;

    // Create a new pane.
    output.CreatePane(
        ref paneGuid, 
        title, 
        Convert.ToInt32(visible), 
        Convert.ToInt32(clearWithSolution));
    
    // Retrieve the new pane.
    output.GetPane(ref paneGuid, out pane);

    return pane;
}

Example

This example shows how to create an Output window pane by using the OutputWindow object.

OutputWindowPane CreatePane(string title)
{
    DTE2 dte = (DTE2)GetService(typeof(DTE));
    OutputWindowPanes panes =
        dte.ToolWindows.OutputWindow.OutputWindowPanes;

    try
    {
        // If the pane exists already, return it.
        return panes.Item(title);
    }
    catch (ArgumentException)
    {
        // Create a new pane.
        return panes.Add(title);
    }
}

Although the OutputWindowPanes collection allows you to retrieve an Output window pane by its title, pane titles are not guaranteed to be unique. When in doubt of a title's uniqueness, use the GetPane method to retrieve the correct pane by its GUID.

Example

This example shows how to delete an Output window pane.

void DeletePane(Guid paneGuid)
{
    IVsOutputWindow output =
        (IVsOutputWindow)GetService(typeof(SVsOutputWindow));

    output.DeletePane(ref paneGuid);
}

Example

This example shows how to delete an Output window pane, given an OutputWindowPane object.

void DeletePane(OutputWindowPane pane)
{
    IVsOutputWindow output =
        (IVsOutputWindow)GetService(typeof(SVsOutputWindow));
    Guid paneGuid = new Guid(pane.Guid);

    output.DeletePane(ref paneGuid);
}

Example

This example shows how to retrieve the built-in General Output window pane.

IVsOutputWindowPane GetGeneralPane()
{
    return (IVsOutputWindowPane)GetService(
        typeof(SVsGeneralOutputWindowPane));
}

Example

This example shows how to parse a standard build message for errors — and add an item to the Error window, if appropriate — before sending the message to the Output window.

void OutputTaskItemStringExExample(string buildMessage,
    IVsOutputWindowPane buildPane, IVsLaunchPad launchPad)
{
    uint[] priority = new uint[1], lineNumber = new uint[1];
    string[] fileName = new string[1], taskItemText = new string[1];
    int[] taskItemFound = new int[1];

    // Determine whether buildMessage contains an error.
    launchPad.ParseOutputStringForTaskItem(
        buildMessage, 
        priority, 
        fileName, 
        lineNumber, 
        taskItemText, 
        taskItemFound);


    // If buildMessage contains an error, send it to both the 
    // Error window and the Output window; otherwise, send it
    // to the Output window only.
    if (taskItemFound[0] != 0)
    {
        buildPane.OutputTaskItemStringEx(
            buildMessage, 
            (VSTASKPRIORITY)priority[0], 
            VSTASKCATEGORY.CAT_BUILDCOMPILE, 
            null, 
            0, 
            fileName[0], 
            lineNumber[0], 
            taskItemText[0], 
            null);
    }
    else
    {
        buildPane.OutputString(buildMessage);
    }

    buildPane.OutputString("\n");
}

See Also

Community Additions

ADD
Show:
© 2014 Microsoft