'Puts app icon in the system tray
Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Private 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 Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
Private Const WM_MOUSEMOVE = &H200
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
Private Const WM_LBUTTONDBLCLK = &H203
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
Private Const WM_RBUTTONDBLCLK = &H206
Private Const WM_RBUTTONDOWN = &H204
Private Const WM_RBUTTONUP = &H205
Private SysTray As NOTIFYICONDATA
Dim Result As Long
Private Sub StartInSysTray()
SysTray.cbSize = Len(SysTray)
SysTray.hWnd = Picture1.hWnd
SysTray.uId = 1&
SysTray.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
SysTray.ucallbackMessage = WM_MOUSEMOVE
'change the below line to the desired icon
SysTray.hIcon = Me.Icon
SysTray.szTip = App.EXEName & ".exe"
Shell_NotifyIcon NIM_ADD, SysTray
Me.Hide
End Sub
Private Sub Form_Load()
StartInSysTray
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Remove the icon from the system tray
SysTray.cbSize = Len(SysTray)
SysTray.hWnd = Picture1.hWnd
SysTray.uId = 1&
Shell_NotifyIcon NIM_DELETE, SysTray
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
Static rec As Boolean, msg As Long
Dim RetVal As String
Dim returnstring
Dim retvalue
msg = x / Screen.TwipsPerPixelX
If rec = False Then
rec = True
Select Case msg
Case WM_LBUTTONDOWN
Me.Show
Me.WindowState = vbNormal
Case WM_LBUTTONUP
Case WM_RBUTTONblck
'Bring up the menu if the right mouse button is clicked over the icon
'what is this for?
If Button = vbRightButton Then
PopupMenu me.mnuFile
End If
'
Case WM_RBUTTONUP
End Select
rec = False
End If
End Sub