当前位置:编程学习 > VB >>

vb在托盘显示

要求如下
【1】打开后一直就有就有托盘图标,打开时窗口应该显示
【2】打开时在托盘弹出气泡,内容为"你好,死王旭"
【3】右键图标,弹出菜单(类似qq),有名字为【王旭易做图】项目
【4】鼠标滑动到图标,显示【王旭SB】
【5】摁下窗口【关闭】按钮(就是“X”),关闭窗口,但不退出程序(类似360杀毒)
【6】程序退出后,图标立即消失(很多时候图标不消失,但鼠标指针一滑过,他才消失)
=========================================
可能比较多,大家可以写清楚问题序号,附上可参考网址
我思绪有点乱
如果有很好的,还会加分
答案:Option Explicit
Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Private Const NIM_ADD = &H0
'在任务栏中增加一个图标
Private Const NIM_DELETE = &H2 '删除任务栏中的一个图标
Private Const NIM_MODIFY = &H1 '修改任务栏中个图标信息
Private Const WM_MOUSEMOVE = &H200
'在图标上移动鼠标
Private Const WM_LBUTTONDOWN = &H201
'鼠标左键按下
Private Const WM_LBUTTONUP = &H202
'鼠标左键释放
Private Const HWND_TOPMOST = -1
Private Const SWP_SHOWWINDOW = &H40
Private Const WM_RBUTTONUP = &H205

Private Type NOTIFYICONDATA

cbSize As Long


' 结构大小(字节)

hwnd As Long


' 处理消息的窗口的句柄

uId As Long


' 唯一的标识符

uFlags As Long


' Flags

uCallBackMessage As Long
' 处理消息的窗口接收的消息

hIcon As Long


' 托盘图标句柄

szTip As String * 128
' Tooltip 提示文本

dwState As Long


' 托盘图标状态

dwStateMask As Long

' 状态掩码

szInfo As String * 256
' 气球提示文本

uTimeoutOrVersion As Long
' 气球提示消失时间或版本






' uTimeout - 气球提示消失时间(单位:ms, 10000 -- 30000)






' uVersion - 版本(0 for V4, 3 for V5)

szInfoTitle As String * 64 ' 气球提示标题

dwInfoFlags As Long

' 气球提示图标
End Type

Private Const NIIF_INFO = &H1

Private Const NIF_INFO = &H10

Private Const NIF_STATE = &H8

Private Const NIF_MESSAGE = &H1 'NIF_MESSAGE 表示发送控制消息;
Private Const NIF_ICON = &H2
'NIF_ICON表示显示控制栏中的图标;
Private Const NIF_TIP = &H4
'NIF_TIP表示任务栏中的图标有动态提示。

Private restoreTime As Date
Dim myData1 As NOTIFYICONDATA
Private Sub Form_Load()

With myData1

.cbSize = Len(myData1)

.hwnd = Me.hwnd

.uId = 0

.uFlags = NIF_TIP Or NIF_ICON Or NIF_MESSAGE Or NIF_INFO Or NIF_STATE

.uCallBackMessage = WM_MOUSEMOVE

.hIcon = Me.Icon.Handle

.szTip = "【王旭SB】" & vbNullChar

.dwState = 0

.dwStateMask = 0

.szInfo = "你好,死王旭" & vbNullChar

.szInfoTitle = "你好" & vbNullChar

.dwInfoFlags = NIIF_INFO

.uTimeoutOrVersion = 10000

End With

Shell_NotifyIcon NIM_ADD, myData1
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)

Dim Message As Long

Message = x / Screen.TwipsPerPixelX

Select Case Message

Case WM_RBUTTONUP


PopupMenu popMenu1

End Select
End Sub

Private Sub Form_Unload(Cancel As Integer)

Me.Hide

Cancel = True
End Sub

Private Sub MenuExit_Click()

Shell_NotifyIcon NIM_DELETE, myData1

End
End Sub
'需要加一个菜单,不是在代码里是在菜单编辑器里,百度HI我发给你

上一个:vb高手来啊
下一个:如何提高开发VB应用程序的效能

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,