I have to give you this in two parts, because there is a 10,000 character limit on individual posts (I know because I've exceeded it before). First: Start a new project, and paste this into the declarations section of Form1
VB Code:
  1. Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
  2.  
  3. Private Type NOTIFYICONDATA
  4.     cbSize As Long
  5.     hWnd As Long
  6.     uId As Long
  7.     uFlags As Long
  8.     ucallbackMessage As Long
  9.     hIcon As Long
  10.     szTip As String * 64
  11. End Type
  12.  
  13. Private Const NIM_ADD = &H0
  14. Private Const NIM_MODIFY = &H1
  15. Private Const NIM_DELETE = &H2
  16. Private Const WM_MOUSEMOVE = &H200
  17. Private Const NIF_MESSAGE = &H1
  18. Private Const NIF_ICON = &H2
  19. Private Const NIF_TIP = &H4
  20. Private Const WM_LBUTTONDBLCLK = &H203
  21. Private Const WM_LBUTTONDOWN = &H201
  22. Private Const WM_LBUTTONUP = &H202
  23. Private Const WM_RBUTTONDBLCLK = &H206
  24. Private Const WM_RBUTTONDOWN = &H204
  25. Private Const WM_RBUTTONUP = &H205
  26.  
  27. Private SysTray As NOTIFYICONDATA
  28.  
  29. Private Sub StartInSysTray()
  30.     SysTray.cbSize = Len(SysTray)
  31.     SysTray.hwnd = Picture1.hwnd
  32.     SysTray.uId = 1&
  33.     SysTray.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
  34.     SysTray.ucallbackMessage = WM_MOUSEMOVE
  35.     SysTray.hIcon = Me.Icon
  36.     SysTray.szTip = "&R&e&s&t&a&r&t" & Chr$(0)
  37.     Shell_NotifyIcon NIM_ADD, SysTray
  38.     Me.Hide
  39.     App.TaskVisible = False
  40. End Sub
  41.  
  42. Private Sub Form_Load()
  43. StartInSysTray
  44. End Sub
  45.  
  46. Private Sub Form_Unload(Cancel As Integer)
  47.     SysTray.cbSize = Len(SysTray)
  48.     SysTray.hwnd = Picture1.hwnd
  49.     SysTray.uId = 1&
  50.     Shell_NotifyIcon NIM_DELETE, SysTray
  51. End Sub
  52.  
  53. 'Add A Picture Control To The Form.   Set its visible property to False
  54. Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  55.  
  56. Static rec As Boolean, msg As Long
  57.     Dim RetVal As String
  58.     Dim returnstring
  59.     Dim retvalue
  60.     msg = X / Screen.TwipsPerPixelX
  61.     If rec = False Then
  62.         rec = True
  63.     Select Case msg
  64.     'here are the various mouse events that you can use once
  65.     'you application is in the system tray.   select the event of your
  66.     'choice and put CloseExceptUs there.   (CloseExceptUs is a
  67.     'routine that I will post momentarily.   It also needs to go on
  68.     'this form.)
  69.     Case WM_LBUTTONDOWN
  70.  
  71.     Case WM_LBUTTONDBLCLK
  72.  
  73.     Case WM_LBUTTONUP
  74.  
  75.     Case WM_RBUTTONUP
  76.  
  77.     End Select
  78.         rec = False
  79.     End If
  80.  
  81. End Sub