Attribute VB_Name = "SysTrayModule" 'This library file written by Alex Vallat. Contact me at homepage at http://www.ByAlexV.co.uk ' 'This module is for putting icons in the system tray. See the procedures for details on 'how to use them. ' 'All functions return true if successful Option Explicit 'The X parameter of the MouseMove Sub of the Recieving control recieves the event. 'The events it can receive are those listed below: 'IMPORTANT!! The control must have its scale mode set to pixels, NOT twips (which is the default) Public Const WM_MOUSEMOVE = &H200 Public Const WM_LBUTTONDOWN = &H201 Public Const WM_LBUTTONUP = &H202 Public Const WM_LBUTTONDBLCLICK = &H203 Public Const WM_RBUTTONDOWN = &H204 Public Const WM_RBUTTONUP = &H205 Public Const WM_RBUTTONDBLCLICK = &H206 '----------------------------------------- Private Const NIF_ICON = &H2 Private Const NIF_MESSAGE = &H1 Private Const NIF_TIP = &H4 Private Const NIM_ADD = &H0 Private Const NIM_DELETE = &H2 Private Const NIM_MODIFY = &H1 Type NOTIFYICONDATA cbSize As Long hWnd As Long uID As Long uFlags As Long uCallBackMessage As Long hIcon As Long szTip As String * 64 End Type Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long Dim nidTray As NOTIFYICONDATA Public Function TrayAddIcon(cCallback As Control, sTip As String, lIcon As Long, lID As Long) As Boolean 'This function adds an icon to the system tray. cCallback must be a control whose mousemove event 'will recieve the messages from the icon in its X parameter. This is usually a picture box. 'sTip is the string to display when the mouse is hovered over the the icon. 'lIcon is the icon to display (As an icon. To load one from a file, use the LoadPicture function) 'lID is an ID to refer to the icon. Use a different ID for each icon you add. nidTray.cbSize = Len(nidTray) nidTray.hWnd = cCallback.hWnd nidTray.uID = lID nidTray.uFlags = NIF_MESSAGE + NIF_ICON + NIF_TIP nidTray.uCallBackMessage = WM_MOUSEMOVE nidTray.hIcon = lIcon nidTray.szTip = sTip & Chr$(0) TrayAddIcon = CBool(Shell_NotifyIcon(NIM_ADD, nidTray)) End Function Public Function TrayChangeIcon(cCallback As Control, lIcon As Long, lID As Long) As Boolean 'This function changes the icon of an existing tray icon. 'lIcon is the new icon to use, and lID is the tray icon ID you want to change. nidTray.cbSize = Len(nidTray) nidTray.hWnd = cCallback.hWnd nidTray.uID = lID nidTray.uFlags = NIF_ICON nidTray.uCallBackMessage = WM_MOUSEMOVE nidTray.hIcon = lIcon TrayChangeIcon = CBool(Shell_NotifyIcon(NIM_MODIFY, nidTray)) End Function Public Function TrayDeleteIcon(cCallback As Control, lID As Long) As Boolean 'This function removes an icon added using TrayAddIcon. Make sure the ID is 'the same as you used to add it. nidTray.cbSize = Len(nidTray) nidTray.hWnd = cCallback.hWnd nidTray.uID = lID nidTray.uCallBackMessage = WM_MOUSEMOVE TrayDeleteIcon = CBool(Shell_NotifyIcon(NIM_DELETE, nidTray)) End Function Public Function TrayChangeTip(cCallback As Control, sTip As String, lID As Long) As Boolean 'This function changes the tip of an existing tray icon. 'sTip is the new tip string to use, and lID is the tray icon ID you want to change. nidTray.cbSize = Len(nidTray) nidTray.hWnd = cCallback.hWnd nidTray.uID = lID nidTray.uFlags = NIF_TIP nidTray.uCallBackMessage = WM_MOUSEMOVE nidTray.szTip = sTip & Chr$(0) TrayChangeTip = CBool(Shell_NotifyIcon(NIM_MODIFY, nidTray)) End Function