使用VB2005开发外接程序Connect类中需要了解的一些事件

Imports System
Imports Microsoft.VisualStudio.CommandBars
Imports Extensibility
Imports EnvDTE
Imports EnvDTE80

Public Class Connect

    Implements IDTExtensibility2
 Implements IDTCommandTarget


    Dim cmWhen As ext_ConnectMode


    '''<summary>实现外接程序对象的构造函数。请将您的初始化代码置于此方法内。</summary>
    Public Sub New()

    End Sub

    '''<summary>实现 IDTExtensibility2 接口的 OnConnection 方法。接收正在加载外接程序的通知。</summary>
    '''<param name='application'>宿主应用程序的根对象。</param>
    '''<param name='connectMode'>描述外接程序的加载方式。</param>
    '''<param name='addInInst'>表示此外接程序的对象。</param>
    '''<remarks>当程序第一次执行时不加载,如果有必要,进行一些初始化工作,等到启动环境时记下启动模式,在启动完成后再加载</remarks>
    Public Sub OnConnection(ByVal Application As Object, ByVal ConnectMode As ext_ConnectMode, ByVal AddInInst As Object, ByRef Custom As Array) Implements IDTExtensibility2.OnConnection
        chDTE = CType(Application, DTE2)
        chAddIN = CType(AddInInst, AddIn)
        If ConnectMode <> ext_ConnectMode.ext_cm_UISetup And ConnectMode <> ext_ConnectMode.ext_cm_Startup Then
            LoadCoderHelper()
        Else
            cmWhen = ConnectMode
        End If
        
    End Sub

    '''<summary>实现 IDTExtensibility2 接口的 OnDisconnection 方法。接收正在卸载外接程序的通知。</summary>
    '''<param name='disconnectMode'>描述外接程序的卸载方式。</param>
    '''<param name='custom'>特定于宿主应用程序的参数数组。</param>
    '''<remarks>只载环境要关闭或用户要求关闭时才卸载,其他方式不卸载</remarks>
    Public Sub OnDisconnection(ByVal disconnectMode As ext_DisconnectMode, ByRef custom As Array) Implements IDTExtensibility2.OnDisconnection
        Debug.Write("OnDisconnection" & custom.ToString & Now & vbNewLine)
        If disconnectMode = ext_DisconnectMode.ext_dm_HostShutdown Or _
            disconnectMode = ext_DisconnectMode.ext_dm_UserClosed Then
            UnloadCoderHelper()
        End If
    End Sub

    '''<summary>实现 IDTExtensibility2 接口的 OnAddInsUpdate 方法。接收外接程序集合已更改的通知。</summary>
    '''<param name='custom'>特定于宿主应用程序的参数数组。</param>
    '''<remarks></remarks>
    Public Sub OnAddInsUpdate(ByRef custom As Array) Implements IDTExtensibility2.OnAddInsUpdate
        'Debug.Write("OnAddInsUpdate" & custom.ToString & Now & vbNewLine)
        '  LoadCoderHelper()
    End Sub

    '''<summary>实现 IDTExtensibility2 接口的 OnStartupComplete 方法。接收宿主应用程序已完成加载的通知。</summary>
    '''<param name='custom'>特定于宿主应用程序的参数数组。</param>
    '''<remarks>如果是启动时需要加载,则载启动完成后加载,因为环境没有加载完成的情况下,将成功调用环境内的命令</remarks>
    Public Sub OnStartupComplete(ByRef custom As Array) Implements IDTExtensibility2.OnStartupComplete
        If cmWhen = ext_ConnectMode.ext_cm_Startup Then
            LoadCoderHelper()
            'chCES.Show()
        End If
    End Sub

    '''<summary>实现 IDTExtensibility2 接口的 OnBeginShutdown 方法。接收正在卸载宿主应用程序的通知。</summary>
    '''<param name='custom'>特定于宿主应用程序的参数数组。</param>
    '''<remarks>开始卸载环境时迅速卸载本程序的一些功能</remarks>
    Public Sub OnBeginShutdown(ByRef custom As Array) Implements IDTExtensibility2.OnBeginShutdown
        Debug.Write("OnBeginShutdown" & custom.ToString & Now & vbNewLine)
        UnloadCoderHelper()

    End Sub
 
    '''<summary>实现 IDTCommandTarget 接口的 QueryStatus 方法。此方法在更新该命令的可用性时调用</summary>
    '''<param name='commandName'>要确定其状态的命令的名称。</param>
    '''<param name='neededText'>该命令所需的文本。</param>
    '''<param name='status'>该命令在用户界面中的状态。</param>
    '''<param name='commandText'>neededText 参数所要求的文本。</param>
    '''<remarks></remarks>
    Public Sub QueryStatus(ByVal CommandName As String, ByVal neededText As vsCommandStatusTextWanted, ByRef status As vsCommandStatus, ByRef commandText As Object) Implements IDTCommandTarget.QueryStatus
        Debug.WriteLine("OueryStatus" & commandName & Now & vbNewLine)
        If neededText = vsCommandStatusTextWanted.vsCommandStatusTextWantedNone Then
            If GetStatus(CommandName) Then
                status = CType(vsCommandStatus.vsCommandStatusEnabled + vsCommandStatus.vsCommandStatusSupported, vsCommandStatus)
            Else
                status = vsCommandStatus.vsCommandStatusUnsupported
            End If
        End If
    End Sub

    '''<summary>实现 IDTCommandTarget 接口的 Exec 方法。此方法在调用该命令时调用。</summary>
    '''<param name='commandName'>要执行的命令的名称。</param>
    '''<param name='executeOption'>描述该命令应如何运行。</param>
    '''<param name='varIn'>从调用方传递到命令处理程序的参数。</param>
    '''<param name='varOut'>从命令处理程序传递到调用方的参数。</param>
    '''<param name='handled'>通知调用方此命令是否已被处理。</param>
    '''<remarks></remarks>
    Public Sub Exec(ByVal commandName As String, ByVal executeOption As vsCommandExecOption, ByRef varIn As Object, ByRef varOut As Object, ByRef handled As Boolean) Implements IDTCommandTarget.Exec
        handled = False
        '  chCES.Show()
        Debug.Write("Exec" & commandName & Now & vbNewLine)
        If executeOption = vsCommandExecOption.vsCommandExecOptionDoDefault Then
            handled = ToDoCommand(commandName, varIn, varOut)
        End If
 End Sub

   
   
End Class

你可能感兴趣的:(connect)