Attribute VB_Name = "Modulec1"
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Declare Function GetMenu Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
Public Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Public Declare Function GetMenuString Lib "user32" Alias "GetMenuStringA" (ByVal hMenu As Long, ByVal wIDItem As Long, ByVal lpString As String, ByVal nMaxCount As Long, ByVal wFlag As Long) As Long
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Public Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
Public Declare Function GetWindowThreadProcessID Lib "user32" Alias "GetWindowThreadProcessId" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
Public Declare Function IsWindowVisible Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Public Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Long, ByVal lpBuffer As String, ByVal nSize As Long, ByRef lpNumberOfBytesWritten As Long) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function SendMessageLong& Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)
Public Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Public Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Public Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hwndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Public Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As Long
Public Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Public Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Public Declare Function ReleaseCapture Lib "user32" () As Long
Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Public Declare Function EnableWindow Lib "user32" (ByVal hWnd As Long, ByVal cmd As Long) As Long
Public Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long
Public Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long
Declare Function sendmessagebynum& Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)
Public Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
Public Declare Function IsWindow Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function iswindowenabled Lib "user32" Alias "IsWindowEnabled" (ByVal hWnd As Long) As Long
Public Type POINTAPI
        X As Long
        Y As Long
End Type
Public Const BM_GETCHECK = &HF0
Public Const BM_SETCHECK = &HF1
Public Const HWND_NOTOPMOST = -2
Public Const HWND_TOPMOST = -1
Public Const LB_GETCOUNT = &H18B
Public Const LB_GETITEMDATA = &H199
Public Const LB_GETTEXT = &H189
Public Const LB_GETTEXTLEN = &H18A
Public Const LB_SETCURSEL = &H186
Public Const LB_SETSEL = &H185
Public Const SND_ASYNC = &H1
Public Const SND_NODEFAULT = &H2
Public Const SND_FLAG = SND_ASYNC Or SND_NODEFAULT
Public Const SW_HIDE = 0
Public Const SW_SHOW = 5
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const VK_DOWN = &H28
Public Const VK_LEFT = &H25
Public Const VK_MENU = &H12
Public Const VK_RETURN = &HD
Public Const VK_RIGHT = &H27
Public Const VK_SHIFT = &H10
Public Const VK_SPACE = &H20
Public Const VK_UP = &H26
Public Const WM_CHAR = &H102
Public Const WM_CLOSE = &H10
Public Const WM_COMMAND = &H111
Public Const WM_GETTEXT = &HD
Public Const WM_GETTEXTLENGTH = &HE
Public Const WM_KEYDOWN = &H100
Public Const WM_KEYUP = &H101
Public Const WM_LBUTTONDBLCLK = &H203
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const WM_MOVE = &HF012
Public Const WM_SETTEXT = &HC
Public Const WM_SYSCOMMAND = &H112
Public Const PROCESS_READ = &H10
Public Const RIGHTS_REQUIRED = &HF0000
Public Const ENTER_KEY = 13
Public Const Flags = SWP_NOMOVE Or SWP_NOSIZE

Public Function ChildInstance(ParentWindow As Long) As Long
     Dim OnInstance As Long, CurrentCount As Long
     If IsWindow(ParentWindow&) = 0& Then Exit Function
     OnInstance& = GetWindow(ParentWindow&, 5)
     If OnInstance& <> 0& Then ChildInstance& = 1
     Do: DoEvents
         OnInstance& = GetWindow(OnInstance&, 2)
         If OnInstance& <> 0& Then CurrentCount& = CurrentCount& + 1
     Loop Until OnInstance& = 0&
     ChildInstance& = CurrentCount& + 1
End Function

Public Function ClassInstance(ParentWindow As Long, ClassWindow As String) As Long
     Dim OnInstance As Long, CurrentCount As Long
     If FindWindowEx(ParentWindow&, 0&, ClassWindow$, vbNullString) = 0& Then Exit Function
     ClassInstance& = 0&
     Do: DoEvents
         OnInstance& = FindWindowEx(ParentWindow&, OnInstance&, ClassWindow$, vbNullString)
         If OnInstance& <> 0& Then
             CurrentCount& = CurrentCount& + 1
            Else
             Exit Do
         End If
     Loop
     ClassInstance& = CurrentCount&
End Function

Public Function FindChildByClass(ParentWindow As Long, ClassWindow As String) As Long
    FindChildByClass& = FindWindowEx(ParentWindow&, 0&, ClassWindow$, vbNullString)
