Accessing and utilizing the contact list

Unlike previous versions of MSN Messenger, which exposed all lists, versions 5 and up only expose the contact list. Via the property MyContacts you have access to an IMessengerContacts object which holds a collection of IMessengerContact objects.

This example puts all the contacts into a list box:

Option Explicit

Private m_objMessenger As MessengerAPI.Messenger

Private Sub Form_Load()

    Dim objMessengerContact As IMessengerContact

    Set m_objMessenger = New MessengerAPI.Messenger

    For Each objMessengerContact In m_objMessenger.MyContacts
        Call List1.AddItem(objMessengerContact.SigninName)
    Next

End Sub

To instantly get an IMessengerContact object of a specific user, use the IMessenger method GetContact, giving it the sign in name of the user and IMessenger::MyServiceId. GetContact will also return IMessengerContact objects for users not on your contact list, refer to the fifth remark on the GetContact page at MSDN for more information.

You can delete a contact with IMessengerContacts::Remove, just give it the IMessengerContact object of the contact you wish to delete.

Directly adding contacts is not possible, but its possible launch the add contact dialog with an email address filled in the edit box using the IMessenger method AddContact. If hwndParent is non-zero, then an error will be raised. By passing a blank string to the function, the Add a Contact dialog will be shown as if the user clicked ‘Add a Contact’.

To get the IMessengerGroups object for a contact, use IMessengerContact::Property with the ePropType argument being MCONTACTPROP_GROUPS_PROPERTY:

Option Explicit

Private m_objMessenger As MessengerAPI.Messenger

Private Sub Form_Load()

    Dim objMessengerContact As MessengerAPI.IMessengerContact
    Dim objMessengerGroup As MessengerAPI.IMessengerGroup

    Set m_objMessenger = New MessengerAPI.Messenger
    Set objMessengerContact = m_objMessenger.GetContact("bob@hotmail.com", m_objMessenger.MyServiceId)

    For Each objMessengerGroup In objMessengerContact.Property(MCONTACTPROP_GROUPS_PROPERTY)
    Call List1.AddItem(objMessengerGroup.Name)
    Next

End Sub

This article was originally published on April 12th, 2003, but due to updates and corrections, it has been republished along with a new date.

0 Response to “Accessing and utilizing the contact list”


Comments are currently closed.