輸出] 視窗 (Visual Studio SDK)
輸出視窗是一組您可以寫入和讀取文字窗格。 Visual Studio定義這些內建的窗格: 建置,透過哪些專案通訊有關的組建中,訊息和一般,透過它Visual Studio通訊整合式的開發環境 (IDE) 的相關訊息。 專案會接收到參考建置窗格自動到IVsBuildableProjectCfg介面方法,以及Visual Studio提供直接存取一般窗格透過SVsGeneralOutputWindowPane服務。 除了內建的窗格中,您可以建立和管理您自己的自訂窗格。
您可以控制輸出視窗直接到IVsOutputWindow和IVsOutputWindowPane介面。 IVsOutputWindow介面所提供的SVsOutputWindow服務,用來定義方法,來建立、 擷取,並摧毀輸出視窗窗格。 IVsOutputWindow介面會定義用於顯示窗格、 隱藏的窗格,以及管理其文字的方法。 另一種控制輸出視窗是透過OutputWindow和OutputWindowPane Visual Studio 的自動化物件模型中的物件。 這些物件封裝幾乎全部的功能都IVsOutputWindow和IVsOutputWindowPane介面。 此外, OutputWindow和OutputWindowPane物件加入一些較高層級的功能,以讓列舉的工作變得更容易輸出視窗窗格,並從窗格中擷取文字。
範例
描述
本範例示範如何建立新的輸出視窗窗格,藉由使用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");
}