home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 5 Developer's Kit / vb5 dev kit.iso / dev / tskvb4 / taskbar.cls next >
Encoding:
Text File  |  1996-07-22  |  5.5 KB  |  168 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "CTaskBar"
  6. Attribute VB_Creatable = False
  7. Attribute VB_Exposed = False
  8. Option Explicit
  9.  
  10. '----------------------------------------------------------
  11. 'This class encapsulates the 32-bit API functions for using
  12. 'the Windows 95/NT4 TaskBar Notification Area (also know as the
  13. 'Tray).  With this class you may add icons to the Notification
  14. 'Area, replace them (for signaling), change their ToolTip text,
  15. 'and delete them when they are no longer needed.
  16. '----------------------------------------------------------
  17. 'Copyright 1995/1996 by Don Bradner.  May be freely distributed
  18. 'Author contact: CIS 76130,1007; internet dbirdman@redshift.com
  19. 'http://www.redshift.com/~arcatpet.  Support available as time
  20. 'allows, including the VBPJ and MSBASIC forums on Compuserve.
  21. '==========================================================
  22. '                       PRIVATE VARIABLES
  23. '==========================================================
  24.  
  25. ' -----------------------------------------------------------
  26. ' NOTIFYICONDATA type is needed for Shell_NotifyIcon function
  27. '------------------------------------------------------------
  28.  
  29. Private Type NOTIFYICONDATA
  30.     lStructureSize    As Long
  31.     hWnd   As Long
  32.     lID As Long
  33.     lFlags As Long
  34.     lCallBackMessage As Long
  35.     hIcon As Long
  36.     sTip As String * 64
  37. End Type
  38.  
  39. ' -----------------------------------------------------------
  40. ' lRect type and AppBarData are needed for SHAppBarMessage function
  41. '------------------------------------------------------------
  42. Private Type lRect
  43.     Left As Long
  44.     Top As Long
  45.     Right As Long
  46.     Bottom As Long
  47. End Type
  48.  
  49. Private Type APPBARDATA
  50.     lStructureSize As Long
  51.     hWnd As Long
  52.     lCallBackMessage As Long
  53.     lEdge As Long
  54.     rc As lRect
  55.     lparam As Long
  56. End Type
  57.  
  58. Private Declare Function Shell_NotifyIcon& Lib "shell32.dll" (ByVal lMessage&, NID As NOTIFYICONDATA)
  59. Private Declare Function SHAppBarMessage& Lib "shell32.dll" (ByVal dwMessage&, pData As APPBARDATA)
  60.  
  61. Private Const NIM_ADD = 0&
  62. Private Const NIM_DELETE = 2&
  63. Private Const NIM_MODIFY = 1&
  64. Private Const NIF_ICON = 2&
  65. Private Const NIF_MESSAGE = 1&
  66. Private Const NIF_TIP = 4&
  67.  
  68. Private Const ABM_GETTASKBARPOS = &H5&
  69. Private structNotify As NOTIFYICONDATA
  70. Private structBarData As APPBARDATA
  71.  
  72. Private Const WM_USER = &H400
  73. Private Const UM_TASKBARMESSAGE = WM_USER + &H201
  74.  
  75. Private lTempLong&
  76.  
  77. '==========================================================
  78. '                          PROPERTIES
  79. '==========================================================
  80.  
  81. Public Property Let hWnd(Client As Form)
  82.     structNotify.hWnd = Client.hWnd
  83. End Property
  84.  
  85. Public Property Let Message(MsgValue&)
  86.     '---------------------------------
  87.     'Sets the message number to a value
  88.     'different than the startup value.
  89.     'useful if more than one instance of
  90.     'the class is used, since each should
  91.     'return separate messages.
  92.     '-----------------------------------
  93.     structNotify.lCallBackMessage = MsgValue
  94. End Property
  95.  
  96. Public Property Get Message&()
  97.     '---------------------------------
  98.     'Returns the message number that
  99.     'has been set at initialization or
  100.     'changed by the client app via the
  101.     'Property Let Message Proc
  102.     '---------------------------------
  103.     Message = structNotify.lCallBackMessage
  104. End Property
  105.  
  106. '==========================================================
  107. '                            METHODS
  108. '==========================================================
  109.  
  110. Public Sub AddIcon(lID&, sTip$, hIcon)
  111.     structNotify.lID = lID
  112.     structNotify.hIcon = hIcon
  113.     structNotify.sTip = sTip & Chr$(0)
  114.     structNotify.lFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
  115.     lTempLong = Shell_NotifyIcon(NIM_ADD, structNotify)
  116. End Sub
  117.  
  118. Public Function AppBarExists&()
  119.     '--------------------------------------------------------
  120.     'Since a user may be running 32-bit Windows but not be using
  121.     'the Explorer shell, we use the SHAppBarMessage call to determine
  122.     'whether there is a system taskbar.
  123.     '---------------------------------------------------------
  124.     structBarData.lStructureSize = 36&
  125.     AppBarExists = SHAppBarMessage(ABM_GETTASKBARPOS, structBarData)
  126. End Function
  127.  
  128. Public Sub ChangeIcon(lID&, hIcon)
  129.     structNotify.lID = lID
  130.     structNotify.hIcon = hIcon
  131.     structNotify.lFlags = NIF_ICON
  132.     lTempLong = Shell_NotifyIcon(NIM_MODIFY, structNotify)
  133. End Sub
  134.  
  135. Public Sub ChangeMessage(lID&, sNewMessage$)
  136.     structNotify.lID = lID
  137.     structNotify.sTip = sNewMessage & Chr$(0)
  138.     structNotify.lFlags = NIF_TIP
  139.     lTempLong = Shell_NotifyIcon(NIM_MODIFY, structNotify)
  140. End Sub
  141.  
  142. Public Sub DeleteIcon(lID&)
  143.     structNotify.lID = lID
  144.     lTempLong = Shell_NotifyIcon(NIM_DELETE, structNotify)
  145. End Sub
  146.  
  147. Public Sub RemoveAllIcons(iTotal&)
  148. Dim lRet&
  149. For lTempLong = 1 To iTotal
  150.     structNotify.lID = lTempLong
  151.     lRet = Shell_NotifyIcon(NIM_DELETE, structNotify)
  152. Next lTempLong
  153. End Sub
  154.  
  155. '==========================================================
  156. '                     INITIALIZE/TERMINATE
  157. '==========================================================
  158. Private Sub Class_Initialize()
  159.     '------------------------------------------
  160.     'Preset portions of the data structure
  161.     '------------------------------------------
  162.     structNotify.lStructureSize = 88&
  163.     structNotify.lFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
  164.     structNotify.lCallBackMessage = UM_TASKBARMESSAGE
  165.     structNotify.sTip = ""
  166. End Sub
  167.  
  168.