VERSION 5.00
Begin VB.UserControl SysTray 
   ClientHeight    =   1710
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   720
   InvisibleAtRuntime=   -1  'True
   MousePointer    =   2  'Cross
   ScaleHeight     =   1710
   ScaleWidth      =   720
   ToolboxBitmap   =   "Systray.ctx":0000
   Begin VB.PictureBox Picture1 
      Height          =   495
      Left            =   120
      Picture         =   "Systray.ctx":0312
      ScaleHeight     =   435
      ScaleWidth      =   315
      TabIndex        =   1
      Top             =   600
      Visible         =   0   'False
      Width           =   375
   End
   Begin VB.Timer Timer1 
      Enabled         =   0   'False
      Left            =   240
      Top             =   0
   End
   Begin VB.Label lbl1 
      Caption         =   "System Tray Icon"
      Height          =   495
      Left            =   0
      TabIndex        =   0
      Top             =   0
      Width           =   735
   End
End
Attribute VB_Name = "SysTray"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Private Const WM_LBUTTONDBLCLK = &H203
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
Private Const WM_RBUTTONDBLCLK = &H206
Private Const WM_RBUTTONDOWN = &H204
Private Const WM_RBUTTONUP = &H205

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

Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
Private Const WM_MOUSEMOVE = &H200
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4

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

Private TrayIcon        As NOTIFYICONDATA
Private IconVis As Boolean
Public IsBlinking As Boolean
Public BlinkDelay As Long
Public IconIsOn        As Boolean
Public SysTrayIcon As Object
Public SysTrayText As String
Public Event TrayClick(Buttons As Boolean)
Public Sub Blink()
If IconIsOn = False Then Exit Sub
If IsBlinking = True Then
    IconVis = True
    Update True
    Timer1.Enabled = False
    IsBlinking = False
    Exit Sub
End If
IconVis = True: IsBlinking = True
Timer1.Interval = BlinkDelay
Timer1.Enabled = True
End Sub
Public Sub Update(IconOn As Boolean)
   If IconOn Then
      TrayIcon.cbSize = Len(TrayIcon)
      TrayIcon.hwnd = UserControl.hwnd
      TrayIcon.uId = 1&
            TrayIcon.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
      If SysTrayText <> "" Then
         TrayIcon.uFlags = TrayIcon.uFlags Or NIF_TIP
      End If
      TrayIcon.ucallbackMessage = WM_MOUSEMOVE
      TrayIcon.hIcon = SysTrayIcon
      If IconVis = False Then TrayIcon.hIcon = UserControl.Picture1.Picture
      TrayIcon.szTip = SysTrayText & Chr(0)
      If Not IconIsOn Then
         Shell_NotifyIcon NIM_ADD, TrayIcon
      Else
         Shell_NotifyIcon NIM_MODIFY, TrayIcon
      End If
      IconIsOn = True
   Else
      If IconIsOn Then
         TrayIcon.cbSize = Len(TrayIcon)
         TrayIcon.hwnd = UserControl.hwnd
         TrayIcon.uId = 1&
         Shell_NotifyIcon NIM_DELETE, TrayIcon
      End If
      IconIsOn = False
   End If
End Sub

Private Sub Timer1_Timer()
If IconVis = True Then IconVis = False Else IconVis = True
Update True
End Sub

Private Sub UserControl_Initialize()
IconIsOn = False
Timer1.Enabled = False
IconVis = True
End Sub


Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, y As Single)
Dim i As Byte, i1 As Long
    Static rec As Boolean, msg As Long
    msg = X / Screen.TwipsPerPixelX
    If rec = False Then
        rec = True
        On Error Resume Next
           If msg = WM_LBUTTONDOWN Then RaiseEvent TrayClick(True)
           If msg = WM_RBUTTONDOWN Then RaiseEvent TrayClick(False)
        rec = False
    End If
End Sub

Private Sub UserControl_Terminate()
Update False
End Sub
