home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 5 Developer's Kit / vb5 dev kit.iso / dev / tbexit / taskbar.cls < prev    next >
Encoding:
Text File  |  1996-01-11  |  3.0 KB  |  144 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "clsTaskBar"
  6. Attribute VB_Creatable = False
  7. Attribute VB_Exposed = False
  8. Option Explicit
  9.  
  10. Private Type RECT
  11.     Left As Long
  12.     Top As Long
  13.     Right As Long
  14.     Bottom As Long
  15. End Type
  16.  
  17. Private Type APPBARDATA
  18.     cbSize As Long
  19.     hWnd As Long
  20.     uCallbackMessage As Long
  21.     uEdge As Long
  22.     rc As RECT
  23.     lParam As Long '  message specific
  24. End Type
  25.  
  26. Private Type NOTIFYICONDATA
  27.     cbSize As Long
  28.     hWnd As Long
  29.     uID As Long
  30.     uFlags As Long
  31.     uCallbackMessage As Long
  32.     hIcon As Long
  33.     szTip As String * 64
  34. End Type
  35.  
  36. Private Declare Function Shell_NotifyIcon& Lib "shell32.dll" _
  37. Alias "Shell_NotifyIconA" (ByVal dwMessage&, _
  38. lpData As NOTIFYICONDATA)
  39.  
  40. Private Declare Function SHAppBarMessage& Lib "shell32.dll" _
  41. (ByVal dwMessage&, pData As APPBARDATA)
  42.  
  43. Private Const NIM_ADD = 0&
  44. Private Const NIM_DELETE = 2&
  45. Private Const NIM_MODIFY = 1&
  46. Private Const NIF_ICON = 2&
  47. Private Const NIF_MESSAGE = 1&
  48. Private Const NIF_TIP = 4&
  49.  
  50. Const ABM_GETTASKBARPOS = &H5
  51. Private udtNotify As NOTIFYICONDATA
  52. Private udtAppBarData As APPBARDATA
  53.  
  54. Private Const WM_USER = &H400
  55. Private Const MYWM_NOTIFYICON = WM_USER + &H301
  56.  
  57.  
  58. Public Property Let hWnd(F As Form)
  59.     
  60. 'Assigns the app's hwnd to the notification structure
  61. udtNotify.hWnd = F.hWnd
  62.  
  63. End Property
  64.  
  65.  
  66. Public Property Get CallbackMessage%()
  67.  
  68. 'Returns the message number that Windows will use to notify
  69. 'the app of mouse events
  70. CallbackMessage = udtNotify.uCallbackMessage
  71.  
  72. End Property
  73.  
  74.  
  75. Public Sub AddIconToTray(hIcon&, ID&)
  76.  
  77. 'Adds a new icon to the system tray
  78.  
  79. Dim lResult&
  80.  
  81. udtNotify.uID = ID
  82. udtNotify.hIcon = hIcon
  83. udtNotify.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
  84. lResult = Shell_NotifyIcon(NIM_ADD, udtNotify)
  85.  
  86. End Sub
  87.  
  88. Public Function TaskbarExists&()
  89.  
  90. 'Verify that the task bar exists.  If the user is using a
  91. '3rd party shell, it might not.
  92. udtAppBarData.cbSize = 36&
  93. TaskbarExists = SHAppBarMessage(ABM_GETTASKBARPOS, udtAppBarData)
  94.  
  95. End Function
  96.  
  97.  
  98. Public Sub ChangeTip(sNewTip$, ID&)
  99.     
  100. 'Changes the text displayed when the user pauses
  101. 'the mouse over the icon.
  102.  
  103. Dim lResult&
  104.  
  105. udtNotify.szTip = sNewTip & Chr$(0)
  106. udtNotify.uID = ID
  107. udtNotify.uFlags = NIF_TIP
  108. lResult = Shell_NotifyIcon(NIM_MODIFY, udtNotify)
  109.  
  110. End Sub
  111.  
  112. Public Sub DeleteIcon(ID&)
  113.     
  114. 'Deletes the specified icon from the system tray
  115. Dim lResult&
  116.  
  117. udtNotify.uID = ID
  118. lResult = Shell_NotifyIcon(NIM_DELETE, udtNotify)
  119.  
  120. End Sub
  121.  
  122. Public Sub DeleteAllIcons(nIcons%)
  123.  
  124. Dim iCounter%
  125. Dim lResult&
  126.  
  127. For iCounter = 1 To nIcons
  128.     udtNotify.uID = iCounter
  129.     lResult = Shell_NotifyIcon(NIM_DELETE, udtNotify)
  130. Next iCounter
  131.  
  132. End Sub
  133.  
  134. Private Sub Class_Initialize()
  135.  
  136. 'Initialize elements of the data structure
  137. udtNotify.cbSize = 88&
  138. udtNotify.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
  139. udtNotify.uCallbackMessage = MYWM_NOTIFYICON
  140. udtNotify.szTip = ""
  141.  
  142. End Sub
  143.  
  144.