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
<p>Const WM_RBUTTONDBLCLK = &H206</p>
<p>Const WM_MBUTTONDBLCLK = &H209</p>
| Occurs when the user clicks the icon in the status area. |
Const WM_LBUTTONDOWN = &H201
<p>Const WM_RBUTTONDOWN = &H204</p>
<p>Const WM_MBUTTONDOWN = &H207</p>
| 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<br>
<br>
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
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.