Option Explicit
Dim tmpData
Dim tmpData1
Dim tmpData2
Dim tmpData3
Dim strMSGrcvd ' message received
Dim imtrialid ' trial id of the message
Dim blnconnected As Boolean ' check if connected to m server
Private Sub cmdSend_Click()
If cmdClose.Tag = "hotmail" Then
Dim strbldmsg As String
Dim strmessage As String
strbldmsg = "MIME-Version: 1.0" & vbCrLf & "Content-Type: text/plain; charset=UTF-8" & vbCrLf & "X-MMS-IM-Format: FN=MS%20Shell%20Dlg; EF=; CO=0; CS=0; PF=0" & vbCrLf & vbCrLf & rtbIMsend.Text ' build the message string
strmessage = "MSG " & imtrialid & " N " & Len(strbldmsg) & vbCrLf & strbldmsg ' send message to buddy
imtrialid = imtrialid + 1
wnsckMSNim.SendData strmessage
rtbIMchat.Text = rtbIMchat.Text & vbCrLf & txtIMto.Text & " : " & rtbIMsend.Text ' add message to the chat window
rtbIMsend.Text = ""
rtbIMchat.SelStart = Len(rtbIMchat)
End If
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub Form_load()
If blnconnected = False Then
If cmdClose.Tag = "hotmail" Then
cmdIgnore.Visible = False
cmdSend.Enabled = False
End If
blnconnected = True
End If
imtrialid = 1
End Sub
Private Sub wnsckMSNim_Close()
Unload Me
End Sub
Private Sub wnsckMSNim_Connect()
StatusBar1.Panels(1).Text = "INITIALIZING CONTACT" ' start connecting to im server
If cmdClose.Tag = "hotmail" Then
If cmdIgnore.Tag = "called" Then ' check if user started im conversation or buddy
wnsckMSNim.SendData "USR " & imtrialid & " " & frmMSN.txtUsername.Text & " " & txtCKIid.Text & vbCrLf
imtrialid = imtrialid + 1
Exit Sub
End If
wnsckMSNim.SendData "ANS " & imtrialid & " " & frmMSN.txtUsername.Text & " " & txtCKIid.Text & " " & txtSid.Text & vbCrLf ' reply to a im chat request
imtrialid = imtrialid + 1
End If
End Sub
Private Sub wnsckMSNim_DataArrival(ByVal bytesTotal As Long)
Dim blnTYp ' check if message is user typing a message
If cmdClose.Tag = "hotmail" Then
Dim strIMData As String
wnsckMSNim.GetData strIMData
If InStr(strIMData, "JOI") Then ' check if buddy has joined im chat
cmdSend.Enabled = True
StatusBar1.Panels(1).Text = " Contacted "
End If
If InStr(strIMData, "USR") Then
wnsckMSNim.SendData "CAL " & imtrialid & " " & cmdSend.Tag & vbCrLf ' call the buddy to an im chat room
imtrialid = imtrialid + 1
cmdIgnore.Tag = ""
End If
Debug.Print "im " & strIMData
If InStr(strIMData, "MSG") Then ' check if buddy sent a message
tmpData = InStr(strIMData, "text/plain")
If InStr(strIMData, "text/x-msmsgsinvite") Then
'file transfer
End If
If tmpData = 0 Then StatusBar1.Panels(1).Text = txtIMfrom.Text & " is typing a message"
If tmpData > 0 Then
StatusBar1.Panels(1).Text = ""
Do While InStr(strIMData, vbCrLf & vbCrLf)
tmpData1 = InStr(strIMData, vbCrLf & vbCrLf)
strMSGrcvd = Right(strIMData, Len(strIMData) - tmpData1 - 3)
If InStr(strMSGrcvd, "MSG") Then
If InStr(strMSGrcvd, "MIME-") Then
tmpData1 = InStr(strMSGrcvd, vbCrLf & vbCrLf)
strMSGrcvd = Right(strMSGrcvd, Len(strMSGrcvd) - tmpData1 - 3)
End If
End If
If InStr(strMSGrcvd, "TypingUser") Then
tmpData3 = InStr(strMSGrcvd, "MSG")
strMSGrcvd = Left(strMSGrcvd, tmpData3 - 1)
If strMSGrcvd <> vbCrLf And strMSGrcvd <> "" Then
tmpData2 = InStr(strMSGrcvd, "MIME-")
If tmpData2 = 0 Then rtbIMchat.Text = rtbIMchat.Text & vbCrLf & txtIMfrom.Text & " : " & strMSGrcvd ' add message sent by the buddy to chat window
rtbIMchat.SelStart = Len(rtbIMchat.Text)
blnTYp = True
End If
End If
strIMData = Right(strIMData, Len(strIMData) - tmpData1 - 1)
If blnTYp = False Then
If strMSGrcvd <> vbCrLf And strMSGrcvd <> "" Then
tmpData2 = InStr(strMSGrcvd, "MIME-")
If tmpData2 = 0 Then rtbIMchat.Text = rtbIMchat.Text & vbCrLf & txtIMfrom.Text & " : " & strMSGrcvd
rtbIMchat.SelStart = Len(rtbIMchat.Text)
blnTYp = True
End If
End If
Loop
End If
End If
End If
End Sub