home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 February / Chip_2002-02_cd1.bin / zkuste / vbasic / Data / Utility / PropWiz.exe / Dev / PropertyAddIn / AddIn.Dsr < prev    next >
Text File  |  2000-01-27  |  5KB  |  160 lines

  1. VERSION 5.00
  2. Begin {AC0714F6-3D04-11D1-AE7D-00A0C90F26F4} Connect 
  3.    ClientHeight    =   10020
  4.    ClientLeft      =   1740
  5.    ClientTop       =   1545
  6.    ClientWidth     =   10335
  7.    _ExtentX        =   18230
  8.    _ExtentY        =   17674
  9.    _Version        =   393216
  10.    Description     =   "Property Wizard Add In"
  11.    DisplayName     =   "Control Property Wizard"
  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.     
  54.     If mfrmAddIn.Create Then
  55.         FormDisplayed = True
  56.         mfrmAddIn.Show
  57.    End If
  58.    
  59. End Sub
  60.  
  61. '------------------------------------------------------
  62. 'this method adds the Add-In to VB
  63. '------------------------------------------------------
  64. Private Sub AddinInstance_OnConnection(ByVal Application As Object, _
  65.     ByVal ConnectMode As Long _
  66.         , ByVal AddInInst As Object, custom() As Variant)
  67.     On Error GoTo error_handler
  68.     
  69.     'save the vb instance
  70.     Set VBInstance = Application
  71.     
  72.     'this is a good place to set a breakpoint and
  73.     'test various addin objects, properties and methods
  74.     Debug.Print VBInstance.FullName
  75.  
  76.     If ConnectMode = vbext_cm_External Then
  77.         'Used by the wizard toolbar to start this wizard
  78.         Me.Show
  79.     Else
  80.         Set mcbMenuCommandBar = AddToAddInCommandBar("Property Wizard")
  81.         'sink the event
  82.         Set Me.MenuHandler = VBInstance.Events.CommandBarEvents(mcbMenuCommandBar)
  83.     End If
  84.   
  85.     If ConnectMode = vbext_cm_AfterStartup Then
  86.         If GetSetting(App.Title, "Settings", "DisplayOnConnect", "0") = "1" Then
  87.             'set this to display the form on connect
  88.             Me.Show
  89.         End If
  90.     End If
  91.   
  92.     Exit Sub
  93.     
  94. error_handler:
  95.     
  96.     MsgBox Err.Description
  97.     
  98. End Sub
  99.  
  100. '------------------------------------------------------
  101. 'this method removes the Add-In from VB
  102. '------------------------------------------------------
  103. Private Sub AddinInstance_OnDisconnection(ByVal RemoveMode As Long, custom() As Variant)
  104.     On Error Resume Next
  105.     
  106.     'delete the command bar entry
  107.     mcbMenuCommandBar.Delete
  108.     
  109.     'shut down the Add-In
  110.     If FormDisplayed Then
  111.         SaveSetting App.Title, "Settings", "DisplayOnConnect", "1"
  112.         FormDisplayed = False
  113.     Else
  114.         SaveSetting App.Title, "Settings", "DisplayOnConnect", "0"
  115.     End If
  116.     
  117.     Unload mfrmAddIn
  118.     Set mfrmAddIn = Nothing
  119.  
  120. End Sub
  121.  
  122. Private Sub IDTExtensibility_OnStartupComplete(custom() As Variant)
  123.     If GetSetting(App.Title, "Settings", "DisplayOnConnect", "0") = "1" Then
  124.         'set this to display the form on connect
  125.         Me.Show
  126.     End If
  127. End Sub
  128.  
  129. 'this event fires when the menu is clicked in the IDE
  130. Private Sub MenuHandler_Click(ByVal CommandBarControl As Object, handled As Boolean, CancelDefault As Boolean)
  131.     Me.Show
  132. End Sub
  133.  
  134. Function AddToAddInCommandBar(sCaption As String) As Office.CommandBarControl
  135.     Dim cbMenuCommandBar As Office.CommandBarControl  'command bar object
  136.     Dim cbMenu As Object
  137.   
  138.     On Error GoTo AddToAddInCommandBarErr
  139.     
  140.     'see if we can find the Add-Ins menu
  141.     Set cbMenu = VBInstance.CommandBars("Add-Ins")
  142.     If cbMenu Is Nothing Then
  143.         'not available so we fail
  144.         Exit Function
  145.     End If
  146.     
  147.     'add it to the command bar
  148.     Set cbMenuCommandBar = cbMenu.Controls.Add(1)
  149.     'set the caption
  150.     cbMenuCommandBar.Caption = sCaption
  151.     
  152.     Set AddToAddInCommandBar = cbMenuCommandBar
  153.     
  154.     Exit Function
  155.     
  156. AddToAddInCommandBarErr:
  157.  
  158. End Function
  159.  
  160.