IDTCommandTarget.Exec 方法

更新:2007 年 11 月

执行指定的命名命令。

命名空间:  EnvDTE
程序集:  EnvDTE(在 EnvDTE.dll 中)

语法

声明
Sub Exec ( _
    CmdName As String, _
    ExecuteOption As vsCommandExecOption, _
    ByRef VariantIn As Object, _
    <OutAttribute> ByRef VariantOut As Object, _
    <OutAttribute> ByRef handled As Boolean _
)
用法
Dim instance As IDTCommandTarget
Dim CmdName As String
Dim ExecuteOption As vsCommandExecOption
Dim VariantIn As Object
Dim VariantOut As Object
Dim handled As Boolean

instance.Exec(CmdName, ExecuteOption, _
    VariantIn, VariantOut, handled)
void Exec(
    string CmdName,
    vsCommandExecOption ExecuteOption,
    ref Object VariantIn,
    out Object VariantOut,
    out bool handled
)
void Exec(
    [InAttribute] String^ CmdName, 
    [InAttribute] vsCommandExecOption ExecuteOption, 
    [InAttribute] Object^% VariantIn, 
    [InAttribute] [OutAttribute] Object^% VariantOut, 
    [InAttribute] [OutAttribute] bool% handled
)
function Exec(
    CmdName : String, 
    ExecuteOption : vsCommandExecOption, 
    VariantIn : Object, 
    VariantOut : Object, 
    handled : boolean
)

参数

  • VariantOut
    类型:System.Object%

    在命令执行后传回调用方 Exec 方法的值。

备注

下面的示例使用 Command 对象及其 AddNamedCommandAddControl 方法,以及使用 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  

权限

另请参见

参考

IDTCommandTarget 接口

IDTCommandTarget 成员

EnvDTE 命名空间