Janela de saída (Visual Studio SDK)
O saída janela é um conjunto de painéis de texto que você pode gravar e ler. Visual Studiodefine esses painéis internos: Build, por meio de quais projetos se comunicar mensagens sobre compilações, e Geral, através do qual Visual Studio se comunica mensagens sobre o ambiente de desenvolvimento integrado (IDE). Projetos recebem uma referência ao Build automaticamente através do painel o IVsBuildableProjectCfg interface métodos, e Visual Studio oferece acesso direto ao Geral painel através o SVsGeneralOutputWindowPane serviço. Além os painéis internos, você pode criar e gerenciar seus próprios painéis personalizados.
Você pode controlar o saída janela diretamente por meio de IVsOutputWindow e IVsOutputWindowPane interfaces. O IVsOutputWindow interface, que é oferecido pelo SVsOutputWindow de serviço, que define métodos para criar, recuperar e destruir saída painéis de janela. O IVsOutputWindow interface define métodos para mostrar painéis, ocultando painéis e manipulação de texto. Uma maneira alternativa de controlar o saída janela é por meio do OutputWindow e OutputWindowPane objetos no modelo de objeto de automação de Visual Studio. Esses objetos encapsulam praticamente toda a funcionalidade da IVsOutputWindow e IVsOutputWindowPane interfaces. Além disso, o OutputWindow e OutputWindowPane objetos adicionam algumas funcionalidades de alto nível para tornar mais fácil enumerar o saída painéis de janela e para recuperar o texto dos painéis.
Exemplo
Descrição
Este exemplo mostra como criar uma nova saída o painel de janela usando o IVsOutputWindow interface.
Código
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;
}
Exemplo
Descrição
Este exemplo mostra como criar um saída o painel de janela usando o OutputWindow objeto.
Código
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);
}
}
Comentários
Embora o OutputWindowPanes coleção permite que você recupere um saída o painel de janela pelo título, títulos do painel não são garantidos como exclusivas. Quando você duvido que a exclusividade de um título, use o GetPane método para recuperar o painel correto por seu GUID.
Exemplo
Descrição
Este exemplo mostra como excluir um saída painel da janela.
Código
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);
}
Exemplo
Descrição
Este exemplo mostra como excluir um saída painel de janela, dada uma OutputWindowPane objeto.
Código
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);
}
Exemplo
Descrição
Este exemplo mostra como recuperar os internos Geral painel da saída janela.
Código
Private Function GetGeneralPane() As IVsOutputWindowPane
Return DirectCast(GetService(GetType(SVsGeneralOutputWindowPane)), IVsOutputWindowPane)
End Function
IVsOutputWindowPane GetGeneralPane()
{
return (IVsOutputWindowPane)GetService(
typeof(SVsGeneralOutputWindowPane));
}
Exemplo
Descrição
Este exemplo mostra como analisar uma mensagem de compilação padrão para erros e, em seguida, adicionar um item para o erro janela, se apropriado, antes que a mensagem é enviada para o saída janela.
Código
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");
}