跳到主要内容

VB6启用托盘效果

·

1、窗口新建立一个Picture1命名为 Pci 然后在里面选择你采用的托盘图标。
2、建立菜单栏标题为托盘,名称为 Popup 的名称。
3、在首行复制以下代码进行加载。

 1Private Type NOTIFYICONDATA'首行加载以下代码 by:红防安全吧
 2    cbSize As Long
 3    hwnd As Long
 4    uId As Long
 5    uFlags As Long
 6    uCallBackMessage As Long
 7    hIcon As Long
 8    szTip As String * 64
 9End Type
10 
11Private Const NIM_ADD = &H0
12Private Const NIM_MODIFY = &H1
13Private Const NIM_DELETE = &H2
14Private Const WM_MOUSEMOVE = &H200
15Private Const NIF_MESSAGE = &H1
16Private Const NIF_ICON = &H2
17Private Const NIF_TIP = &H4
18 
19Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
20Dim t As NOTIFYICONDATA

4、启动窗口加载以下代码

1'启动时加载pci图标
2  t.cbSize = Len(t)
3    t.hwnd = Pic.hwnd
4    t.uId = 1&
5    t.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
6    t.uCallBackMessage = WM_MOUSEMOVE
7    t.hIcon = Pic.Picture
8    t.szTip = "WebSafe Scan" & Chr$(0)
9    Shell_NotifyIcon NIM_ADD, t

5、以下是右下角按右按键时弹出的代码

 1Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
 2    t.cbSize = Len(t)  '右按键弹出
 3    t.hwnd = Pic.hwnd
 4    t.uId = 1&
 5    Shell_NotifyIcon NIM_DELETE, t
 6End Sub
 7 
 8Private Sub pic_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
 9    If Hex(X) = "1E3C" Then
10        Me.PopupMenu Popup
11    End If
12End Sub

6、这里是关闭右上角叉时出现的卸载对象

 1Private Sub Form_Unload(Cancel As Integer) '卸载对象
 2Cancel = 1
 3t.cbSize = Len(t)
 4t.hwnd = Pic.hwnd
 5t.uId = 1&
 6t.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
 7t.uCallBackMessage = WM_MOUSEMOVE
 8t.hIcon = Pic.Picture
 9t.szTip = "WebSafe Scan" & Chr$(0)
10Shell_NotifyIcon NIM_ADD, t
11 
12End'退出
13End Sub
白日映照满天星
作者
白日映照满天星
订阅我频道让你站在上帝角度观察视野! QQ:3925993 有尝解决技术问题【备注你的问题】 🐑

阅读量:评论:
赞赏码图