高手请进:VB托盘消息(气球提示)问题
IflMsg=WM_RBUTTONUPThenSetForegroundWindowForm2.hwndPopupMenuTraymenuEndIf请加入托盘消息(气球提...
If lMsg = WM_RBUTTONUP Then
SetForegroundWindow Form2.hwnd
PopupMenu Traymenu
End If
请加入托盘消息(气球提示)的程序.
(托盘已实现了,仅需加入托盘气球提示程序.)
比如提示五秒,然后消失. 展开
SetForegroundWindow Form2.hwnd
PopupMenu Traymenu
End If
请加入托盘消息(气球提示)的程序.
(托盘已实现了,仅需加入托盘气球提示程序.)
比如提示五秒,然后消失. 展开
5个回答
展开全部
加三个Command1,Command2,Command3
'模块
Option Explicit
'使用高分辨率图标所用的API
Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal dwImageType As Long, ByVal dwDesiredWidth As Long, ByVal dwDesiredHeight As Long, ByVal dwFlags As Long) As Long
Private Const LR_LOADFROMFILE = &H10
Private Const LR_LOADMAP3DCOLORS = &H1000
Private Const IMAGE_ICON = 1
'系统托盘
Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
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
Public Enum bFlag
NIIF_NONE = &H0
NIIF_INFO = &H1
NIIF_WARNING = &H2
NIIF_ERROR = &H3
NIIF_GUID = &H5
NIIF_ICON_MASK = &HF
NIIF_NOSOUND = &H10 '关闭提示音标志
End Enum
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
MouseMove = &H200
LeftUp = &H202
LeftDown = &H201
LeftDbClick = &H203
RightUp = &H205
RightDown = &H204
RightDbClick = &H206
MiddleUp = &H208
MiddleDown = &H207
MiddleDbClick = &H209
BalloonClick = (WM_USER + 5)
End Enum
Public ni As NOTIFYICONDATA
Public Sub TrayAddIcon(ByVal MyForm As Form, ByVal MyIcon As String, ByVal ToolTip As String, Optional ByVal bFlag As bFlag)
With ni
.cbSize = Len(ni)
.hwnd = MyForm.hwnd
.uID = vbNull
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.uCallbackMessage = WM_MOUSEMOVE
.hIcon = LoadImage(App.hInstance, MyIcon, IMAGE_ICON, 16, 16, LR_LOADFROMFILE Or LR_LOADMAP3DCOLORS)
.szTip = ToolTip & vbNullChar
End With
Call Shell_NotifyIcon(NIM_ADD, ni)
End Sub
Public Sub TrayRemoveIcon()
Shell_NotifyIcon NIM_DELETE, ni
End Sub
Public Sub TrayBalloon(ByVal MyForm As Form, ByVal sBaloonText As String, sBallonTitle As String, Optional ByVal bFlag As bFlag)
With ni
.cbSize = Len(ni)
.hwnd = MyForm.hwnd
.uID = vbNull
.uFlags = NIF_INFO
.dwInfoFlags = bFlag
.szInfoTitle = sBallonTitle & vbNullChar
.szInfo = sBaloonText & vbNullChar
End With
Shell_NotifyIcon NIM_MODIFY, ni
End Sub
Public Sub TrayTip(ByVal MyForm As Form, ByVal sTipText As String)
With ni
.cbSize = Len(ni)
.hwnd = MyForm.hwnd
.uID = vbNull
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.szTip = sTipText & vbNullChar
End With
Shell_NotifyIcon NIM_MODIFY, ni
End Sub
'窗体
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Sub Command1_Click()
'显示气泡提示用法
TrayBalloon Form1, "欢迎访问枕善居(http://www.mndsoft.com)!", "系统托盘", NIIF_INFO
End Sub
Private Sub Command2_Click()
'显示无声气泡提示
TrayBalloon Form1, "欢迎访问枕善居(http://www.mndsoft.com)!", "系统托盘", NIIF_INFO Or NIIF_NOSOUND
End Sub
Private Sub Command3_Click()
'改变提示文字信息
TrayTip Form1, "欢迎访问枕善居(http://www.mndsoft.com)!"
End Sub
Private Sub Form_Load()
'载入系统托盘
TrayAddIcon Form1, App.Path & "\xptray.ico", "系统托盘"
Command1.Caption = "气泡提示"
Command2.Caption = "气泡提示 (无声)"
Command3.Caption = "一般提示"
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'气泡单击时的鼠标事件
Dim Result As Long
Dim cEvent As Single
cEvent = X / Screen.TwipsPerPixelX
Select Case cEvent
Case MouseMove
'Debug.Print "MouseMove"
Case LeftUp
Debug.Print "左键放开"
Case LeftDown
Debug.Print "左键按下"
Form1.WindowState = 0
Form1.Show
Case LeftDbClick
Debug.Print "左键双击"
Case MiddleUp
Debug.Print "中间键放开"
Case MiddleDown
Debug.Print "中间键按下"
Case MiddleDbClick
Debug.Print "中间键单击"
Case RightUp
Debug.Print "右健放开"
Case RightDown
Debug.Print "右健按下"
'单击后移出
Result = SetForegroundWindow(Me.hwnd)
'当时显示
Me.PopupMenu Me.mSysPopup
Case RightDbClick
Debug.Print "右健双击"
Case BalloonClick
Debug.Print "单击气泡"
End Select
End Sub
Private Sub Form_Resize()
'窗口最小化
If Me.WindowState = vbMinimized Then Me.Hide
End Sub
Private Sub Form_Unload(Cancel As Integer)
'退出时移出托盘图标
TrayRemoveIcon
End Sub
Private Sub mShow_Click()
Form1.WindowState = 0
Form1.Show
End Sub
Private Sub mExit_Click()
Unload Me
End Sub
'模块
Option Explicit
'使用高分辨率图标所用的API
Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal dwImageType As Long, ByVal dwDesiredWidth As Long, ByVal dwDesiredHeight As Long, ByVal dwFlags As Long) As Long
Private Const LR_LOADFROMFILE = &H10
Private Const LR_LOADMAP3DCOLORS = &H1000
Private Const IMAGE_ICON = 1
'系统托盘
Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
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
Public Enum bFlag
NIIF_NONE = &H0
NIIF_INFO = &H1
NIIF_WARNING = &H2
NIIF_ERROR = &H3
NIIF_GUID = &H5
NIIF_ICON_MASK = &HF
NIIF_NOSOUND = &H10 '关闭提示音标志
End Enum
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
MouseMove = &H200
LeftUp = &H202
LeftDown = &H201
LeftDbClick = &H203
RightUp = &H205
RightDown = &H204
RightDbClick = &H206
MiddleUp = &H208
MiddleDown = &H207
MiddleDbClick = &H209
BalloonClick = (WM_USER + 5)
End Enum
Public ni As NOTIFYICONDATA
Public Sub TrayAddIcon(ByVal MyForm As Form, ByVal MyIcon As String, ByVal ToolTip As String, Optional ByVal bFlag As bFlag)
With ni
.cbSize = Len(ni)
.hwnd = MyForm.hwnd
.uID = vbNull
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.uCallbackMessage = WM_MOUSEMOVE
.hIcon = LoadImage(App.hInstance, MyIcon, IMAGE_ICON, 16, 16, LR_LOADFROMFILE Or LR_LOADMAP3DCOLORS)
.szTip = ToolTip & vbNullChar
End With
Call Shell_NotifyIcon(NIM_ADD, ni)
End Sub
Public Sub TrayRemoveIcon()
Shell_NotifyIcon NIM_DELETE, ni
End Sub
Public Sub TrayBalloon(ByVal MyForm As Form, ByVal sBaloonText As String, sBallonTitle As String, Optional ByVal bFlag As bFlag)
With ni
.cbSize = Len(ni)
.hwnd = MyForm.hwnd
.uID = vbNull
.uFlags = NIF_INFO
.dwInfoFlags = bFlag
.szInfoTitle = sBallonTitle & vbNullChar
.szInfo = sBaloonText & vbNullChar
End With
Shell_NotifyIcon NIM_MODIFY, ni
End Sub
Public Sub TrayTip(ByVal MyForm As Form, ByVal sTipText As String)
With ni
.cbSize = Len(ni)
.hwnd = MyForm.hwnd
.uID = vbNull
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.szTip = sTipText & vbNullChar
End With
Shell_NotifyIcon NIM_MODIFY, ni
End Sub
'窗体
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Sub Command1_Click()
'显示气泡提示用法
TrayBalloon Form1, "欢迎访问枕善居(http://www.mndsoft.com)!", "系统托盘", NIIF_INFO
End Sub
Private Sub Command2_Click()
'显示无声气泡提示
TrayBalloon Form1, "欢迎访问枕善居(http://www.mndsoft.com)!", "系统托盘", NIIF_INFO Or NIIF_NOSOUND
End Sub
Private Sub Command3_Click()
'改变提示文字信息
TrayTip Form1, "欢迎访问枕善居(http://www.mndsoft.com)!"
End Sub
Private Sub Form_Load()
'载入系统托盘
TrayAddIcon Form1, App.Path & "\xptray.ico", "系统托盘"
Command1.Caption = "气泡提示"
Command2.Caption = "气泡提示 (无声)"
Command3.Caption = "一般提示"
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'气泡单击时的鼠标事件
Dim Result As Long
Dim cEvent As Single
cEvent = X / Screen.TwipsPerPixelX
Select Case cEvent
Case MouseMove
'Debug.Print "MouseMove"
Case LeftUp
Debug.Print "左键放开"
Case LeftDown
Debug.Print "左键按下"
Form1.WindowState = 0
Form1.Show
Case LeftDbClick
Debug.Print "左键双击"
Case MiddleUp
Debug.Print "中间键放开"
Case MiddleDown
Debug.Print "中间键按下"
Case MiddleDbClick
Debug.Print "中间键单击"
Case RightUp
Debug.Print "右健放开"
Case RightDown
Debug.Print "右健按下"
'单击后移出
Result = SetForegroundWindow(Me.hwnd)
'当时显示
Me.PopupMenu Me.mSysPopup
Case RightDbClick
Debug.Print "右健双击"
Case BalloonClick
Debug.Print "单击气泡"
End Select
End Sub
Private Sub Form_Resize()
'窗口最小化
If Me.WindowState = vbMinimized Then Me.Hide
End Sub
Private Sub Form_Unload(Cancel As Integer)
'退出时移出托盘图标
TrayRemoveIcon
End Sub
Private Sub mShow_Click()
Form1.WindowState = 0
Form1.Show
End Sub
Private Sub mExit_Click()
Unload Me
End Sub
参考资料: http://hi.baidu.com/%CE%DE%C1%C4%CB%A3%CB%A3%BF%E1
展开全部
VB不熟;那我删了好了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
上面的程序是抄的,我也试过不行的.而且人家只问如何显示消息.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
留个邮箱 我发给你
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
没做过
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询