Option Explicit
Const MAX_TOOLTIP As Integer = 64
Const nif_icon = &H2
Const nif_message = &H1
Const nif_tip = &H4
Const niM_add = &H0
Const nim_delete = &H2
Const wm_mousemove = &H200
Const wm_lbuttondown = &H201
Const wm_lbuttonup = &H202
Const wm_lbuttonblclk = &H203
Const wm_rbuttondown = &H204
Const wm_rbuttonup = &H205
Const wm_rbuttondblclk = &H206
Const sw_restore = 9
Const sw_hide = 0
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As LongPrivate Declare Function Shell_NotifyIconA Lib "shell32.dll" Alias " Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As LongPrivate 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 TypePrivate nfIconData As NOTIFYICONDATAPrivate Sub Command1_Click()
nfIconData.hwnd = Me.hwnd
nfIconData.uID = Me.Icon
nfIconData.uFlags = nif_icon Or nif_message Or nif_tip
nfIconData.uCallbackMessage = wm_mousemove
nfIconData.hIcon = Me.Icon.Handle
nfIconData.szTip = "system tray example" & vbNullChar
nfIconData.cbSize = Len(nfIconData)
Call Shell_NotifyIconA(niM_add, nfIconData)
End SubPrivate Sub Command2_Click()
Call Shell_NotifyIconA(nim_delete, nfIconData)
End SubPrivate Sub Command3_Click()
ShowWindow Me.hwnd, sw_hide
End SubPrivate Sub Command4_Click()
Call Shell_NotifyIcon(nim_delete, nfIconData)
End SubPrivate Sub Command5_Click()
Me.Visible = False
End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim lMsg As Single
lMsg = X / Screen.TwipsPerPixelX
If lMsg = wm_rbuttonup Or lMsg = wm_lbuttonup Then Me.PopupMenu sys
End Sub
Const MAX_TOOLTIP As Integer = 64
Const nif_icon = &H2
Const nif_message = &H1
Const nif_tip = &H4
Const niM_add = &H0
Const nim_delete = &H2
Const wm_mousemove = &H200
Const wm_lbuttondown = &H201
Const wm_lbuttonup = &H202
Const wm_lbuttonblclk = &H203
Const wm_rbuttondown = &H204
Const wm_rbuttonup = &H205
Const wm_rbuttondblclk = &H206
Const sw_restore = 9
Const sw_hide = 0
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As LongPrivate Declare Function Shell_NotifyIconA Lib "shell32.dll" Alias " Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As LongPrivate 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 TypePrivate nfIconData As NOTIFYICONDATAPrivate Sub Command1_Click()
nfIconData.hwnd = Me.hwnd
nfIconData.uID = Me.Icon
nfIconData.uFlags = nif_icon Or nif_message Or nif_tip
nfIconData.uCallbackMessage = wm_mousemove
nfIconData.hIcon = Me.Icon.Handle
nfIconData.szTip = "system tray example" & vbNullChar
nfIconData.cbSize = Len(nfIconData)
Call Shell_NotifyIconA(niM_add, nfIconData)
End SubPrivate Sub Command2_Click()
Call Shell_NotifyIconA(nim_delete, nfIconData)
End SubPrivate Sub Command3_Click()
ShowWindow Me.hwnd, sw_hide
End SubPrivate Sub Command4_Click()
Call Shell_NotifyIcon(nim_delete, nfIconData)
End SubPrivate Sub Command5_Click()
Me.Visible = False
End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim lMsg As Single
lMsg = X / Screen.TwipsPerPixelX
If lMsg = wm_rbuttonup Or lMsg = wm_lbuttonup Then Me.PopupMenu sys
End Sub
Call Shell_NotifyIconA(niM_add, nfIconData)
Call Shell_NotifyIconA(nim_delete, nfIconData)
Call Shell_NotifyIcon(nim_delete, nfIconData)
Public Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias " Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
载程序中调用
Shell_NotifyIcon