home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Microsoft Plateform / Visual Basic 5.0 / Msvb50.ace / msvb50 / MSVB50 / VB / TEMPLATE / CLASSES / ADDIN.CLS next >
Encoding:
Visual Basic class definition  |  1996-10-16  |  4.0 KB  |  151 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "Connect"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = True
  10. Attribute VB_Description = "My Add-In"
  11. Option Explicit
  12.  
  13. Implements IDTExtensibility
  14.  
  15. Public FormDisplayed          As Boolean
  16. Public VBInstance             As VBIDE.VBE
  17. Dim mcbMenuCommandBar         As Office.CommandBarControl
  18. Dim mfrmAddIn                 As New frmAddIn
  19. Public WithEvents MenuHandler As CommandBarEvents          'command bar event handler
  20. Attribute MenuHandler.VB_VarHelpID = -1
  21.  
  22.  
  23. Sub Hide()
  24.     
  25.     On Error Resume Next
  26.     
  27.     FormDisplayed = False
  28.     mfrmAddIn.Hide
  29.    
  30. End Sub
  31.  
  32. Sub Show()
  33.   
  34.     On Error Resume Next
  35.     
  36.     If mfrmAddIn Is Nothing Then
  37.         Set mfrmAddIn = New frmAddIn
  38.     End If
  39.     
  40.     Set mfrmAddIn.VBInstance = VBInstance
  41.     Set mfrmAddIn.Connect = Me
  42.     FormDisplayed = True
  43.     mfrmAddIn.Show
  44.    
  45. End Sub
  46.  
  47. '------------------------------------------------------
  48. 'this method adds the Add-In to VB
  49. '------------------------------------------------------
  50. Private Sub IDTExtensibility_OnConnection(ByVal VBInst As Object, ByVal ConnectMode As vbext_ConnectMode, ByVal AddInInst As VBIDE.AddIn, custom() As Variant)
  51.     
  52.     On Error GoTo error_handler
  53.     
  54.     'save the vb instance
  55.     Set VBInstance = VBInst
  56.     
  57.     'this is a good place to set a breakpoint and
  58.     'test various addin objects, properties and methods
  59.     Debug.Print VBInst.FullName
  60.  
  61.     If ConnectMode = vbext_cm_External Then
  62.         'Used by the wizard toolbar to start this wizard
  63.         Me.Show
  64.     Else
  65.         Set mcbMenuCommandBar = AddToAddInCommandBar("My AddIn")
  66.         'sink the event
  67.         Set Me.MenuHandler = VBInst.Events.CommandBarEvents(mcbMenuCommandBar)
  68.     End If
  69.   
  70.     If ConnectMode = vbext_cm_AfterStartup Then
  71.         If GetSetting(App.Title, "Settings", "DisplayOnConnect", "0") = "1" Then
  72.             'set this to display the form on connect
  73.             Me.Show
  74.         End If
  75.     End If
  76.   
  77.     Exit Sub
  78.     
  79. error_handler:
  80.     
  81.     MsgBox Err.Description
  82.     
  83. End Sub
  84.  
  85. '------------------------------------------------------
  86. 'this method removes the Add-In from VB
  87. '------------------------------------------------------
  88. Private Sub IDTExtensibility_OnDisconnection(ByVal RemoveMode As vbext_DisconnectMode, custom() As Variant)
  89.     
  90.     On Error Resume Next
  91.     
  92.     'delete the command bar entry
  93.     mcbMenuCommandBar.Delete
  94.     
  95.     'shut down the Add-In
  96.     If FormDisplayed Then
  97.         SaveSetting App.Title, "Settings", "DisplayOnConnect", "1"
  98.         FormDisplayed = False
  99.     Else
  100.         SaveSetting App.Title, "Settings", "DisplayOnConnect", "0"
  101.     End If
  102.     
  103.     Unload mfrmAddIn
  104.     Set mfrmAddIn = Nothing
  105.  
  106. End Sub
  107.  
  108. Private Sub IDTExtensibility_OnStartupComplete(custom() As Variant)
  109.     If GetSetting(App.Title, "Settings", "DisplayOnConnect", "0") = "1" Then
  110.         'set this to display the form on connect
  111.         Me.Show
  112.     End If
  113. End Sub
  114.  
  115. Private Sub IDTExtensibility_OnAddInsUpdate(custom() As Variant)
  116. '
  117. End Sub
  118.  
  119. 'this event fires when the menu is clicked in the IDE
  120. Private Sub MenuHandler_Click(ByVal CommandBarControl As Object, handled As Boolean, CancelDefault As Boolean)
  121.     Me.Show
  122. End Sub
  123.  
  124. Function AddToAddInCommandBar(sCaption As String) As Office.CommandBarControl
  125.     Dim cbMenuCommandBar As Office.CommandBarControl  'command bar object
  126.     Dim cbMenu As Object
  127.   
  128.     On Error GoTo AddToAddInCommandBarErr
  129.     
  130.     'see if we can find the Add-Ins menu
  131.     Set cbMenu = VBInstance.CommandBars("Add-Ins")
  132.     If cbMenu Is Nothing Then
  133.         'not available so we fail
  134.         Exit Function
  135.     End If
  136.     
  137.     'add it to the command bar
  138.     Set cbMenuCommandBar = cbMenu.Controls.Add(1)
  139.     'set the caption
  140.     cbMenuCommandBar.Caption = sCaption
  141.     
  142.     Set AddToAddInCommandBar = cbMenuCommandBar
  143.     
  144.     Exit Function
  145.     
  146. AddToAddInCommandBarErr:
  147.  
  148. End Function
  149.  
  150.  
  151.