Click here to Skip to main content
Click here to Skip to main content

Notify Icon - System tray icon explored

, 15 Feb 2006
Rate this:
Please Sign up or sign in to vote.
A simple class that creates an icon in the status area.

Sample Image - maximum width is 600 pixels

Introduction

    In my article System Tray Icon, I introduced a simple Class that creates an icon in the status area. Icons in the status area are short cuts to processes that are running in the background of a computer, such as a virus protection program or a volume control. These processes do not come with their own user interfaces. Notify Icon provides a way to program in this functionality.

Class Details

Public Methods

ShowIcon (ByRef SysTrayForm As Form) Sets the current icon.

 

RemoveIcon (SysTrayForm As Form) Remove the current icon.

 

ChangeIcon (SysTrayForm As Form, picNewIcon As PictureBox)

 

Sets the ToolTip text displayed when the mouse hovers over a status area icon.
(RestoreIcon (SysTrayForm As Form) Restore default icon.

 

ChangeToolTip (SysTrayForm As Form, strNewTip As String) Sets the ToolTip text displayed when the mouse hovers over a status area icon.

 

Public Events

Const WM_LBUTTONDBLCLK = &H203

Const WM_RBUTTONDBLCLK = &H206

Const WM_MBUTTONDBLCLK = &H209

 

 

Occurs when the user clicks the icon in the status area.
Const WM_LBUTTONDOWN = &H201

Const WM_RBUTTONDOWN = &H204

Const WM_MBUTTONDOWN = &H207

 

 

Occurs when the user presses the mouse button while the pointer is over the icon in the status notification area of the taskbar.
Const WM_MOUSEMOVE = &H200

 

 

 

Occurs when the user moves the mouse while the pointer is over the icon in the status notification area of the taskbar.

 

Const WM_LBUTTONUP = &H202

          

          Const WM_RBUTTONUP = &H205
          <p>Const WM_MBUTTONUP = &H208</p>
          

 

Occurs when the user releases the mouse button while the pointer is over the icon in the status notification area of the taskbar.

 

Using the code

A brief description of how to use the article or code.

<font color="#000000">'
'     ###         ###          ######
'    #     #   # #               #                   #   #
'     ###   # #  ###   #####     #   #####   ####     # #
'        #   #      #            #    ##  # #   ##     #
'    ####   #    ###             #    #      ###  #   #
'</font>

Structure Used

<font color="#000000">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</font>

API Used

<font color="#000000">Private Declare Function Shell_NotifyIcon Lib "shell32" _
Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, _
lpData As NOTIFYICONDATA) As Long</font>

Private Properties

<font color="#000000">Private Property Let bRunningInTray(ByVal vData As Boolean)
    RunningInTray = vData
End Property


Property Get bRunningInTray() As Boolean
    bRunningInTray = RunningInTray
End Property</font>

Function details

<font color="#000000">Public Sub ShowIcon(ByRef SysTrayForm As Form)
    With nic
        .cbSize = Len(nic)
        .Hwnd = SysTrayForm.Hwnd
        .uId = vbNull
        .uFlags = 7
        .ucallbackMessage = 512 'On Mouse Move
        .hIcon = SysTrayForm.Icon
        .szTip = SysTrayForm.Caption + Chr(0)
    End With
    
    Shell_NotifyIcon 0, nic
    
    RunningInTray = True
End Sub

Public Sub RemoveIcon(SysTrayForm As Form)
    With nic
        .cbSize = Len(nic)
        .Hwnd = SysTrayForm.Hwnd
        .uId = vbNull
        .uFlags = 7
        .ucallbackMessage = vbNull
        .hIcon = SysTrayForm.Icon
        .szTip = Chr(0)
    End With
    Shell_NotifyIcon 2, nic
    If SysTrayForm.Visible = False Then SysTrayForm.Show    'Incase user can't see form
    
    RunningInTray = False
End Sub

Public Sub ChangeIcon(SysTrayForm As Form, picNewIcon As PictureBox)
    If RunningInTray = True Then   'If running in the tray
        With nic
            .cbSize = Len(nic)
            .Hwnd = SysTrayForm.Hwnd
            .hIcon = picNewIcon.Picture
        End With
        Shell_NotifyIcon 1, nic
    End If
End Sub

Public Sub RestoreIcon(SysTrayForm As Form)
    If RunningInTray = True Then   'If running in the tray
        With nic
            .cbSize = Len(nic)
            .Hwnd = SysTrayForm.Hwnd
            .hIcon = SysTrayForm.Icon
        End With
        Shell_NotifyIcon 1, nic
    End If
End Sub
Public Sub ChangeToolTip(SysTrayForm As Form, strNewTip As String)
    If RunningInTray = True Then   'If running in the tray
        With nic
            .cbSize = Len(nic)
            .Hwnd = SysTrayForm.Hwnd
            .szTip = strNewTip & Chr(0)
        End With
        Shell_NotifyIcon 1, nic
    End If
End Sub


</font>

History

  • v1.1 (16/February/2006)
    First release

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

parinit
Web Developer
India India
No Biography provided

Comments and Discussions

 
Generalparanit email Pinmemberronpeed27-Jun-08 17:31 
what's your email?

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 15 Feb 2006
Article Copyright 2006 by parinit
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid