home *** CD-ROM | disk | FTP | other *** search
/ Master 95 #1 / MASTER95_1.iso / microsof / vbasic4 / vb4-6.cab / align.cls < prev    next >
Encoding:
Text File  |  1995-07-26  |  4.8 KB  |  129 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "Connector"
  6. Attribute VB_Creatable = True
  7. Attribute VB_Exposed = True
  8. Attribute VB_Description = "Align Sample Add-In"
  9. 'This class is used to connect this addin to the Visual Basic
  10. 'design environment.  It must the Public property set to True, and the
  11. 'Instancing property set to '2 - Createable MultiUse' (recommended for addins)
  12. 'or '1 - Createble SingleUse'
  13. Option Explicit
  14. 'Storage for the menu and menuline objects created when the add-in adds its own menu
  15. 'and menulines to Visual Basic
  16. Const AlignLeft = 0
  17. Const AlignRight = 1
  18. Const AlignTop = 2
  19. Const AlignBottom = 3
  20. Const AlignAbout = 4
  21. Const SizeWidth = 5
  22. Const SizeHeight = 6
  23. Const SizeBoth = 7
  24.  
  25. Dim AlignMenu As VBIDE.SubMenu
  26. Dim SizeMenu As VBIDE.SubMenu
  27. Dim MenuLines(AlignLeft To SizeBoth) As VBIDE.MenuLine
  28. Dim AlignHandler(AlignLeft To AlignBottom) As AlignAll
  29. Dim SizeHandler(SizeWidth To SizeBoth) As SizeAll
  30. Dim ConnectID(AlignLeft To SizeBoth) As Long
  31. Dim VBInstance As VBIDE.Application
  32.  
  33. Sub ConnectAddIn(VBDriverInstance As VBIDE.Application)
  34. Dim i%
  35.     'This method is called when this add-in is installed in an instance
  36.     'of Visual Basic.  Choose "Align Sample Add-In" from the Add-In manager
  37.     'on another instance of VB. VBInstance will be the object representation
  38.     'of the instance of Visual Basic which installed the add-in.  To change
  39.     'the name of the addin in the addin manager, select the Align project in the
  40.     'object browser, click on the Connector class, and choose Options.
  41.  
  42.     'Save the instance of Visual Basic so we can refer to it later.
  43.     Set VBInstance = VBDriverInstance
  44.     
  45.     With VBInstance.AddInMenu.MenuItems
  46.         'Add our Align menu and menu lines to the Visual Basic Add-In menu.
  47.         Set AlignMenu = .AddMenu("A&lign")
  48.         With AlignMenu.MenuItems
  49.             Set MenuLines(AlignLeft) = .Add("&Left Align")
  50.             Set MenuLines(AlignRight) = .Add("&Right Align")
  51.             Set MenuLines(AlignTop) = .Add("&Top Align")
  52.             Set MenuLines(AlignBottom) = .Add("&Bottom Align")
  53.             Set MenuLines(AlignAbout) = .Add("About...")
  54.         End With
  55.         'Add our Align menu and menu lines to the Visual Basic Add-In menu.
  56.         Set SizeMenu = .AddMenu("Si&ze")
  57.         With SizeMenu.MenuItems
  58.             Set MenuLines(SizeWidth) = .Add("&Width")
  59.             Set MenuLines(SizeHeight) = .Add("&Height")
  60.             Set MenuLines(SizeBoth) = .Add("&Both")
  61.         End With
  62.     End With
  63.     
  64.     'Connect the corresponding event handler object to the correct menu line.
  65.     For i% = AlignLeft To AlignBottom
  66.         'Create a new handler for each direction.
  67.         Set AlignHandler(i%) = New AlignAll
  68.         'Save the ID for each connected event.
  69.         ConnectID(i%) = MenuLines(i%).ConnectEvents(AlignHandler(i%))
  70.         'Pass the VBInstance to the child objects.
  71.         Set AlignHandler(i%).VBInstance = VBInstance
  72.     Next i%
  73.     
  74.     'Set the AfterClick handler for the about box.
  75.     ConnectID(AlignAbout) = MenuLines(AlignAbout).ConnectEvents(Me)
  76.     
  77.     'Connect the SizeHandler events.  Same as hooking up Align events.
  78.     For i% = SizeWidth To SizeBoth
  79.         Set SizeHandler(i%) = New SizeAll
  80.         ConnectID(i%) = MenuLines(i%).ConnectEvents(SizeHandler(i%))
  81.         Set SizeHandler(i%).VBInstance = VBInstance
  82.     Next i%
  83.     
  84.     'Initialize the directional Align instances.
  85.     AlignHandler(AlignLeft).MainProp = "Left"
  86.     AlignHandler(AlignRight).MainProp = "Left"
  87.     AlignHandler(AlignRight).ShiftProp = "Width"
  88.     AlignHandler(AlignTop).MainProp = "Top"
  89.     AlignHandler(AlignBottom).MainProp = "Top"
  90.     AlignHandler(AlignBottom).ShiftProp = "Height"
  91.     
  92.     'Initialize SizeFlags on Size instances.
  93.     SizeHandler(SizeWidth).SizeFlags = 1
  94.     SizeHandler(SizeHeight).SizeFlags = 2
  95.     SizeHandler(SizeBoth).SizeFlags = 3
  96. End Sub
  97.  
  98. Sub DisconnectAddIn(Mode As Integer)
  99. Dim i%
  100. Dim mnuItems As VBIDE.MenuItems
  101.     'Remove AlignMenu items.
  102.     Set mnuItems = AlignMenu.MenuItems
  103.     For i% = AlignLeft To AlignAbout
  104.         'Disconnect the event handlers from the menu lines
  105.         MenuLines(i%).DisconnectEvents ConnectID(i%)
  106.         'Remove the menu and menu lines we installed in Visual Basic
  107.         mnuItems.Remove MenuLines(i%)
  108.     Next i%
  109.         
  110.     'Remove SizeMenu items.
  111.     Set mnuItems = SizeMenu.MenuItems
  112.     For i% = SizeWidth To SizeBoth
  113.         MenuLines(i%).DisconnectEvents ConnectID(i%)
  114.         mnuItems.Remove MenuLines(i%)
  115.     Next i%
  116.     
  117.     'Remove items from Addins menu.
  118.     With VBInstance.AddInMenu.MenuItems
  119.         .Remove AlignMenu
  120.         .Remove SizeMenu
  121.     End With
  122. End Sub
  123.  
  124. 'Use this class to provide an AfterClick handler for About...
  125. Public Sub AfterClick()
  126.     About.Show vbModal
  127. End Sub
  128.  
  129.