输出窗口 (Visual Studio SDK)

输出 窗口是设置可以写入的文本窗格和读取。 Visual Studio 定义这些内置窗格: 生成,项目将有关生成的消息和 泛型, Visual Studio 传达有关集成开发环境 (ide) 的消息 (IDE)。 项自动接收对 生成 窗格。 IVsBuildableProjectCfg 接口方法和 Visual Studio 提供了直接访问 泛型 窗格。 SVsGeneralOutputWindowPane 服务。 除了内置窗格外,您可以创建和管理拥有自定义窗格。

可以直接通过 IVsOutputWindowIVsOutputWindowPane 界面控件 输出 窗口。 IVsOutputWindow 接口, SVsOutputWindow 服务提供,定义用于创建,检索和销毁的 输出 窗格的方法。 IVsOutputWindow 接口定义显示的窗格中,隐藏的窗格和操作方法从其文本。 控件 输出 窗口一个替代方法是通过 Visual Studio 自动化对象模型的 OutputWindowOutputWindowPane 对象。 这些对象封装几乎所有 IVsOutputWindowIVsOutputWindowPane 接口的功能。 此外, OutputWindowOutputWindowPane 对象添加一些更高级的功能使其更易于枚举 输出 、、、和从窗格中检索文本。

示例

说明

使用 IVsOutputWindow 接口,本示例演示如何创建新的 输出 窗口窗格。

代码

Private Function CreatePane(ByVal paneGuid As Guid, ByVal title As String, ByVal visible As Boolean, ByVal clearWithSolution As Boolean) As IVsOutputWindowPane 
    Dim output As IVsOutputWindow = DirectCast(GetService(GetType(SVsOutputWindow)), IVsOutputWindow) 
    Dim pane As IVsOutputWindowPane 
    
    ' Create a new pane. 
    output.CreatePane(paneGuid, title, Convert.ToInt32(visible), Convert.ToInt32(clearWithSolution)) 
    
    ' Retrieve the new pane. 
    output.GetPane(paneGuid, pane) 
    
    Return pane 
End Function
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;
}

示例

说明

使用 OutputWindow 对象,本示例演示如何创建 输出 窗口窗格。

代码

Private Function CreatePane(ByVal title As String) As OutputWindowPane 
    Dim dte As DTE2 = DirectCast(GetService(GetType(DTE)), DTE2) 
    Dim panes As OutputWindowPanes = dte.ToolWindows.OutputWindow.OutputWindowPanes 
    
    Try 
        ' If the pane exists already, return it. 
        Return panes.Item(title) 
    Catch generatedExceptionName As ArgumentException 
        ' Create a new pane. 
        Return panes.Add(title) 
    End Try 
End Function
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);
    }
}

注释

虽然 OutputWindowPanes 集合可以按其前缀检索 输出 窗口窗格,该窗格标题不一定是唯一的。 当您怀疑标题的唯一性时,请使用 GetPane 方法按 GUID 检索正确的窗格。

示例

说明

此示例演示如何删除 输出 窗口窗格。

代码

Private Sub DeletePane(ByVal paneGuid As Guid) 
    Dim output As IVsOutputWindow = DirectCast(GetService(GetType(SVsOutputWindow)), IVsOutputWindow) 
    
    output.DeletePane(paneGuid) 
End Sub
void DeletePane(Guid paneGuid)
{
    IVsOutputWindow output =
        (IVsOutputWindow)GetService(typeof(SVsOutputWindow));

    output.DeletePane(ref paneGuid);
}

示例

说明

此示例演示如何删除 输出 窗口窗格将 OutputWindowPane 对象。

代码

Private Sub DeletePane(ByVal pane As OutputWindowPane) 
    Dim output As IVsOutputWindow = DirectCast(GetService(GetType(SVsOutputWindow)), IVsOutputWindow) 
    Dim paneGuid As New Guid(pane.Guid) 
    
    output.DeletePane(paneGuid) 
End Sub
void DeletePane(OutputWindowPane pane)
{
    IVsOutputWindow output =
        (IVsOutputWindow)GetService(typeof(SVsOutputWindow));
    Guid paneGuid = new Guid(pane.Guid);

    output.DeletePane(ref paneGuid);
}

示例

说明

此示例演示如何检索 输出 窗口的内置 泛型 窗格。

代码

Private Function GetGeneralPane() As IVsOutputWindowPane 
    Return DirectCast(GetService(GetType(SVsGeneralOutputWindowPane)), IVsOutputWindowPane) 
End Function
IVsOutputWindowPane GetGeneralPane()
{
    return (IVsOutputWindowPane)GetService(
        typeof(SVsGeneralOutputWindowPane));
}

示例

说明

此示例演示如何分析错误的标准生成消息,以及将项目添加到 错误 窗口,因此,如果需要,在消息之前发送到 输出 窗口。

代码

Private Sub OutputTaskItemStringExExample(ByVal buildMessage As String, ByVal buildPane As IVsOutputWindowPane, ByVal launchPad As IVsLaunchPad) 
    Dim priority As UInteger() = New UInteger(0) {}, lineNumber As UInteger() = New UInteger(0) {} 
    Dim fileName As String() = New String(0) {}, taskItemText As String() = New String(0) {} 
    Dim taskItemFound As Integer() = New Integer(0) {} 
    
    ' 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 Then 
        buildPane.OutputTaskItemStringEx(buildMessage, DirectCast(priority(0), VSTASKPRIORITY), VSTASKCATEGORY.CAT_BUILDCOMPILE, Nothing, 0, fileName(0), _ 
        lineNumber(0), taskItemText(0), Nothing) 
    Else 
        buildPane.OutputString(buildMessage) 
    End If 
    
    buildPane.OutputString(vbLf) 
End Sub
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");
}

请参见

参考

IVsLaunchPad

IVsLaunchPadFactory

IVsOutputWindow

IVsOutputWindowPane

OutputWindow

OutputWindowPane

SVsGeneralOutputWindowPane

SVsLaunchPadFactory

SVsOutputWindow