home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Programmer'…arterly (Limited Edition) / Visual_Basic_Programmers_Journal_VB-CD_Quarterly_Limited_Edition_1995.iso / code / ch24code / clsreg.cls < prev    next >
Encoding:
Text File  |  1995-08-15  |  3.1 KB  |  109 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "Application"
  6. Attribute VB_Creatable = True
  7. Attribute VB_Exposed = True
  8. Option Explicit
  9. Private mnuitRegedit As Object
  10. Private mvbApp As Object
  11. Private mParent As Object
  12. #If Win16 Then
  13. Private mAppHandle As Integer
  14. #Else
  15. Private mAppHandle As Long
  16. #End If
  17.  
  18. ' Declarations for functions used by DisconnectAddIn
  19. #If Win16 Then
  20. Private Declare Function PostAppMessage Lib "User" _
  21.     (ByVal htask As Integer, _
  22.     ByVal wMsg As Integer, _
  23.     ByVal wParam As Integer, _
  24.     lParam As Any) _
  25.     As Integer
  26. Private Declare Function IsTask Lib "KERNEL" _
  27.      (ByVal htask As Integer) _
  28.      As Integer
  29. #Else
  30. ' Under Win32, ending an application is very different.
  31. Private Declare Function OpenProcess Lib "KERNEL32" _
  32.     (ByVal dwDesiredAccess As Long, _
  33.     ByVal bInheritHandle As Long, _
  34.     ByVal dwProcessId As Long) As Long
  35. Private Declare Function TerminateProcess Lib "KERNEL32" _
  36.     (ByVal hProcess As Long, _
  37.     ByVal uExitCode As Long) As Long
  38. Const TERMINATE_PROCESS = &H1
  39. #End If
  40. Const WM_QUIT = &H12
  41.  
  42.  
  43.  
  44.  
  45. Public Sub ConnectAddIn(objApplication As Object)
  46.     ' Establish a reference to the VB application.
  47.     Set mvbApp = objApplication
  48.     Set mnuitRegedit = mvbApp.addinmenu.MenuItems.Add("&Registration Info Editor")
  49.     mnuitRegedit.ConnectEvents Me
  50.     ' Shows how to add submenus.
  51.     ' Dim mnuSub1 As Object, mnuSub2 As Object, mnuSub3 As Object
  52.     ' Set mnuSub1 = mvbApp.addinmenu.MenuItems.AddMenu("&Submenu1")
  53.     ' mnuSub1.MenuItems.Add ("&MenuItem1")
  54.     ' Set mnuSub2 = mnuSub1.MenuItems.AddMenu("&Submenu2")
  55.     ' mnuSub1.MenuItems.Add ("M&enuItem2")
  56.     ' mnuSub1.MenuItems.Add ("Me&nuItem3")
  57.     ' Set mnuSub3 = mnuSub2.MenuItems.AddMenu("&Submenu3")
  58. End Sub
  59.  
  60. Public Sub DisconnectAddIn(iConnect As Integer)
  61.     Dim iWorked As Integer
  62.     ' Check if RegEdit is still running.
  63.     #If Win16 Then
  64.     If IsTask(mAppHandle) Then
  65.         ' Tell RegEdit to close
  66.         iWorked = PostAppMessage(mAppHandle, WM_QUIT, 0, 0)
  67.     End If
  68.     #Else
  69.         iWorked = OpenProcess(TERMINATE_PROCESS, _
  70.             0, mAppHandle)
  71.         If iWorked Then
  72.             iWorked = TerminateProcess(iWorked, 0)
  73.         End If
  74.     #End If
  75.     Select Case iConnect
  76.         ' Addin disconnected because VB closed.
  77.         Case 0
  78.             ' No extra work.
  79.         ' Addin disconnected because user deselected its
  80.         ' check box in the Addin manager.
  81.         Case 1
  82.             ' Remove menu item.
  83.             mnuitRegedit.Parent.Remove mnuitRegedit
  84.     End Select
  85.     ' End AddIn
  86.     End
  87. End Sub
  88.  
  89. Public Sub afterclick()
  90.     mAppHandle = Shell("REGEDIT /V", 1)
  91. End Sub
  92.  
  93. ' Parent property (read always/write once).
  94. Public Property Get Parent() As Object
  95.     ' Return the parent object.
  96.     Set Parent = mParent
  97. End Property
  98.  
  99. Public Property Set Parent(objSetting As Object)
  100.     If TypeName(mParent) = "Nothing" Then
  101.         Set mParent = objSetting
  102.     Else
  103.         ' Can't reset.
  104.         Err.Raise 383, "Application object", "Parent property is read-only."
  105.     End If
  106. End Property
  107.  
  108.  
  109.