VB6.0。当程序在托盘运行时,怎样弹出消息?

当程序在托盘运行时,怎样弹出消息?(如图是某软件实现的效果)大家不要介意我的托盘,空的只不过是我把它擦掉了。... 当程序在托盘运行时,怎样弹出消息?(如图是某软件实现的效果)
大家不要介意我的托盘,空的只不过是我把它擦掉了。
展开
 我来答
湘湖泛舟
推荐于2016-01-30 · TA获得超过1076个赞
知道大有可为答主
回答量:833
采纳率:0%
帮助的人:900万
展开全部
新建一个模块
粘上以下代码

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
'鼠标事件,在调用窗口中的move()过程中返回以下按键值,可用来进行相关操作
Public Enum TrayClick
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
' **************************************************************
'1 设置托盘一般提示
'注:MyIcon 图标既可以来源于文件,又可能来源于窗体内的某个图标
' **************************************************************
Public Sub TrayAddIcon(ByVal MyForm As Form, ByVal MyIcon, 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
If TypeName(MyIcon) = "String" Then
.hIcon = LoadImage(App.hInstance, MyIcon, IMAGE_ICON, 16, 16, LR_LOADFROMFILE Or LR_LOADMAP3DCOLORS)
Else
If InStr(1, "Picture,Image", TypeName(MyIcon), vbTextCompare) > 0 Then
.hIcon = MyIcon
End If
End If
.szTip = ToolTip & vbNullChar
End With
Call Shell_NotifyIcon(NIM_ADD, ni)
End Sub
' *********************************************
'2 托盘托盘气泡提示
' *********************************************
'一、有声气泡提示
'TrayBalloon Form1, Command1.Caption & vbNewLine & Format(Date, "日期:yyyy年mm月dd日"), "系统托盘", NIIF_INFO
'二、无声气泡提示
'TrayBalloon Form1, Command2.Caption, "系统托盘", NIIF_INFO Or NIIF_NOSOUND
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
' *********************************************
'3 移除托盘图标
' *********************************************
Public Sub TrayRemoveIcon()
Shell_NotifyIcon NIM_DELETE, ni
End Sub
'3.1删除其他程序的托盘图标
Sub TrayRemoveIcon_Ex(Hwnd As Long)
Dim TrayIcon As NOTIFYICONDATA
TrayIcon.cbSize = Len(TrayIcon)
TrayIcon.Hwnd = Hwnd
TrayIcon.uID = vbNull
Call Shell_NotifyIcon(NIM_DELETE, TrayIcon)
End Sub
' *********************************************
'4 更改托盘的提示文本
' *********************************************
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
' *********************************************
'5 更改托盘的图标
' *********************************************
Sub TrayIcon(MyIcon)
' Update the tray icon.
With ni
If TypeName(MyIcon) = "String" Then
.hIcon = LoadImage(App.hInstance, MyIcon, IMAGE_ICON, 16, 16, LR_LOADFROMFILE Or LR_LOADMAP3DCOLORS)
Else
If TypeName(MyIcon) = "Picture" Then
.hIcon = MyIcon
End If
End If
.uFlags = NIF_ICON
End With
Shell_NotifyIcon NIM_MODIFY, ni
End Sub
'5 获取托盘图标的提示文本
Function TrayInfo(Wnd As Long) As String
' Update the tray icon.
With ni
.Hwnd = Wnd
.uFlags = NIF_INFO
End With
Shell_NotifyIcon NIM_MODIFY, ni
TrayInfo = ni.szTip
End Function

调用的方法如下:
TrayBalloon Form1, "当前状态:" & "导入数据完成" & "", App.Title, NIIF_INFO Or NIIF_NOSOUND
沙慧月03
2012-07-13 · TA获得超过2157个赞
知道大有可为答主
回答量:2717
采纳率:100%
帮助的人:3627万
展开全部

我有一个托盘控件,留下你的邮箱,我把控件发给你 

代码

Private Sub Command1_Click()

With EFMTrayIcon1

.Visible = True

.TimeOut = 0



.PopupBalloon Me, "你好!", "提示"

End With

End Sub




Private Sub Form_Load()

EFMTrayIcon1.Visible = True


End Sub


Private Sub Form_Unload(Cancel As Integer)

EFMTrayIcon1.Visible = False

End Sub 

追问
stevenlele@yeah.net。我也想参考一下你的。
追答
我已发
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
瓜皮少年Pro
2012-07-13
知道答主
回答量:18
采纳率:0%
帮助的人:3.3万
展开全部
是不是在托盘被隐藏了?点击托盘-自定义-找到vb6.0设置显示图标和通知。另外可能是你装的vb有问题。
更多追问追答
追问
不是隐藏,我是说怎么弹出消息!空的只不过是我把它擦掉了。
追答
能说明白一点吗?
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
lnzzxzy
2012-07-13 · TA获得超过8128个赞
知道小有建树答主
回答量:1316
采纳率:80%
帮助的人:760万
展开全部
新增一个窗体FORM2用于放提示信息,定好位置
在原窗体上放一个Timer1,设置1秒中断一次:Tag = "0"
并加上下面的代码
Private Sub Timer1_Timer()
Tag = (Val(Tag) + 1) Mod 5
If Tag = "0" Then Form2.Show
If Tag = "1" Then Form2.Hide
End Sub
追问
忘了说了,不要新增窗体。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式