Window2.DTE 屬性
取得最上層的擴充性物件。
命名空間: EnvDTE80
組件: EnvDTE80 (在 EnvDTE80.dll 中)
語法
'宣告
ReadOnly Property DTE As DTE
DTE DTE { get; }
property DTE^ DTE {
DTE^ get ();
}
abstract DTE : DTE
function get DTE () : DTE
屬性值
型別:EnvDTE.DTE
DTE 物件。
備註
在 Visual Studio 中,DTE 物件是 Automation 模型的根物件,Automation 物件在其他物件模型中經常稱為「應用程式」。
範例
這個範例會使用透過 Window2 物件取得的 DTE 物件,判斷 [輸出視窗]是屬於巨集 IDE 還是 Visual Studio IDE。
如需如何像執行增益集一般,執行這個範例的詳細資訊,請參閱 HOW TO:編譯和執行 Automation 物件模型程式碼範例。
Imports EnvDTE
Imports EnvDTE80
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)
DTEExample(_applicationObject)
End Sub
Sub DTEExample(ByVal dte As DTE2)
Dim msg As String = _
"The current Output Window object belongs to the "
Dim output As Window2 = _
CType(_applicationObject.Windows.Item _
(Constants.vsWindowKindOutput), Window2)
If IsMacrosIDE(output.DTE) Then
MsgBox(msg & "macros IDE.")
Else
MsgBox(msg & "main IDE.")
End If
output = _
CType(dte.MacrosIDE.Windows.Item(Constants.vsWindowKindOutput), _
Window2)
If IsMacrosIDE(output.DTE) Then
MsgBox(msg & "macros IDE.")
Else
MsgBox(msg & "main IDE.")
End If
End Sub
Function IsMacrosIDE(ByVal ide As DTE) As Boolean
Dim val As Boolean = True
Try
' The MacrosIDE property will throw an exception if ide
' is not the main DTE object.
If IsNothing(ide.MacrosIDE) = False Then
val = False
End If
Catch ex As Exception
End Try
Return val
End Function
using EnvDTE;
using EnvDTE80;
using System.Windows.Forms;
public void OnConnection(object application,
ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;
DTEExample(_applicationObject);
}
public void DTEExample(DTE2 dte)
{
String msg = "The current Output Window object belongs to the ";
Window2 output =
(Window2)_applicationObject.Windows.Item(Constants.vsWindowKindOutput);
if (IsMacrosIDE(output.DTE))
MessageBox.Show(msg + "macros IDE.");
else
MessageBox.Show(msg + "main IDE.");
output =
(Window2)_applicationObject.Windows.Item
(Constants.vsWindowKindMacroExplorer);
if (IsMacrosIDE(output.DTE))
MessageBox.Show(msg + "macros IDE.");
else
MessageBox.Show(msg + "main IDE.");
}
public bool IsMacrosIDE(DTE ide)
{
try
{
bool val = true;
if (ide.MacrosIDE == null)
val = false;
}
catch (Exception ex)
{
}
return val;
}
.NET Framework 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。