'user defined type required by Shell_NotifyIcon API call
      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



      'constants required by Shell_NotifyIcon API call:
      Public Const NIM_ADD = &H0
      Public Const NIM_MODIFY = &H1
      Public Const NIM_DELETE = &H2
      Public Const NIF_MESSAGE = &H1
      Public Const NIF_ICON = &H2
      Public Const NIF_TIP = &H4
      Public Const WM_MOUSEMOVE = &H200
      Public Const WM_LBUTTONDOWN = &H201     'Button down
      Public Const WM_LBUTTONUP = &H202       'Button up
      Public Const WM_LBUTTONDBLCLK = &H203   'Double-click
      Public Const WM_RBUTTONDOWN = &H204     'Button down
      Public Const WM_RBUTTONUP = &H205       'Button up
      Public Const WM_RBUTTONDBLCLK = &H206   'Double-click

      Public Declare Function SetForegroundWindow Lib "user32" _
      (ByVal hwnd As Long) As Long
      Public Declare Function Shell_NotifyIcon Lib "shell32" _
      Alias "Shell_NotifyIconA" _
      (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean

      Public nid As NOTIFYICONDATA




Declare Function SetFocusAPI Lib "user32" Alias "SetForegroundWindow" (ByVal hwnd As Long) As Long
Private Declare Function EnumWindows& Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long)
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function IsWindowVisible& Lib "user32" (ByVal hwnd As Long)
Private Declare Function GetParent& Lib "user32" (ByVal hwnd As Long)

Dim sPattern As String, hFind As Long



Function EnumWinProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
  Dim k As Long, sName As String
  hFind = 0
  If IsWindowVisible(hwnd) And GetParent(hwnd) = 0 Then
     sName = Space$(128)
     k = GetWindowText(hwnd, sName, 128)
     If k > 0 Then
        sName = Left$(sName, k)
        If lParam = 0 Then sName = UCase(sName)
        If sName Like sPattern Then
           hFind = hwnd
           EnumWinProc = 0
           Exit Function
        End If
     End If
  End If
  EnumWinProc = 1
End Function

Public Function FindWindowWild(sWild As String, Optional bMatchCase As Boolean = True) As Long
  sPattern = sWild
  If Not bMatchCase Then sPattern = UCase(sPattern)
  EnumWindows AddressOf EnumWinProc, bMatchCase
  FindWindowWild = hFind
End Function