'
Public Const WM_MOUSEMOVE = &H200 '在图标上移动鼠标
Public Const WM_LBUTTONDOWN = &H201 '鼠标左键按下
Public Const WM_LBUTTONUP = &H202 '鼠标左键释放
Public Const WM_LBUTTONDBLCLK = &H203 '双击鼠标左键
Public Const WM_RBUTTONDOWN = &H204 '鼠标右键按下
Public Const WM_RBUTTONUP = &H205 '鼠标右键释放
Public Const WM_RBUTTONDBLCLK = &H206 '双击鼠标右键
Public Const WM_SETHOTKEY = &H32 '响应您定义的热键
'自定义一个调用API Shell_NotifyIcon要用到的类 型"NOTIFYICONDATA"
Public Type NOTIFYICONDATA
cdSize As Long 'NOTIFYICONDATA类型的大小
hwnd As Long '你的应用程序窗体的名柄
uId As Long '应用程序图标资源的ID号
uFlags As Long '使那些参数有效它是以下枚举类型中的
'NIF_MESSAGE、NIF_ICON、NIF_TIP三组的组合
uCallbackMessage As Long '鼠标移动时把此消息发给该图标的窗体
hIcon As Long '图标名柄
szTip As String * 64 '当鼠标在图标上时显示的Tip文本
End Type
'这是一个枚举类型它告诉API Shell_NotifyIcon去做什么操作
Public Const NIM_ADD = &H0 '在“金碟”中加一图标
Public Const NIM_MODIFY = &H1 '修改“金碟”中的图标
Public Const NIM_DELETE = &H2 '删除“金碟”中的图标
Public Const NIF_MESSAGE = &H1 '使类型"NOTIFYICONDATA"中的uCallbackMessage有效
Public Const NIF_ICON = &H2 '使类型"NOTIFYICONDATA"中的hIcon有效
Public Const NIF_TIP = &H4 '使类型"NOTIFYICONDATA"中的szTip有效
' Public Const WM_MOUSEMOVE = &H200 '使鼠标移动消息有效
'定义一个"NOTIFYICONDATA"类型的变量
Public Declare Function Shell_NotifyIcon Lib "shell32" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Boolean
Public Declare Function LoadCursorFromFile Lib "user32" Alias "LoadCursorFromFileA" (ByVal lpFileName As String) As Long
Dim nid As NOTIFYICONDATA
'加载改托盘图标
Public Sub LoadTrayIcon(ByVal lHwnd As Long)
Dim sTip As String
Dim nid As NOTIFYICONDATA
nid.szTip = "84051754-- 在线" & Chr$(0)
nid.cdSize = LenB(nid)
nid.hwnd = lHwnd
nid.uId = 0
nid.hIcon = FormMain.Icon.Handle
nid.uCallbackMessage = WM_MOUSEMOVE
nid.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
Shell_NotifyIcon NIM_ADD, nid
End Sub
'删除改托盘图标
Public Sub DeleteTrayIcon(ByVal lHwnd As Long)
Dim nid As NOTIFYICONDATA
nid.cdSize = LenB(nid)
nid.hwnd = lHwnd
nid.uId = 0
Shell_NotifyIcon NIM_DELETE, nid
End Sub
'更改托盘图标
Public Sub SetTrayIcon(ByVal lHwnd As Long, ByVal IconPath As String)
' If pic.Picture.Type <> vbPicTypeIcon Then Exit Sub
Dim nid As NOTIFYICONDATA
nid.hwnd = lHwnd
nid.hIcon = LoadCursorFromFile(IconPath)
nid.uFlags = NIF_ICON
Shell_NotifyIcon NIM_MODIFY, nid
End Sub