Public Const WM_LBUTTONDBLCLICK = &H203
Public Const WM_RBUTTONUP = &H205 Public Const WM_MOUSEMOVE = &H200 Public Const NIM_ADD = &H0 Public Const NIM_MODIFY = &H1 Public Const NIM_DELETE = &H2 Public Const NIF_MESSAGE = &H1 Public Const NIF_ICON = &H2 Public Const NIF_TIP = &H4 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 VBGTray As NOTIFYICONDATA Declare Function Shell_NotifyIcon Lib "shell32" Alias _ "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long 'on the form1 Private Sub GoSystemTray() VBGTray.cbSize = Len(VBGTray) VBGTray.hWnd = Me.hWnd VBGTray.uId = vbNull VBGTray.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE VBGTray.ucallbackMessage = WM_MOUSEMOVE VBGTray.hIcon = Me.Icon 'tooltiptext VBGTray.szTip = Me.Caption & vbNullChar Call Shell_NotifyIcon(NIM_ADD, VBGTray) App.TaskVisible = False 'remove application from taskbar Me.Hide End Sub Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Static lngMsg As Long Static blnFlag As Boolean Dim result As Long lngMsg = X / Screen.TwipsPerPixelX If blnFlag = False Then blnFlag = True Select Case lngMsg 'doubleclick Case WM_LBUTTONDBLCLICK Me.Show 'right-click Case WM_RBUTTONUP result = SetForegroundWindow(Me.hwnd) Me.PopupMenu mnuSystemtray End Select blnFlag = False End If End Sub Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) VBGTray.cbSize = Len(VBGTray) VBGTray.hWnd = Me.hWnd VBGTray.uId = vbNull Call Shell_NotifyIcon(NIM_DELETE, VBGTray) End Sub 'make on the form a menu called mnuSystemTray 'set visible to false 'with the neccesarry items 'at least one to exit the application! 'don't forget to put the appropiate code under the menu-item(s) 'use it as for example 'form_load 'do something what has to be done 'goto to systemtray => Call GoSystemTray |