首先在formload里加入以下代码:MyProc = SetWindowLong(Me.Hwnd, GWL_WNDPROC, AddressOf WindowProc)
ShowTray me.hwnd,Picture1,"hello"其次定义windowproc
Private Function WindowProc(ByVal Hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
   Dim ret As Long
        
      '实现窗体的拖动
      If msg = WM_NCHITTEST Then
      
        ret = DefWindowProc(Hwnd, msg, wParam, lParam)
        If ret = HTCLIENT Then
          WindowProc = HTCAPTION
        Else
          WindowProc = ret
        End If
                               
       '将其他的消息传给默认的窗口函数进行处理
      Else
        
        If msg = WM_SYSCOMMAND And wParam = SC_MINIMIZE Then
         
            frmEmail.Visible = False
            
        Else
        
            WindowProc = CallWindowProc(MyProc, Hwnd, msg, wParam, lParam)
            
        End If
        
      End If
      
End Function'加入代码托盘
Private Sub ShowTray(myhwnd, IconPic As PictureBox, Optional tip As String = "")
'sets cbSize to the Length of TrayIcon
    TrayIcon.cbSize = Len(TrayIcon)
    ' Handle of the window used to handle messages - which is the this form
    TrayIcon.Hwnd = myhwnd
    ' ID code of the icon
    TrayIcon.uID = vbNull
    ' Flags
    TrayIcon.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    ' ID of the call back message
    TrayIcon.uCallbackMessage = WM_MOUSEMOVE
    ' The icon - sets the icon that should be used
    TrayIcon.hIcon = IconPic.Picture
    ' The Tooltip for the icon - sets the Tooltip that will be displayed
    TrayIcon.szTip = tip & Chr$(0)
    
    ' Add icon to the tray by calling the Shell_NotifyIcon API
    'NIM_ADD is a Constant - add icon to tray
    Call Shell_NotifyIcon(NIM_ADD, TrayIcon)
    
    ' Don't let application appear in the Windows task list
    App.TaskVisible = FalseEnd Sub