' This class came from another project. The remarks may or may not pertain to this project
' almost all of this class from http://vbnet.mvps.org/index.html?code/subclass/shellnotifystructinfo.htm
' added additional routines & modified a couple so they can be used generically
' and also to allow multiple icons per hWnd
' This class will allow you to modify system tray icons for your application
' Any hWnd can have a tray icon. All icons you assign to the tray icons are your
' responsibility for destroying when appropriate. Only top level windows should
' be installing tray icons. This is because should Explorer crash & then
' restart & new taskbar created, the message we look for to restore the icons
' on the new taskbar is only sent to top level windows.
' This class can be setup in your routines at any time and can be deactivated at
' any time, destroyed, or activated any time after the hWnd has begun subclassing.
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long, ByRef lpRect As RECT) As Long
Private Declare Function IsIconic Lib "user32.dll" (ByVal hwnd As Long) As Long
Private Declare Function DrawAnimatedRects Lib "user32.dll" (ByVal hwnd As Long, ByVal idAni As Long, ByRef lprcFrom As RECT, ByRef lprcTo As RECT) As Long
Private Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function LockWindowUpdate Lib "user32.dll" (ByVal hwndLock As Long) As Long
Private Declare Function MoveWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" _
(ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Private Declare Function GetFileVersionInfoSize Lib "Version.dll" Alias "GetFileVersionInfoSizeA" _
(ByVal lptstrFilename As String, lpdwHandle As Long) As Long
Private Declare Function GetFileVersionInfo Lib "Version.dll" Alias "GetFileVersionInfoA" _
(ByVal lptstrFilename As String, ByVal dwhandle As Long, ByVal dwlen As Long, lpData As Any) As Long
Private Declare Function VerQueryValue Lib "Version.dll" Alias "VerQueryValueA" (pBlock As Any, _
ByVal lpSubBlock As String, lpBuffer As Any, nVerSize As Long) As Long
'Private Type GUID
' Data1 As Long
' Data2 As Integer
' Data3 As Integer
' Data4(7) As Byte
'End Type
Private Type NOTIFYICONDATA
cbSize As Long
hwnd As Long
uID As Long
uFlags As Long
uCallbackMessage As Long
hIcon As Long
szTip As String * 128 'shell 5+ <> 64 chars max for shell <5
dwState As Long 'shell 5+ <> not used in this class
dwStateMask As Long 'shell 5+
szInfo As String * 256 'shell 5+
uTimeoutAndVersion As Long 'shell 5+
szInfoTitle As String * 64 'shell 5+
dwInfoFlags As Long 'shell 5+
guidItem(15) As Byte ' GUID shell 6+ <> reserved by Windows
End Type
' tray update commands
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
' tray update masks
Private Const NIF_MESSAGE = &H1
Private Const NIF_INFO As Long = &H10
Private Const NIF_ICON = &H2
Private Const NIF_STATE As Long = &H8
Private Const NIF_TIP = &H4
Private Const NIS_HIDDEN = &H1
'balloon tip notification messages <> not used here; for ref only