VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsSystemTray"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long

    Private Const NIM_ADD = &H0
    Private Const NIM_MODIFY = &H1
    Private Const NIM_DELETE = &H2
    Private Const NIF_MESSAGE = &H1
    Private Const NIF_ICON = &H2
    Private Const NIF_TIP = &H4
    Private Const WM_MOUSEMOVE = &H200
    Private Const WM_LBUTTONDOWN = &H201    'Button down
    Private Const WM_LBUTTONUP = &H202      'Button up
    Private Const WM_LBUTTONDBLCLK = &H203  'Double-click
    Private Const WM_RBUTTONDOWN = &H204    'Button down
    Private Const WM_RBUTTONUP = &H205      'Button up
    Private Const WM_RBUTTONDBLCLK = &H206  'Double-click
    Private Const EM_GETLINECOUNT = &HBA

    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 NID As NOTIFYICONDATA
    Private WithEvents frmWork As Form
Attribute frmWork.VB_VarHelpID = -1
Public Sub TrayIcon(frm As frmMain)
    Set frmWork = frm
    Shell_NotifyIcon NIM_DELETE, NID
    With NID
        .cbSize = Len(NID)
        .hwnd = frm.hwnd
        .uID = vbNull
        .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
       .uCallbackMessage = WM_MOUSEMOVE
        .hIcon = frm.Icon
        .szTip = frm.Caption & vbNullChar
    End With
    Shell_NotifyIcon NIM_ADD, NID
End Sub
Private Sub DeleteTrayIcon()
    Shell_NotifyIcon NIM_DELETE, NID
End Sub
Private Sub frmWork_Unload(Cancel As Integer)
    DeleteTrayIcon
End Sub
Private Sub frmWork_MouseMove(button As Integer, Shift As Integer, X As Single, Y As Single)
    Static Message As Long
    Message = X / Screen.TwipsPerPixelX
    Select Case Message
        Case WM_LBUTTONDBLCLK
          frmWork.WindowState = vbNormal
          frmWork.Show
       Case WM_RBUTTONDOWN
          frmWork.WindowState = vbNormal
          frmWork.Show
    End Select
End Sub
Private Sub frmWork_Resize()
    If frmWork.WindowState = vbMinimized Then
        TrayIcon frmMain
        frmWork.Hide
    Else
        TrayIcon frmMain
        frmWork.Show
    End If
End Sub
