home *** CD-ROM | disk | FTP | other *** search
/ distrib.akp.su/Programming/Vb-6+Rus/ / distrib.akp.su.tar / distrib.akp.su / Programming / Vb-6+Rus / VB98 / TEMPLATE / PROJECTS / ADDIN.DSR < prev    next >
Text File  |  1998-06-18  |  5KB  |  155 lines

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