End Function
Public Function Findchildbytitle(ParentWindow As Long, WindowText As String) As Long
    Dim GetChild As Long, GetNextChild As Long, PrepLong As Long
    GetChild& = GetWindow(ParentWindow&, 5)
    If UCase(GetCaption(GetChild&)) Like UCase(WindowText$) Then Findchildbytitle& = GetChild&
    GetChild& = GetWindow(ParentWindow&, 5)
    While ParentWindow&
        GetNextChild& = GetWindow(ParentWindow&, 5)
        If UCase(GetCaption(GetNextChild&)) Like UCase(WindowText$) & "*" Then Findchildbytitle& = GetChild&
           GetChild& = GetWindow(ParentWindow&, 5)
        If UCase(GetCaption(GetChild&)) Like UCase(WindowText$) & "*" Then Findchildbytitle& = GetChild&
    Wend
    Findchildbytitle& = 0&
End Function
Public Function FindChildByTitleEx(ParentWindow As Long, WindowText As String) As Long
    FindChildByTitleEx& = FindWindowEx(ParentWindow&, 0&, vbNullString, WindowText$)
End Function

Public Function GetCaption(WinHandle As Long) As String
    Dim Buffer As String, TextLen As Long
    TextLen& = GetWindowTextLength(WinHandle&)
    Buffer$ = String(TextLen&, 0&)
    Call GetWindowText(WinHandle&, Buffer$, TextLen& + 1)
    GetCaption$ = Buffer$
End Function
Public Function NextOfClassByCount(ParentWindow As Long, ClassWindow As String, ByCount As Long) As Long
    Dim NextOfClass As Long, NextWindow As Long
    If ByCount& > ClassInstance(ParentWindow&, ClassWindow$) Then Exit Function
    If FindWindowEx(ParentWindow&, 0&, ClassWindow$, vbNullString) = 0& Then Exit Function
    For NextOfClass& = 1 To ByCount&
        NextWindow& = FindWindowEx(ParentWindow&, NextWindow&, ClassWindow$, vbNullString)
    Next NextOfClass&
    NextOfClassByCount& = NextWindow&
End Function
Public Sub RunMenuByString(ParentWindow As Long, StringToGet As String)
    Dim MenuHandle As Long, MenuItemCount As Long, NextItem As Long
    Dim SubMenu As Long, NextMenuItemCount As Long, MenuItemId As Long
    Dim NextNextItem As Long, NextMenuItemId As Long, FixedString As String
    MenuHandle& = GetMenu(ParentWindow&)
    MenuItemCount& = GetMenuItemCount(MenuHandle&)
    For NextItem& = 0& To MenuItemCount& - 1
        SubMenu& = GetSubMenu(MenuHandle&, NextItem&)
        NextMenuItemCount& = GetMenuItemCount(SubMenu&)
        For NextNextItem& = 0& To NextMenuItemCount& - 1
             NextMenuItemId& = GetMenuItemID(SubMenu&, NextNextItem&)
             FixedString$ = String(100, " ")
             Call GetMenuString(SubMenu&, NextMenuItemId&, FixedString$, 100, 1)
             If InStr(LCase(FixedString$), LCase(StringToGet$)) Then
                  Call SendMessageLong(ParentWindow&, WM_COMMAND, NextMenuItemId&, 0&)
                  Exit Sub
             End If
        Next NextNextItem&
    Next NextItem&
End Sub
Public Sub WaitForWindowByClass(ParentWindow As Long, ClassWindow As String)
    Dim FindThisWindow As Long
    Do: DoEvents
        FindThisWindow& = FindChildByClass(ParentWindow&, ClassWindow$)
    Loop Until FindThisWindow& <> 0&
End Sub

Public Sub WaitForWindowByTitle(ParentWindow As Long, WindowText As String)
    Dim FindThisWindow As Long
    Do: DoEvents
        FindThisWindow& = Findchildbytitle(ParentWindow&, WindowText$)
    Loop Until FindThisWindow& <> 0&
End Sub

Public Sub Chat_Hide()
ZoneClient& = FindWindow("ZoneLobbyWindow", vbNullString)
Call ShowWindow(ZoneClient&, SW_HIDE)
End Sub

Function Chat_Show()
ZoneClient& = FindWindow("ZoneLobbyWindow", vbNullString)
Call ShowWindow(ZoneClient&, SW_SHOW)
End Function

Public Sub Chat_Close()
ZoneClient& = FindWindow("ZoneLobbyWindow", vbNullString)
Call SendMessage(ZoneClient&, WM_CLOSE, 0&, 0&)
End Sub

Sub Chat_Invite()
ZoneClient& = FindWindow("Zonelobbywindow", vbNullString)
RunMenuByString ZoneClient&, "Invite"
End Sub

Sub SHR_DontAsk()
ZoneClient& = FindWindow("Zonelobbywindow", vbNullString)
RunMenuByString ZoneClient&, "Don't Ask Question"
End Sub

Sub SHR_Ask()
ZoneClient& = FindWindow("Zonelobbywindow", vbNullString)
RunMenuByString ZoneClient&, "Ask Question"
End Sub
