System Tray and Title Bar Button
This (really long) code is something I wrote awhile ago to demonstrate how to 1) add a button to the title bar, and 2) minimize the form to the system tray.

VB Code:
  1. 'form code:
  2. Option Explicit
  3.  
  4. Private Sub Form_Load()
  5.   Init
  6. End Sub
  7.  
  8. Private Sub Form_Unload(Cancel As Integer)
  9.   RemoveIcon
  10.   Terminate
  11. End Sub
  12.  
  13. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
  14. Dim msg As Long
  15.  
  16.   msg = x / Screen.TwipsPerPixelX
  17.   Select Case msg
  18.     'Case WM_LBUTTONDOWN
  19.  
  20.     'Case WM_LBUTTONUP
  21.  
  22.     Case WM_LBUTTONDBLCLK
  23.       Me.Visible = True
  24.       Me.WindowState = 0
  25.     'Case WM_RBUTTONDOWN
  26.            
  27.     'Case WM_RBUTTONUP
  28.  
  29.     'Case WM_RBUTTONDBLCLK
  30.  
  31.   End Select
  32.  
  33. End Sub
  34.  
  35. Public Sub ButtonPressed()
  36.   AddIcon Me, "test"
  37. End Sub
  38.  
  39. 'module code:
  40. Option Explicit
  41.  
  42. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
  43.   (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  44. Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, _
  45.   lpRect As Rect) As Long
  46. Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
  47. Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, _
  48.   ByVal hWndNewParent As Long) As Long
  49. Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, _
  50.   ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx _
  51.   As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
  52. Private Declare Function SetWindowsHookEx Lib "user32" Alias _
  53.   "SetWindowsHookExA" (ByVal idHook&, ByVal lpfn&, ByVal hmod&, ByVal _
  54.   dwThreadId&) As Long
  55. Private Declare Function UnhookWindowsHookEx Lib "user32" _
  56.   (ByVal hHook&) As Long
  57. Private Declare Function CreateWindowEx Lib "user32" Alias _
  58.   "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, _
  59.   ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, _
  60.   ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal _
  61.   hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, _
  62.   lpParam As Any) As Long
  63. Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, _
  64.   ByVal nCmdShow As Long) As Long
  65.  
  66. Private Declare Function Shell_NotifyIcon Lib "shell32" Alias _
  67.   "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) _
  68.   As Boolean
  69.  
  70.  
  71. Private Type Rect
  72.     Left As Long
  73.     Top As Long
  74.     Right As Long
  75.     Bottom As Long
  76. End Type
  77.  
  78. Private Type CWPSTRUCT
  79.     lParam As Long
  80.     wParam As Long
  81.     Message As Long
  82.     hwnd As Long
  83. End Type
  84.  
  85. Public Type NOTIFYICONDATA
  86.    cbSize As Long
  87.    hwnd As Long
  88.    uid As Long
  89.    uFlags As Long
  90.    uCallBackMessage As Long
  91.    hIcon As Long
  92.    szTip As String * 64
  93. End Type
  94.  
  95. Private Const NIM_ADD = &H0
  96. Private Const NIM_MODIFY = &H1
  97. Private Const NIM_DELETE = &H2
  98. Private Const WM_MOUSEMOVE = &H200
  99. Private Const NIF_MESSAGE = &H1
  100. Private Const NIF_ICON = &H2
  101. Private Const NIF_TIP = &H4
  102.  
  103. Public Const WM_LBUTTONDBLCLK = &H203
  104. Public Const WM_LBUTTONDOWN = &H201
  105. Public Const WM_LBUTTONUP = &H202
  106. Public Const WM_RBUTTONDBLCLK = &H206
  107. Public Const WM_RBUTTONDOWN = &H204
  108. Public Const WM_RBUTTONUP = &H205
  109.  
  110. Private NID As NOTIFYICONDATA
  111.  
  112. Const WM_MOVE = &H3
  113. Const WM_SETCURSOR = &H20
  114. Const WM_NCPAINT = &H85
  115. Const WM_COMMAND = &H111
  116.  
  117. Const SWP_FRAMECHANGED = &H20
  118. Const GWL_EXSTYLE = -20
  119.  
  120. Private WHook&
  121. Private ButtonHwnd As Long
  122.  
  123. Public Sub Init()
  124.     'Create the button that is going to be placed in the Titlebar
  125.     ButtonHwnd& = CreateWindowEx(0&, "Button", "-", &H40000000, 50, 50, 14, 14, frmMain.hwnd, 0&, App.hInstance, 0&)
  126.     'Show the button cause it´s invisible
  127.     Call ShowWindow(ButtonHwnd&, 1)
  128.     'Initialize the window hooking for the button
  129.     WHook = SetWindowsHookEx(4, AddressOf HookProc, 0, App.ThreadID)
  130.     Call SetWindowLong(ButtonHwnd&, GWL_EXSTYLE, &H80)
  131.     Call SetParent(ButtonHwnd&, GetParent(frmMain.hwnd))
  132. End Sub
  133.  
  134. Public Sub Terminate()
  135.     'Terminate the window hooking
  136.     Call UnhookWindowsHookEx(WHook)
  137.     Call SetParent(ButtonHwnd&, frmMain.hwnd)
  138. End Sub
  139.  
  140. Public Function HookProc&(ByVal nCode&, ByVal wParam&, Inf As CWPSTRUCT)
  141.     Dim FormRect As Rect
  142.     Static LastParam&
  143.     If Inf.hwnd = GetParent(ButtonHwnd&) Then
  144.         If Inf.Message = WM_COMMAND Then
  145.             Select Case LastParam
  146.                 'If the LastParam is cmdInTitlebar call the Click-Procedure
  147.                 'of the button
  148.                 Case ButtonHwnd&: frmMain.ButtonPressed
  149.             End Select
  150.         ElseIf Inf.Message = WM_SETCURSOR Then
  151.             LastParam = Inf.wParam
  152.         End If
  153.         ElseIf Inf.hwnd = frmMain.hwnd Then
  154.         If Inf.Message = WM_NCPAINT Or Inf.Message = WM_MOVE Then
  155.             'Get the size of the Form
  156.             Call GetWindowRect(frmMain.hwnd, FormRect)
  157.             'Place the button int the Titlebar
  158.             Call SetWindowPos(ButtonHwnd&, 0, FormRect.Right - 75, FormRect.Top + 6, 17, 14, SWP_FRAMECHANGED)
  159.         End If
  160.     End If
  161. End Function
  162.  
  163. Public Sub AddIcon(TheForm As Form, strT As String)
  164.     NID.cbSize = Len(NID)
  165.     NID.hwnd = TheForm.hwnd
  166.     NID.uid = vbNull
  167.     NID.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
  168.     NID.uCallBackMessage = WM_MOUSEMOVE
  169.     NID.hIcon = TheForm.Icon
  170.     NID.szTip = strT & vbNullChar
  171.     Shell_NotifyIcon NIM_ADD, NID
  172.    
  173.     TheForm.WindowState = vbMinimized
  174.     TheForm.Hide
  175. End Sub
  176.  
  177. Public Sub RemoveIcon()
  178.   Shell_NotifyIcon NIM_DELETE, NID
  179. End Sub

Enjoy!