Attribute VB_Name = "FirstZone"
Option Explicit
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 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 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 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 Const VK_SPACE = &H20
Public Const WM_SETTEXT = &HC
Public Const WM_KEYDOWN = &H100
Public Const WM_GETTEXT = &HD
Public Const WM_GETTEXTLENGTH = &HE
Public Const WM_KEYUP = &H101

Public Function LastChatLine() As String
Dim ctext As String, fchar As Long, tchar As String, tchars As String
Dim ttext As String, llen As Long, chatline As String
Dim ZoneLobbyWindow As Long, WindowManager As Long, atlaxwin As Long
Dim chatcontrol As Long, richedita As Long
ZoneLobbyWindow = FindWindow("zonelobbywindow", vbNullString)
atlaxwin = FindWindowEx(ZoneLobbyWindow, 0&, "atlaxwin", vbNullString)
WindowManager = FindWindowEx(atlaxwin, 0&, "windowmanager", vbNullString)
atlaxwin = FindWindowEx(WindowManager, 0&, "atlaxwin", vbNullString)
atlaxwin = FindWindowEx(WindowManager, atlaxwin, "atlaxwin", vbNullString)
atlaxwin = FindWindowEx(WindowManager, atlaxwin, "atlaxwin", vbNullString)
atlaxwin = FindWindowEx(WindowManager, atlaxwin, "atlaxwin", vbNullString)
atlaxwin = FindWindowEx(WindowManager, atlaxwin, "atlaxwin", vbNullString)
chatcontrol = FindWindowEx(atlaxwin, 0&, "chatcontrol", vbNullString)
richedita = FindWindowEx(chatcontrol, 0&, "richedit20a", vbNullString)
ctext$ = GetText(richedita)
    For fchar& = 1 To Len(ctext$)
      tchar$ = Mid(ctext$, fchar&, 1&)
      tchars$ = tchars$ & tchar$
      If tchar$ = Chr$(13) Then
        ttext$ = Mid(tchars$, 1, Len(tchars$) - 1)
        tchars$ = ""
      End If
    Next fchar&
    llen& = Val(fchar&) - Len(tchars$)
  chatline$ = Mid$(ctext$, llen&, Len(tchars$))
  LastChatLine = chatline$
End Function

Public Function Lobbysend(ChatMessage As String)

Dim ZoneLobbyWindow As Long, atlaxwin As Long, WindowManager As Long, chatcontrol As Long, RichEdit20A As Long, zrolloverbutton As Long

ZoneLobbyWindow& = FindWindow("ZoneLobbyWindow", vbNullString)


atlaxwin& = FindWindowEx(ZoneLobbyWindow&, 0&, "AtlAxWin", vbNullString)
WindowManager& = FindWindowEx(atlaxwin&, 0&, "WindowManager", vbNullString)
atlaxwin& = FindWindowEx(WindowManager&, 0&, "AtlAxWin", vbNullString)
atlaxwin& = FindWindowEx(WindowManager&, atlaxwin&, "AtlAxWin", vbNullString)
atlaxwin& = FindWindowEx(WindowManager&, atlaxwin&, "AtlAxWin", vbNullString)
atlaxwin& = FindWindowEx(WindowManager&, atlaxwin&, "AtlAxWin", vbNullString)
atlaxwin& = FindWindowEx(WindowManager&, atlaxwin&, "AtlAxWin", vbNullString)
chatcontrol& = FindWindowEx(atlaxwin&, 0&, "ChatControl", vbNullString)

RichEdit20A& = FindWindowEx(chatcontrol&, RichEdit20A&, "RichEdit20A", vbNullString)
RichEdit20A& = FindWindowEx(chatcontrol&, RichEdit20A&, "RichEdit20A", vbNullString)

SendMessageByString RichEdit20A&, WM_SETTEXT, 0&, ChatMessage$

zrolloverbutton& = FindWindowEx(chatcontrol&, 0&, "ZRolloverButton", vbNullString)

Call SendMessage(zrolloverbutton&, WM_KEYDOWN, VK_SPACE, 0&)
Call SendMessage(zrolloverbutton&, WM_KEYUP, VK_SPACE, 0&)

End Function

Public Function GetText(WindowHandle As Long) As String
    Dim Buffer As String, TextLength As Long
    TextLength& = SendMessage(WindowHandle&, WM_GETTEXTLENGTH, 0&, 0&)
    If TextLength > 64000 Then
        Exit Function
    End If
    Buffer$ = String(TextLength&, 0&)
    Call SendMessageByString(WindowHandle&, WM_GETTEXT, TextLength& + 1, Buffer$)
    GetText$ = Buffer$
End Function
Public Sub Gamesend(What As String)
Dim atldc As Long, atlaxwin As Long, chatcontrol As Long
Dim zrolloverbutton As Long, richedita As Long
atldc& = FindWindow("atl:600d85c8", vbNullString)
atlaxwin& = FindWindowEx(atldc, 0&, "atlaxwin", vbNullString)
atlaxwin& = FindWindowEx(atldc, atlaxwin, "atlaxwin", vbNullString)
chatcontrol& = FindWindowEx(atlaxwin, 0&, "chatcontrol", vbNullString)
zrolloverbutton& = FindWindowEx(chatcontrol, 0&, "zrolloverbutton", vbNullString)
richedita& = FindWindowEx(chatcontrol, 0&, "richedit20a", vbNullString)
richedita& = FindWindowEx(chatcontrol, richedita, "richedit20a", vbNullString)
SendMessageByString richedita&, WM_SETTEXT, 0&, What$
    Call SendMessage(zrolloverbutton&, WM_KEYDOWN, VK_SPACE, 0&)
    Call SendMessage(zrolloverbutton&, WM_KEYUP, VK_SPACE, 0&)
End Sub

