托盘程序参考:'窗体放一个Command1,把窗体的ShowInTaskbar属性设置为False Option ExplicitPrivate Type NOTIFYICONDATA '托盘结构 cbSize As Long hwnd As Long uID As Long uFlags As Long uCallbackMessage As Long hIcon As Long szTip As String * 128 dwState As Long dwStateMask As Long szInfo As String * 256 uTimeoutAndVersion As Long szInfoTitle As String * 64 dwInfoFlags As Long End Type Const niif_info = &H1Private Const NIM_ADD = &H0 Private Const NIM_MODIFY = &H1 Private Const NIM_DELETE = &H2 Private Const NIF_MESSAGE = &H1 Private Const NIF_ICON = &H2 Private Const NIF_TIP = &H4 Private Const NIF_INFO = &H10 Private Const WM_LBUTTONDBLCLK = &H203 Private Const WM_LBUTTONDOWN = &H201 Private Const WM_RBUTTONUP = &H205 Private Const WM_MOUSEMOVE As Long = &H200Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean '托盘函数 Dim TrayI As NOTIFYICONDATA Private Sub Command1_Click() '气泡提示(别忘了加一个command1控件) Dim infotitle infotitle = "题目" Dim info info = "内容" With TrayI .cbSize = Len(TrayI) .hwnd = Form1.hwnd .uID = vbNull .uFlags = NIF_INFO .dwInfoFlags = niif_info .szInfoTitle = infotitle & vbNullChar .szInfo = info & vbNullChar End With Shell_NotifyIcon NIM_MODIFY, TrayI End SubPrivate Sub Form_Load() Dim Title_tray As String Title_tray = "你好" With TrayI .cbSize = Len(TrayI) .hwnd = Form1.hwnd .uID = vbNull .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE .uCallbackMessage = WM_MOUSEMOVE .hIcon = Form1.Icon .szTip = Title_tray & vbNullChar End With Call Shell_NotifyIcon(NIM_ADD, TrayI) End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 1 Then Me.WindowState = vbNormal Me.Visible = True ' Form1.PopupMenu Form1.bb '弹出菜单 End If If Button = 2 Then '右键 End If End Sub'Private Sub Timer1_Timer() 'Dim a 'a = 1 'End SubPrivate Sub Form_Resize() If Me.WindowState = vbMinimized Then Me.Visible = False End If End Sub
关闭自身的话,用end语句就行了是其他程序的话,可以用sendmessage发送wm_close消息
Option ExplicitPrivate Type NOTIFYICONDATA '托盘结构
cbSize As Long
hwnd As Long
uID As Long
uFlags As Long
uCallbackMessage As Long
hIcon As Long
szTip As String * 128
dwState As Long
dwStateMask As Long
szInfo As String * 256
uTimeoutAndVersion As Long
szInfoTitle As String * 64
dwInfoFlags As Long
End Type
Const niif_info = &H1Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
Private Const NIF_INFO = &H10
Private Const WM_LBUTTONDBLCLK = &H203
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_RBUTTONUP = &H205
Private Const WM_MOUSEMOVE As Long = &H200Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean '托盘函数
Dim TrayI As NOTIFYICONDATA
Private Sub Command1_Click() '气泡提示(别忘了加一个command1控件)
Dim infotitle
infotitle = "题目"
Dim info
info = "内容"
With TrayI
.cbSize = Len(TrayI)
.hwnd = Form1.hwnd
.uID = vbNull
.uFlags = NIF_INFO
.dwInfoFlags = niif_info
.szInfoTitle = infotitle & vbNullChar
.szInfo = info & vbNullChar
End With
Shell_NotifyIcon NIM_MODIFY, TrayI
End SubPrivate Sub Form_Load()
Dim Title_tray As String
Title_tray = "你好"
With TrayI
.cbSize = Len(TrayI)
.hwnd = Form1.hwnd
.uID = vbNull
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.uCallbackMessage = WM_MOUSEMOVE
.hIcon = Form1.Icon
.szTip = Title_tray & vbNullChar
End With
Call Shell_NotifyIcon(NIM_ADD, TrayI)
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Me.WindowState = vbNormal
Me.Visible = True
' Form1.PopupMenu Form1.bb '弹出菜单
End If
If Button = 2 Then
'右键
End If
End Sub'Private Sub Timer1_Timer()
'Dim a
'a = 1
'End SubPrivate Sub Form_Resize()
If Me.WindowState = vbMinimized Then
Me.Visible = False
End If
End Sub