Email to me if you want to get a working example (cool, free). :-)
Option Explicit Private 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'Declare the constants for the API function. These constants can be 'found in the header file Shellapi.h.'The following constants are the messages sent to the 'Shell_NotifyIcon function to add, modify, or delete an icon from the 'taskbar status area. Private Const NIM_ADD = &H0 Private Const NIM_MODIFY = &H1 Private Const NIM_DELETE = &H2'The following constant is the message sent when a mouse event occurs 'within the rectangular boundaries of the icon in the taskbar status 'area. Private Const WM_MOUSEMOVE = &H200'The following constants are the flags that indicate the valid 'members of the NOTIFYICONDATA data type. Private Const NIF_MESSAGE = &H1 Private Const NIF_ICON = &H2 Private Const NIF_TIP = &H4'The following constants are used to determine the mouse input on the 'the icon in the taskbar status area.'Left-click constants. Private Const WM_LBUTTONDBLCLK = &H203 'Double-click Private Const WM_LBUTTONDOWN = &H201 'Button down Private Const WM_LBUTTONUP = &H202 'Button up'Right-click constants. Private Const WM_RBUTTONDBLCLK = &H206 'Double-click Private Const WM_RBUTTONDOWN = &H204 'Button down Private Const WM_RBUTTONUP = &H205 'Button up Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As BooleanPrivate Sub Form_Load() nid.cbSize = Len(nid) nid.hWnd = Me.hWnd nid.uId = vbNull nid.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE nid.uCallBackMessage = WM_MOUSEMOVE nid.szTip = "测试" & vbNullChar nid.hIcon = Me.Icon Shell_NotifyIcon NIM_ADD, nid Me.Visibled = False End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Select Case msg Case WM_LBUTTONDOWN Case WM_LBUTTONUP Case WM_LBUTTONDBLCLK Me.Visible = True Me.SetFocus Case WM_RBUTTONDOWN PopupMenu mnuFile Case WM_RBUTTONUP Case WM_RBUTTONDBLCLK End Select End SubPrivate Sub Form_Terminate() Shell_NotifyIcon NIM_DELETE, nid End Sub
http://expert.csdn.net/Topic/32298.shtm
http://expert.csdn.net/Topic/32298.shtm
http://expert.csdn.net/Topic/32298.shtm
http://expert.csdn.net/Topic/32298.shtm
或http://go18.163.com/~lumine/pages/mysoft/source/vb/systray.zip下载SysTray的源程序。
Private 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'Declare the constants for the API function. These constants can be
'found in the header file Shellapi.h.'The following constants are the messages sent to the
'Shell_NotifyIcon function to add, modify, or delete an icon from the
'taskbar status area.
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2'The following constant is the message sent when a mouse event occurs
'within the rectangular boundaries of the icon in the taskbar status
'area.
Private Const WM_MOUSEMOVE = &H200'The following constants are the flags that indicate the valid
'members of the NOTIFYICONDATA data type.
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4'The following constants are used to determine the mouse input on the
'the icon in the taskbar status area.'Left-click constants.
Private Const WM_LBUTTONDBLCLK = &H203 'Double-click
Private Const WM_LBUTTONDOWN = &H201 'Button down
Private Const WM_LBUTTONUP = &H202 'Button up'Right-click constants.
Private Const WM_RBUTTONDBLCLK = &H206 'Double-click
Private Const WM_RBUTTONDOWN = &H204 'Button down
Private Const WM_RBUTTONUP = &H205 'Button up
Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As BooleanPrivate Sub Form_Load()
nid.cbSize = Len(nid)
nid.hWnd = Me.hWnd
nid.uId = vbNull
nid.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
nid.uCallBackMessage = WM_MOUSEMOVE
nid.szTip = "测试" & vbNullChar
nid.hIcon = Me.Icon
Shell_NotifyIcon NIM_ADD, nid
Me.Visibled = False
End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Select Case msg
Case WM_LBUTTONDOWN
Case WM_LBUTTONUP
Case WM_LBUTTONDBLCLK
Me.Visible = True
Me.SetFocus
Case WM_RBUTTONDOWN
PopupMenu mnuFile
Case WM_RBUTTONUP
Case WM_RBUTTONDBLCLK
End Select
End SubPrivate Sub Form_Terminate()
Shell_NotifyIcon NIM_DELETE, nid
End Sub