Option Explicit
Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Private Const NIM_ADD = &H0
Private Const NIM_DELETE = &H2
Private Const NIM_MODIFY = &H1
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
Private Const WM_MOUSEMOVE = &H200
Private Type NOTIFYICONDATA
cbSize As Long
hwnd As Long
uID As Long
uFlags As Long
uCallbackMessage As Long
hIcon As Long
szTip As String * 40
End Type
Dim myData As NOTIFYICONDATA
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbRightButton Then
Me.WindowState = 0
End If
End Sub
Private Sub Form_Resize()
If Me.WindowState = 1 Then
With myData
.cbSize = Len(myData)
.hwnd = Me.hwnd
.uID = 0
.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
.uCallbackMessage = WM_MOUSEMOVE
.hIcon = Me.Icon.Handle '默认为窗口图标
.szTip = "数据采集工具 V1.0.0" & vbNullChar
End With
Shell_NotifyIcon NIM_ADD, myData
Else
Shell_NotifyIcon NIM_DELETE, myData
End If
End Sub