Add Icon To The Sys Tray

'Add a module to your project (In the menu choose Project -> Add Module, Then click Open)
'Add 4 CommandButtons to your form, And 2 PictureBoxes. Add 2 Icons (ICO Files) to
'the Picture Boxes. The icon in Picture1 will be the icon when enabled, and the icon in
'Picture2 will be the icon when disabled. Set the Picture Boxes AutoSize Property to True.
'The form caption will display mouse activity.
'Insert this code to the module :

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 Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" _
(ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Global TaskIcon As NOTIFYICONDATA
Global Const NIM_ADD = &H0
Global Const NIM_MODIFY = &H1
Global Const NIM_DELETE = &H2
Global Const NIF_MESSAGE = &H1
Global Const NIF_ICON = &H2
Global Const NIF_TIP = &H4
Global Const WM_MOUSEMOVE = &H200

'Insert the following code to your form:

Private Sub LoadIconToTaskBar()
TaskIcon.cbSize = Len(TaskIcon)
TaskIcon.hwnd = Picture1.hwnd
TaskIcon.uID = 1&
TaskIcon.uFlags = NIF_MESSAGE Or NIF_ICON Or NIF_TIP
TaskIcon.uCallbackMessage = WM_MOUSEMOVE
TaskIcon.hIcon = Picture1.Picture
'Replace 'My ToolTip Text' with the ToolTip Text to show when icon is loaded.
TaskIcon.szTip = "My ToolTip Text" & Chr$(0)
Shell_NotifyIcon NIM_ADD, TaskIcon
End Sub
Private Sub EnableTaskBarIcon()
TaskIcon.hIcon = Picture1.Picture
'Replace 'Enabled Tool Tip' with the ToolTip Text to show when icon is enabled.
TaskIcon.szTip = "Enabled Tool Tip" & Chr$(0)
Shell_NotifyIcon NIM_MODIFY, TaskIcon
End Sub
Private Sub DisableTaskBarIcon()
TaskIcon.hIcon = Picture2.Picture
'Replace 'Disabled Tool Tip' with the ToolTip Text to show when icon is disabled.
TaskIcon.szTip = "Disabled Tool Tip" & Chr$(0)
Shell_NotifyIcon NIM_MODIFY, TaskIcon
End Sub
Private Sub RemoveIconFromTaskBar()
Shell_NotifyIcon NIM_DELETE, TaskIcon
End Sub

Private Sub Command1_Click()
LoadIconToTaskBar
End Sub

Private Sub Command2_Click()
DisableTaskBarIcon
End Sub

Private Sub Command3_Click()
EnableTaskBarIcon
End Sub

Private Sub Command4_Click()
RemoveIconFromTaskBar
End Sub

Private Sub Form_Load()
Command1.Caption = "Load Icon To Task Bar"
Command2.Caption = "Disable Icon"
Command3.Caption = "Enable Icon"
Command4.Caption = "Unload Icon"
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, x As _
Single, Y As Single)
If Hex(x) = "1800" Then Me.Caption = "mouse move"
If Hex(x) = "1824" Then Me.Caption = "double click"
If Hex(x) = "1830" Then Me.Caption = "right click"
If Hex(x) = "180C" Then Me.Caption = "left click"
End Sub

Go Back