VB启用托盘效果

| |
[不指定 2019/03/11 16:58 | by admin ]
1、窗口新建立一个Picture1命名为 Pci 然后在里面选择你采用的托盘图标
2、建立菜单栏标题为托盘,名称为 Popup
3、在首行复制以下代码进行加载

'------------------------------------------------------------------------------------------------------------------
Private Type NOTIFYICONDATA'首行加载以下代码BY:红防安全吧 http://hkfx.net
    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
程序源码 | 评论(0) | 引用(0) | 阅读(226)