×

VB6启用托盘效果

hqy hqy 发表于2025-02-21 16:09:31 浏览5 评论0

抢沙发发表评论

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



Private Type NOTIFYICONDATA

    cbSize As Long

    hwnd As Long

    uId As Long

    uFlags As Long

    uCallBackMessage As Long

    hIcon As Long

    szTip As String * 64

End Type

 

Private Const NIM_ADD = &H0

Private Const NIM_MODIFY = &H1

Private Const NIM_DELETE = &H2

Private Const WM_MOUSEMOVE = &H200

Private Const NIF_MESSAGE = &H1

Private Const NIF_ICON = &H2

Private Const NIF_TIP = &H4

 

Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean

Dim t As NOTIFYICONDATA


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


'启动时加载pci图标

  t.cbSize = Len(t)

    t.hwnd = Pic.hwnd

    t.uId = 1&

    t.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE

    t.uCallBackMessage = WM_MOUSEMOVE

    t.hIcon = Pic.Picture

    t.szTip = "WebSafe Scan" & Chr$(0)

    Shell_NotifyIcon NIM_ADD, t

?复制代码

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


Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

    t.cbSize = Len(t)  '右按键弹出

    t.hwnd = Pic.hwnd

    t.uId = 1&

    Shell_NotifyIcon NIM_DELETE, t

End Sub

 

Private Sub pic_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    If Hex(X) = "1E3C" Then

        Me.PopupMenu Popup

    End If

End Sub

?复制代码

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


Private Sub Form_Unload(Cancel As Integer) '卸载对象

Cancel = 1

t.cbSize = Len(t)

t.hwnd = Pic.hwnd

t.uId = 1&

t.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE

t.uCallBackMessage = WM_MOUSEMOVE

t.hIcon = Pic.Picture

t.szTip = "WebSafe Scan" & Chr$(0)

Shell_NotifyIcon NIM_ADD, t

 

End'退出

End Sub


打赏

本文链接:https://www.kinber.cn/post/4920.html 转载需授权!

分享到:


推荐本站淘宝优惠价购买喜欢的宝贝:

image.png

 您阅读本篇文章共花了: 

群贤毕至

访客