Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hWnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Private Declare Function GetTickCount& Lib "kernel32" ()
Private Sub Title(What As String) 'Sets the caption of the window to "Chat [What]"
Me.Caption = "MHX Homework Helper - Live Help [" & What & "]"
End Sub
Private Sub AddText(Who, WhatText) 'Adds text to the chat-window
txtChat.Text = txtChat.Text & "-=" & Who & "=-" & vbCrLf 'First the name of the user
txtChat.Text = txtChat.Text & WhatText & vbCrLf 'And then the text
txtChat.SelStart = Len(txtChat.Text) 'Roll the window when text doesn't fit.
End Sub
Private Sub Command1_Click()
Chat.Hide
frmHomeworkMain.Show
End Sub
Private Sub con_Click() 'Connect button
Dim Server As String
Server = InputBox("Please write IP or HostName.", "Connect", "LocalHost")
sock.Close 'Close it before trying to connect, in case it's already connected.
sock.Connect Server, 8765
End Sub
Private Sub Form_Load()
Title "Disconnected"
Dim i As Long
For i = 0 To Screen.FontCount - 1
Combo1.AddItem Screen.Fonts(i)
Next i
Combo1.ListIndex = 0
txtOut.Font =
End Sub
Private Sub Image1_Click()
ShellExecute Me.hWnd, "open", "http://www.geocities.com/nitrogenocide2003/MHXDonate.html", vbNullString, vbNullString, ByVal 1&
End Sub
Private Sub sock_Close()
Title "Disconnected"
End Sub
Private Sub sock_Connect()
Dim msg As String
Title "Connected"
DoEvents 'Without the DoEvents sock will not send the data because sock haven't
msg = "name|" & txtName.Text 'connected yet.
sock.SendData msg 'Send our name.
Chat.Label3.Caption = "ONLINE"
End Sub
Private Sub sock_DataArrival(ByVal bytesTotal As Long) 'When someone sends us data.
Dim GetIt As String
sock.GetData GetIt
msg = Split(GetIt, "|")
Select Case msg(0)
Case "cons" 'Server sends us the list of connected users.
List.Clear
For i = 1 To UBound(msg) - 1
List.AddItem msg(i)
Next i
Case "text" 'Server sends us text, transfered from some other user.
AddText msg(1), msg(2)
End Select
End Sub
Private Sub txtOut_KeyDown(KeyCode As Integer, Shift As Integer) 'When pressed enter, send the text.
If KeyCode = 13 Then
AddText txtName.Text, txtOut.Text
sock.SendData "text|" & txtOut.Text
txtOut.Text = ""
End If
End Sub