VB实现NotifyIcon

原创 2006年05月26日 12:44:00

申明

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
   
'当程序退出时,处理托盘图标---结束

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

WPF NotifyIcon 实现例子

  • 2012-08-15 23:25
  • 36KB
  • 下载

MFC实现NotifyIcon托盘应用程序

/*参考别人的做了细微修改*/ 类似于QQ的托盘程序编写 1.首先我们新建一个MFC程序,在对话框Dlg类中添加一个NOTIFYICONDATA类型对象NOTIFYICONDATA m_nid; ...

WPF实现系统托盘 NotifyIcon

  • 2012-07-26 17:16
  • 393KB
  • 下载

Shell_NotifyIcon实现任意托盘图标的隐藏与再现

发TB_HIDEBUTTON消息来隐藏托盘图标并不完美,会留下一块空白 仔细看一下NOTIFYICONDATA结构,发现了dwState 如果dwStateMask为NIS_HIDDEN,则当dwSt...
  • gfm688
  • gfm688
  • 2012-09-25 15:54
  • 2408

用C#实现智能设备上的NotifyIcon类

前几天有网友问.NET CF中怎么实现NotifyIcon,我这才知道原来.NET CF并没有提供NotifyIcon控件。     于是偶想PC上可以用Shell_NotifyIcon和Messa...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)