IDTCommandTarget.QueryStatus 方法
傳回指定之具名命令的目前狀態 (啟用、暫止、隱藏等等)。
命名空間: EnvDTE
組件: EnvDTE (在 EnvDTE.dll 中)
語法
'宣告
Sub QueryStatus ( _
CmdName As String, _
NeededText As vsCommandStatusTextWanted, _
<OutAttribute> ByRef StatusOption As vsCommandStatus, _
<OutAttribute> ByRef CommandText As Object _
)
void QueryStatus(
string CmdName,
vsCommandStatusTextWanted NeededText,
out vsCommandStatus StatusOption,
out Object CommandText
)
void QueryStatus(
[InAttribute] String^ CmdName,
[InAttribute] vsCommandStatusTextWanted NeededText,
[InAttribute] [OutAttribute] vsCommandStatus% StatusOption,
[InAttribute] [OutAttribute] Object^% CommandText
)
abstract QueryStatus :
CmdName:string *
NeededText:vsCommandStatusTextWanted *
StatusOption:vsCommandStatus byref *
CommandText:Object byref -> unit
function QueryStatus(
CmdName : String,
NeededText : vsCommandStatusTextWanted,
StatusOption : vsCommandStatus,
CommandText : Object
)
參數
- CmdName
型別:System.String
要檢查的命令名稱。
- NeededText
型別:EnvDTE.vsCommandStatusTextWanted
vsCommandStatusTextWanted 常數,指定是否要從檢查傳回資訊及 (如果要的話) 傳回何種資訊。
- StatusOption
型別:EnvDTE.vsCommandStatus%
vsCommandStatus 指定命令的目前狀態。
- CommandText
型別:System.Object%
指定 vsCommandStatusTextWantedStatus 時傳回的文字。
備註
以下範例使用 Command 物件,它的 AddNamedCommand 和 AddControl 方法,以及 IDTCommandTarget 介面和它的 (Exec 和 QueryStatus) 方法,示範如何使增益集顯示為 Visual Studio 中 [工具] 功能表上的命令。 請注意,這個程式碼不適用於巨集。
範例
Implements IDTCommandTarget
Dim applicationObject As EnvDTE.DTE
Dim addInInstance as EnvDTE.AddIn
Dim objAddIn As AddIn = CType(addInInst, AddIn)
Dim CommandObj As Command
Try
CommandObj = applicationObject.Commands.AddNamedCommand(objAddIn, "MyAddin1", "MyAddin1", "Executes the command for MyAddin1", True, 59, Nothing, 1 + 2)
'1+2 == vsCommandStatusSupported+vsCommandStatusEnabled
CommandObj.AddControl(applicationObject.CommandBars.Item("Tools"))
Catch e as System.Exception
End Try
Public Sub Exec(ByVal cmdName As String, ByVal executeOption As vsCommandExecOption, ByRef varIn As Object, ByRef varOut As Object, ByRef handled As Boolean) Implements IDTCommandTarget.Exec
handled = False
If (executeOption = vsCommandExecOption.vsCommandExecOptionDoDefault) Then
If cmdName = "MyAddin1.Connect.MyAddin1" Then
handled = True
Exit Sub
End If
End If
End Sub
Public Sub QueryStatus(ByVal cmdName As String, ByVal neededText As vsCommandStatusTextWanted, ByRef statusOption As vsCommandStatus, ByRef commandText As Object) Implements IDTCommandTarget.QueryStatus
If neededText = EnvDTE.vsCommandStatusTextWanted.vsCommandStatusTextWantedNone Then
If cmdName = "MyAddin1.Connect.MyAddin1" Then
statusOption = CType(vsCommandStatus.vsCommandStatusEnabled & vsCommandStatus.vsCommandStatusSupported, vsCommandStatus)
Else
statusOption = vsCommandStatus.vsCommandStatusUnsupported
End If
End If
End Sub
.NET Framework 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。