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 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。