2个回答
展开全部
下面的代码放到一个标准模块中:
Option Explicit
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
Private Const NIF_STATE = &H8
Private Const NIF_INFO = &H10
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
Private Const NIM_SETFOCUS = &H3
Private Const NIM_SETVERSION = &H4
Private Const NIM_VERSION = &H5
Private Const WM_USER As Long = &H400
Private Const NIN_BALLOONSHOW = (WM_USER + 2)
Private Const NIN_BALLOONHIDE = (WM_USER + 3)
Private Const NIN_BALLOONTIMEOUT = (WM_USER + 4)
Private Const NIN_BALLOONUSERCLICK = (WM_USER + 5)
Private Const NOTIFYICON_VERSION = 3
Private Const NIS_HIDDEN = &H1
Private Const NIS_SHAREDICON = &H2
Private Const WM_NOTIFY As Long = &H4E
Private Const WM_COMMAND As Long = &H111
Private Const WM_CLOSE As Long = &H10
Private Const WM_MOUSEMOVE As Long = &H200
Private Const WM_LBUTTONDOWN As Long = &H201
Private Const WM_LBUTTONUP As Long = &H202
Private Const WM_LBUTTONDBLCLK As Long = &H203
Private Const WM_MBUTTONDOWN As Long = &H207
Private Const WM_MBUTTONUP As Long = &H208
Private Const WM_MBUTTONDBLCLK As Long = &H209
Private Const WM_RBUTTONDOWN As Long = &H204
Private Const WM_RBUTTONUP As Long = &H205
Private Const WM_RBUTTONDBLCLK As Long = &H206
Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Private 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
'鼠标事件
Public Enum TrayRetunEventEnum
NM_MOUSEMOVE = &H200 '鼠标移过
NM_LBUTTONDOWN = &H201 '鼠标左键按下
NM_LBUTTONUP = &H202 '鼠标右键弹起
NM_LDBCLICK = &H203 '鼠标左键双击
NM_RBUTTONDOWN = &H204 '鼠标右键按下
NM_RBUTTONUP = &H205 '鼠标右键弹起
NM_RDBCLICK = &H206 '鼠标右键双击
NM_MBUTTONDOWN = &H207 '鼠标中键按下
NM_MBUTTONUP = &H208 '鼠标中键弹起
NM_MDBCLICK = &H209 '鼠标中键双击
NM_BALLONCLICK = (WM_USER + 5) '气泡被单击
End Enum
Private m_Tray As NOTIFYICONDATA
Private m_Load As Boolean
Public Function AddTrayIcon(ByVal hWnd As Long, ByVal ToolTip As String, ByVal hIcon As Long) As Long
With m_Tray
.cbSize = Len(m_Tray)
.hWnd = hWnd
.uID = vbNull
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.uCallbackMessage = WM_MOUSEMOVE
.hIcon = hIcon
.szTip = ToolTip & vbNullChar
End With
AddTrayIcon = Shell_NotifyIcon(NIM_ADD, m_Tray)
End Function
Public Property Get Tips() As String
Tips = m_Tray.szTip
End Property
Public Property Let Tips(ByVal NewValue As String)
m_Tray.szTip = NewValue & vbNullChar
Shell_NotifyIcon NIM_MODIFY, m_Tray
End Property
Public Property Get IconHandle() As Long
IconHandle = m_Tray.hIcon
End Property
Public Property Let IconHandle(ByVal NewValue As Long)
m_Tray.hIcon = IconHandle
Shell_NotifyIcon NIM_MODIFY, m_Tray
End Property
Public Function RemoveIcon() As Long
Shell_NotifyIcon NIM_DELETE, m_Tray
End Function
'然后你在窗口添加一个Picture1控件
窗口的代码
Private Sub Form_Load()
Call AddTrayIcon(Picture1.hWnd, "提示文字", Me.Icon.Handle)
End SUb
Private Sub Form_Unload()
Call RemoveIcon '移除托盘图标
End Sub
Option Explicit
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
Private Const NIF_STATE = &H8
Private Const NIF_INFO = &H10
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
Private Const NIM_SETFOCUS = &H3
Private Const NIM_SETVERSION = &H4
Private Const NIM_VERSION = &H5
Private Const WM_USER As Long = &H400
Private Const NIN_BALLOONSHOW = (WM_USER + 2)
Private Const NIN_BALLOONHIDE = (WM_USER + 3)
Private Const NIN_BALLOONTIMEOUT = (WM_USER + 4)
Private Const NIN_BALLOONUSERCLICK = (WM_USER + 5)
Private Const NOTIFYICON_VERSION = 3
Private Const NIS_HIDDEN = &H1
Private Const NIS_SHAREDICON = &H2
Private Const WM_NOTIFY As Long = &H4E
Private Const WM_COMMAND As Long = &H111
Private Const WM_CLOSE As Long = &H10
Private Const WM_MOUSEMOVE As Long = &H200
Private Const WM_LBUTTONDOWN As Long = &H201
Private Const WM_LBUTTONUP As Long = &H202
Private Const WM_LBUTTONDBLCLK As Long = &H203
Private Const WM_MBUTTONDOWN As Long = &H207
Private Const WM_MBUTTONUP As Long = &H208
Private Const WM_MBUTTONDBLCLK As Long = &H209
Private Const WM_RBUTTONDOWN As Long = &H204
Private Const WM_RBUTTONUP As Long = &H205
Private Const WM_RBUTTONDBLCLK As Long = &H206
Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Private 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
'鼠标事件
Public Enum TrayRetunEventEnum
NM_MOUSEMOVE = &H200 '鼠标移过
NM_LBUTTONDOWN = &H201 '鼠标左键按下
NM_LBUTTONUP = &H202 '鼠标右键弹起
NM_LDBCLICK = &H203 '鼠标左键双击
NM_RBUTTONDOWN = &H204 '鼠标右键按下
NM_RBUTTONUP = &H205 '鼠标右键弹起
NM_RDBCLICK = &H206 '鼠标右键双击
NM_MBUTTONDOWN = &H207 '鼠标中键按下
NM_MBUTTONUP = &H208 '鼠标中键弹起
NM_MDBCLICK = &H209 '鼠标中键双击
NM_BALLONCLICK = (WM_USER + 5) '气泡被单击
End Enum
Private m_Tray As NOTIFYICONDATA
Private m_Load As Boolean
Public Function AddTrayIcon(ByVal hWnd As Long, ByVal ToolTip As String, ByVal hIcon As Long) As Long
With m_Tray
.cbSize = Len(m_Tray)
.hWnd = hWnd
.uID = vbNull
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.uCallbackMessage = WM_MOUSEMOVE
.hIcon = hIcon
.szTip = ToolTip & vbNullChar
End With
AddTrayIcon = Shell_NotifyIcon(NIM_ADD, m_Tray)
End Function
Public Property Get Tips() As String
Tips = m_Tray.szTip
End Property
Public Property Let Tips(ByVal NewValue As String)
m_Tray.szTip = NewValue & vbNullChar
Shell_NotifyIcon NIM_MODIFY, m_Tray
End Property
Public Property Get IconHandle() As Long
IconHandle = m_Tray.hIcon
End Property
Public Property Let IconHandle(ByVal NewValue As Long)
m_Tray.hIcon = IconHandle
Shell_NotifyIcon NIM_MODIFY, m_Tray
End Property
Public Function RemoveIcon() As Long
Shell_NotifyIcon NIM_DELETE, m_Tray
End Function
'然后你在窗口添加一个Picture1控件
窗口的代码
Private Sub Form_Load()
Call AddTrayIcon(Picture1.hWnd, "提示文字", Me.Icon.Handle)
End SUb
Private Sub Form_Unload()
Call RemoveIcon '移除托盘图标
End Sub
AiPPT
2024-09-19 广告
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询