关闭

VB实现NotifyIcon

标签: vbintegershelldeleteimagebutton
1809人阅读 评论(0) 收藏 举报

申明

Option Explicit

'NotifyIcon---与托盘图标相关的申明---开始
Public 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

Public Const NIM_ADD = &H0
Public Const NIM_MODIFY = &H1
Public Const NIM_DELETE = &H2
Public Const NIF_MESSAGE = &H1
Public Const NIF_ICON = &H2
Public Const NIF_TIP = &H4

Public Const WM_LBUTTONDBLCLK = &H203
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const WM_MBUTTONDBLCLK = &H209
Public Const WM_MBUTTONDOWN = &H207
Public Const WM_MBUTTONUP = &H208
Public Const WM_RBUTTONDBLCLK = &H206
Public Const WM_RBUTTONDOWN = &H204
Public Const WM_RBUTTONUP = &H205

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

Public TrayI As NOTIFYICONDATA

'NotifyIcon---与托盘图标相关的申明---结束

Form中调用

'托盘图标---开始
    trayMenu.Visible = False
    'Image1(0).Visible = False
    TrayI.cbSize = Len(TrayI)
    'TrayI.hWnd = Picture1.hWnd     'Link the trayicon to this picturebox
    TrayI.hWnd = Me.hWnd
    TrayI.uId = 1&
    TrayI.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    TrayI.ucallbackMessage = WM_LBUTTONDOWN
    TrayI.hIcon = Image1(0).Picture
    TrayI.szTip = Me.Caption & Chr$(0)
    'Create the icon
    Shell_NotifyIcon NIM_ADD, TrayI
'托盘图标---结束

点击托盘图标

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
   
'当点击了托盘图标后---开始
    Dim Msg
        Msg = X / Screen.TwipsPerPixelX
    If Msg = WM_LBUTTONDBLCLK Then  'If the user dubbel-clicked on the icon
        Me.WindowState = 0
        Me.Show
    End If
   
    If Msg = WM_RBUTTONUP Then  'Right click
        Me.PopupMenu trayMenu
    End If
'当点击了托盘图标后---结束

End Sub

退出程序时

'当程序退出时,处理托盘图标---开始
    TrayI.cbSize = Len(TrayI)
    TrayI.hWnd = Me.hWnd
    TrayI.uId = 1&
    Shell_NotifyIcon NIM_DELETE, TrayI  'Delete NotifyIcon
   
'当程序退出时,处理托盘图标---结束

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:142642次
    • 积分:2088
    • 等级:
    • 排名:第18348名
    • 原创:61篇
    • 转载:12篇
    • 译文:0篇
    • 评论:32条
    文章分类
    最新评论
    友情链接