IDTCommandTarget.QueryStatus Method
Returns the current status (enabled, disabled, hidden, and so forth) of the specified named command.
Namespace: EnvDTE
Assembly: EnvDTE (in EnvDTE.dll)
Syntax
'Declaration
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
)
Parameters
- CmdName
Type: System.String
The name of the command to check.
- NeededText
Type: EnvDTE.vsCommandStatusTextWanted
A vsCommandStatusTextWanted constant specifying if information is returned from the check, and if so, what type of information is returned.
- StatusOption
Type: EnvDTE.vsCommandStatus%
A vsCommandStatus specifying the current status of the command.
- CommandText
Type: System.Object%
The text to return if vsCommandStatusTextWantedStatus is specified.
Remarks
The following example uses the Command object, its AddNamedCommand and AddControl methods, and the IDTCommandTarget interface and its (Exec and QueryStatus) methods, to demonstrate how to make an Add-in appear as a command on the Tools menu in Visual Studio. Note that this code does not work in a macro.
Examples
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 Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.