共用方式為


IDTCommandTarget.Exec 方法

執行指定的具名命令。

命名空間:  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 _
)
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
)
abstract Exec : 
        CmdName:string * 
        ExecuteOption:vsCommandExecOption * 
        VariantIn:Object byref * 
        VariantOut:Object byref * 
        Handled:bool byref -> unit
function Exec(
    CmdName : String, 
    ExecuteOption : vsCommandExecOption, 
    VariantIn : Object, 
    VariantOut : Object, 
    Handled : boolean
)

參數

  • CmdName
    類型:String

    要執行的命令名稱。

  • VariantIn
    類型:Object%

    傳遞給命令的值。

  • VariantOut
    類型:Object%

    命令執行之後傳回給呼叫端 Exec 方法的值。

  • Handled
    類型:Boolean%

備註

以下範例使用 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  

.NET Framework 安全性

請參閱

參考

IDTCommandTarget 介面

EnvDTE 命名空間