Attribute VB_Name = "Module1"
Declare Function SetSysModalWindow Lib "User32" (ByVal hWnd As Integer) As Integer
Declare Sub SetWindowText Lib "User32" Alias "SetWindowTextA" (ByVal hWnd As Integer, ByVal lpString As String)
Declare Function GetWindowTextLength Lib "User32" Alias "GetWindowTextLengthA" (ByVal hWnd%) As Integer
Declare Function GetWindow Lib "User32" (ByVal hWnd As Integer, ByVal wCmd As Integer) As Integer
Declare Function GetWindowText Lib "User32" Alias "GetWindowTextA" (ByVal hWnd%, ByVal lpSting$, ByVal nMaxCount%) As Integer
Declare Function Shell_NotifyIcon& Lib "shell32.DLL" (ByVal lMessage&, NID As NOTIFYICONDATA)
Declare Function SHAppBarMessage& Lib "shell32.DLL" (ByVal dwMessage&, pData As APPBARDATA)
Declare Function FindWindow% Lib "User32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpCaption As Any)
Declare Function SendMessage& Lib "User32" Alias "SendMessageA" (ByVal hWnd%, ByVal wMsg%, ByVal wParam%, ByVal lParam As Long)
Declare Function ShowWindow Lib "User32" (ByVal hWnd As Integer, ByVal nCmdShow As Integer) As Integer


Type NOTIFYICONDATA
    lStructureSize    As Long
    hWnd   As Long
    lID As Long
    lFlags As Long
    lCallBackMessage As Long
    hIcon As Long
    sTip As String * 64
End Type

Type lRect
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

Type APPBARDATA
    lStructureSize As Long
    hWnd As Long
    lCallBackMessage As Long
    lEdge As Long
    rc As lRect
    lParam As Long
End Type



Global idShell_NotifyIcon&
Global idSHAppBarMessage&

Global Const NIM_ADD = 0&
Global Const NIM_DELETE = 2&
Global Const NIM_MODIFY = 1&
Global Const NIF_ICON = 2&
Global Const NIF_MESSAGE = 1&
Global Const NIF_TIP = 4&

Global Const ABM_GETTASKBARPOS = &H5&

Global structNotify As NOTIFYICONDATA
Global structBarData As APPBARDATA

'Message blaster callback stuff
Const WM_USER = &H400
Global Const UM_TASKBARMESSAGE = WM_USER + &H201
Global Const POSTPROCESS = 1

Function GetWindowHwnd(cp$)
GetWindowHwnd = FindWindow(0&, cp$)
End Function
Sub SetWindowsText(Hwndr As Variant, t$)
SetWindowText Hwndr, t$

End Sub
Sub CloseProgram(Hwndr)
X& = SendMessage(Hwndr, &H112, &HF060, 0&)
End Sub


Sub ShowWindows(Hwndr, ToF)
If ToF Then s = ShowWindow(Hwndr, 1) Else s = ShowWindow(Hwndr, 0)
End Sub
Sub LoadTaskList(Where As ListBox)
Where.Clear
CurrWnd = GetWindow(Where.Parent.hWnd, 0)
While CurrWnd <> 0
    Length = GetWindowTextLength(CurrWnd)
    ListItem$ = Space$(Length + 1)
    Length = GetWindowText(CurrWnd, ListItem$, Length + 1)
    If Length > 0 Then
            Where.AddItem ListItem$
    End If
    CurrWnd = GetWindow(CurrWnd, 2)
    X = DoEvents()
Wend
End Sub
Sub AddIcon(FormObject As Form, Icon As Variant, Tip$, MsgHk1 As Msghook)

Dim ltemplong As Long
    
'Make sure the Explorer shell is running. If not, we can't use the taskbar
    structBarData.lStructureSize = 36&
    ltemplong = SHAppBarMessage(ABM_GETTASKBARPOS, structBarData)
    If ltemplong <> 1 Then
        Exit Sub
    End If
    
'Set up the data structure for the Shell_NotifyIcon function
    structNotify.lStructureSize = 88&
    structNotify.hWnd = FormObject.hWnd
    structNotify.lID = 0&
    structNotify.lFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
    structNotify.lCallBackMessage = UM_TASKBARMESSAGE
    structNotify.hIcon = Icon
    structNotify.sTip = Tip$ & Chr$(0)
    ltemplong = Shell_NotifyIcon(NIM_ADD, structNotify)
    
'Setup the message blaster to call us when we
'get a message from the shell notify icon
 MsgHk1.HwndHook = FormObject.hWnd
 MsgHk1.Message(UM_TASKBARMESSAGE) = True
End Sub
Sub DeleteIcon(FormObject As Form, MsgHk1 As Msghook)

Dim ltemplong As Long
    
'Make sure the Explorer shell is running. If not, we can't use the taskbar
    structBarData.lStructureSize = 36&
    ltemplong = SHAppBarMessage(ABM_GETTASKBARPOS, structBarData)
    If ltemplong <> 1 Then
        Exit Sub
    End If
    
'Set up the data structure for the Shell_NotifyIcon function
    ltemplong = Shell_NotifyIcon(NIM_DELETE, structNotify)
    
'Setup the message blaster to call us when we
'get a message from the shell notify icon
' MsgHk1.HwndHook = FormObject.hWnd
' MsgHk1.Message(UM_TASKBARMESSAGE) = False
End Sub

