'Module: SysTray.BAS
' To put an icon in system tray
'Author: Pheeraphat Sawangphian
'E-Mail:
[email protected]
'URL: http://www.geocities.com/Hollywood/Lot/6166
'Note: Put the following lines in Form Load event.
' SystemTray.cbSize = Len(SystemTray)
' SystemTray.hWnd = Me.hWnd
' SystemTray.uId = vbNull
' SystemTray.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
' SystemTray.ucallbackMessage = WM_MOUSEMOVE
' SystemTray.hIcon = <Icon>
' SystemTray.szTip = <Tip> & vbNullChar
' Call Shell_NotifyIcon(NIM_ADD, SystemTray)
' Where <Icon> is an icon you want to show in system tray.
' <Tip> is a tip that shown when mouse moved over the icon in system tray
' You can detect mouse event in Form MouseMove event.
' To remove an icon from system tray:
' Call Shell_NotifyIcon(NIM_DELETE, SystemTray)
Option Explicit 'force explicit declaration of all variables
Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Public Const NIM_ADD = &H0 'add an icon into system tray
Public Const NIM_MODIFY = &H1 'update an icon in system tray
Public Const NIM_DELETE = &H2 'remove an icon from system tray
Public Const NIF_MESSAGE = &H1 'I want return messages
Public Const NIF_ICON = &H2 'adding an icon
Public Const NIF_TIP = &H4 'adding a tip
'rodent constant need for the callback
Public Const WM_LBUTTONDBLCLK = &H203
Public Const WM_RBUTTONUP = &H205
Public Const WM_MOUSEMOVE = &H200
'system tray notification definitions
Public 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
Public SystemTray As NOTIFYICONDATA