Windows Live Messenger API How-To
Posted: Wed Mar 09, 2011 3:51 pm
Hello and welcome to my tutorial on how to use the Windows Live Messenger API.
Tested and works with MSN 2011
Controls needed
2 Labels, name = lbl_st, text = unknown | name = "Label1", text = "My Status"
Timer1, enabled = true, interval = 100
Textbox1, text = "Email Address"
4 Buttons; text = "Add Contact" | text = "Load Online Contacts" | text = "Sign-out" | text = "Change Status"
Listbox1
Combobox1, items =
First thing you need to do after you create your project is add a reference to the API. Go to "My Project" and click on the "References" tab. Then click on "Add..." and click on "COM" tab and scroll down till you find "Messenger API Type Library", and select it. At the bottom of the same page you will see checkboxed-listbox, scroll down to "MessengerAPI" and check it.


Now you go to your form and import these at the top.
Might not work on some versions of msn. How to login.
Button_click (login) event
Comment, Rate, +rep
Thanks
CodexVideos
Tested and works with MSN 2011
Controls needed
2 Labels, name = lbl_st, text = unknown | name = "Label1", text = "My Status"
Timer1, enabled = true, interval = 100
Textbox1, text = "Email Address"
4 Buttons; text = "Add Contact" | text = "Load Online Contacts" | text = "Sign-out" | text = "Change Status"
Listbox1
Combobox1, items =
Code: Select all
Away
Be Right Back
Busy
Invisible
Offline
On the phone
Online
Out to lunch
Unknown

First thing you need to do after you create your project is add a reference to the API. Go to "My Project" and click on the "References" tab. Then click on "Add..." and click on "COM" tab and scroll down till you find "Messenger API Type Library", and select it. At the bottom of the same page you will see checkboxed-listbox, scroll down to "MessengerAPI" and check it.


Now you go to your form and import these at the top.
Code: Select all
Now after Public Class <form name> add this.
Imports MessengerAPI.MISTATUS
Imports MessengerAPI
Code: Select all
Add this to form_load event:
Public msn As New MessengerAPI.Messenger
Public msnwindow As MessengerAPI.IMessengerWindow = msn.Window
Code: Select all
Add this after/before form_load event:
AddHandler msn.OnMyStatusChange, AddressOf msn_OnMyStatusChange
Control.CheckForIllegalCrossThreadCalls = False
Code: Select all
Button1_click (add contact) event:
If mMyStatus = MISTATUS_AWAY Then
lbl_st.Text = "Away"
ElseIf mMyStatus = MISTATUS_BE_RIGHT_BACK Then
lbl_st.Text = "Be Right Back"
ElseIf mMyStatus = MISTATUS_BUSY Then
lbl_st.Text = "Busy"
ElseIf mMyStatus = MISTATUS_INVISIBLE Then
lbl_st.Text = "Invisible"
ElseIf mMyStatus = MISTATUS_OFFLINE Then
lbl_st.Text = "Offline"
ElseIf mMyStatus = MISTATUS_ON_THE_PHONE Then
lbl_st.Text = "On the phone"
ElseIf mMyStatus = MISTATUS_ONLINE Then
lbl_st.Text = "Online"
ElseIf mMyStatus = MISTATUS_OUT_TO_LUNCH Then
lbl_st.Text = "Out to lunch"
ElseIf mMyStatus = MISTATUS_UNKNOWN Then
lbl_st.Text = "Unknown"
End If
Code: Select all
Button2_click (Change status) event:
Try
If Not TextBox1.Text = "Email Address" Then
msn.AddContact(0, TextBox1.Text)
End If
Catch ex As Exception
End Try
Code: Select all
Button3_click (load online contacts) event:
Try
If ComboBox1.SelectedItem = "Away" Then
msn.MyStatus = MISTATUS_AWAY
ElseIf ComboBox1.SelectedItem = "Be Right Back" Then
msn.MyStatus = MISTATUS_BE_RIGHT_BACK
ElseIf ComboBox1.SelectedItem = "Busy" Then
msn.MyStatus = MISTATUS_BUSY
ElseIf ComboBox1.SelectedItem = "Invisible" Then
msn.MyStatus = MISTATUS_INVISIBLE
ElseIf ComboBox1.SelectedItem = "Offline" Then
msn.MyStatus = MISTATUS_OFFLINE
ElseIf ComboBox1.SelectedItem = "On the phone" Then
msn.MyStatus = MISTATUS_ON_THE_PHONE
ElseIf ComboBox1.SelectedItem = "Online" Then
msn.MyStatus = MISTATUS_ONLINE
ElseIf ComboBox1.SelectedItem = "Out to lunch" Then
msn.MyStatus = MISTATUS_OUT_TO_LUNCH
ElseIf ComboBox1.SelectedItem = "Unknown" Then
msn.MyStatus = MISTATUS_UNKNOWN
End If
Catch ex As Exception
End Try
Code: Select all
Listbox1_doubleclick event:
Dim contacts As IMessengerContacts = msn.MyContacts
Dim contact As IMessengerContact
ListBox1.Items.Clear()
For Each contact In contacts
If Not contact.Status = MISTATUS.MISTATUS_OFFLINE Then
ListBox1.Items.Add(contact.FriendlyName)
End If
Next
Code: Select all
Button4_click (sign-out) event:
Dim contacts As IMessengerContacts = msn.MyContacts
Dim vContact As IMessengerContact
For Each Contact As IMessengerContact In contacts
If ListBox1.SelectedItem = Contact.FriendlyName Then
vContact = msn.GetContact(Contact.SigninName, Contact.ServiceId)
End If
Next
msn.InstantMessage(vContact)
Code: Select all
Timer1_tick event:
msn.Signout()
Code: Select all
*BONUS* If msn.MyStatus = MISTATUS_AWAY Then
lbl_st.Text = "Away"
ElseIf msn.MyStatus = MISTATUS_BE_RIGHT_BACK Then
lbl_st.Text = "Be Right Back"
ElseIf msn.MyStatus = MISTATUS_BUSY Then
lbl_st.Text = "Busy"
ElseIf msn.MyStatus = MISTATUS_INVISIBLE Then
lbl_st.Text = "Invisible"
ElseIf msn.MyStatus = MISTATUS_OFFLINE Then
lbl_st.Text = "Offline"
ElseIf msn.MyStatus = MISTATUS_ON_THE_PHONE Then
lbl_st.Text = "On the phone"
ElseIf msn.MyStatus = MISTATUS_ONLINE Then
lbl_st.Text = "Online"
ElseIf msn.MyStatus = MISTATUS_OUT_TO_LUNCH Then
lbl_st.Text = "Out to lunch"
ElseIf msn.MyStatus = MISTATUS_UNKNOWN Then
lbl_st.Text = "Unknown"
End If
Might not work on some versions of msn. How to login.
Button_click (login) event
Code: Select all
There are many more features you can do, just try it yourself.msn.Signin(0, "USERNAME", "PASSWORD")
Comment, Rate, +rep

Thanks
CodexVideos