要实现如下功能
1.开机任务栏出现图标,但不运行窗体。(我已经做成系统服务了的)
2.图标右键菜单
3.关闭窗体不退出托盘图标,点托盘右键上“退出”选项才退出。谢谢大虾帮忙

解决方案 »

  1.   

    SysTrayDecs.bas
    '------------------------------------------------------
    ' VB CENTER
    '
    ' Tutorial: Using the system tray
    ' 09/26/98
    '
    ' You may distribute this file as long as all the credits
    ' Are given to VB Center
    '
    ' For more tutorials and a detailed explanation of this
    ' tutorial, visit our page: http://vbcenter.cjb.net
    '
    '------------------------------------------------------Declare Function Shell_NotifyIcon Lib "shell32.dll" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
    'If you get an error message at the beginning of the program,
    'use the declaration below:
    'Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias " Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long'These three constants specify what you want to do
    Public Const NIM_ADD = &H0
    Public Const NIM_DELETE = &H2
    Public Const NIM_MODIFY = &H1Public Const NIF_ICON = &H2
    Public Const NIF_MESSAGE = &H1
    Public Const NIF_TIP = &H4Public Const WM_LBUTTONDBLCLK = &H203
    Public Const WM_LBUTTONDOWN = &H201
    Public Const WM_LBUTTONUP = &H202
    Public Const WM_MOUSEMOVE = &H200
    Public Const WM_RBUTTONDBLCLK = &H206
    Public Const WM_RBUTTONDOWN = &H204
    Public Const WM_RBUTTONUP = &H205Type NOTIFYICONDATA
            cbSize As Long
            hwnd As Long
            uID As Long
            uFlags As Long
            uCallbackMessage As Long
            hIcon As Long
            szTip As String * 64
    End TypePublic IconData As NOTIFYICONDATA
    'FormPrivate Sub Form_Resize()If Me.WindowState = 1 Then
    'The user has minimized his windowCall Shell_NotifyIcon(NIM_ADD, IconData)' Add the form's icon to the trayMe.Hide' Hide the button at the taskbarEnd IfEnd SubPrivate Sub Form_Load()With IconData.cbSize = Len(IconData)
    ' The length of the NOTIFYICONDATA type.hIcon = Me.Icon
    ' A reference to the form's icon.hwnd = Me.hwnd
    ' hWnd of the form.szTip = "My Tooltip" & Chr(0)
    ' Tooltip string delimited with a null character.uCallbackMessage = WM_MOUSEMOVE
    ' The icon we're placing will send messages to the MouseMove event.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    ' It will have message handling and a tooltip.uID = vbNull
    ' uID is not used by VB, so it's set to a Null valueEnd WithEnd SubPrivate Sub mnuExit_Click()Unload Me
    ' Unload the formEnd
    ' Just to be sure the program has endedEnd SubPrivate Sub mnuShow_Click()Me.WindowState = vbNormal
    Shell_NotifyIcon NIM_DELETE, IconData
    Me.ShowEnd SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)Dim Msg As LongMsg = X
    ' The message is passed to the X value' You must set your form's ScaleMode property to pixels in order to get the correct messageIf Msg = WM_LBUTTONDBLCLK Then
    ' The user has double-clicked your iconCall mnuShow_Click
    ' Show the windowElseIf Msg = WM_RBUTTONDOWN Then
    ' Right-clickPopupMenu mnuPopup
    ' Popup the menuEnd IfEnd SubPrivate Sub Form_Unload(Cancel As Integer)Shell_NotifyIcon NIM_DELETE, IconDataEnd Sub