Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Enhanced MSN Messenger in C# using Windows Forms

0.00/5 (No votes)
26 Apr 2007 1  
An application which will provide certain features which are not available in MSN Messenger

Introduction

We have used MSN Messenger for many years. It has been improved a lot in terms of functionality and UI from since its first release. But, it is still missing some functionality which might be useful in certain situations. So, I designed this application which will provide certain features which are not currently available in MSN Messenger. I designed this application in VS.NET 2003 using C# and Windows Forms. I will explain little bit about the application, then I will explain the design and coding behind this application.

Features present in this Application

  • Allows you to see contact list and message history
  • Allows you to browse message history sorted by date
  • Allows you to mail the message history of selected users
  • Allows you to Monitor any contact status
  • Automatically reloads contact's status, when the status changes
  • Maintains a list of recent users whom you messaged

Steps to create this application

First, create a new Windows project in C# and add a COM dll named Interop.MessengerAPI.dll to the project's references. This dll is present in the code folder in the attachment, or you can search for it in Google. Then design the main form as shown below:

Screenshot - image001.jpg

Here, I am using a ListView control to display all contacts. Then I designed MainMenu to do the following: to sort users based on their status, to notify status changes of a selected contact, to view message history of a contact sorted by date, to mail the selected user's message history, to maintain the recent user's list who you have messaged, to perform an automatic update of listview whenever a user changes status, and to exit from application. After creating the Main form, add new forms and name each as historywindow, alerts, and MessageViewer. Design these forms as shown below:

History Window

Screenshot - image002.jpg

Alters Window

Screenshot - image003.jpg

MessageViewer Window

Screenshot - image004.jpg

Now I will explain important steps in coding each form.

Main form (Form1.cs)

In form load, I create an instance of MSN Messenger. Later, I get the path of the message history, which will be stored in the registry. This registry entry will be different for each computer. You can get the path of the message history by searching the registry with this key: MessageLogPath. Later, copy this key path and paste it in app.config, in the value field of the key registryPath.

Normally, MSN Messenger will store each user history in the path stored in the MessageLogPath registry entry in the form of an XML file with a default XSL file to format it.

Later, I add a method to be invoked whenever a user changes his status. This updates the ListView Control with an updated status of all users. Finally, I am looping through each contact of Messenger and adding it to ListView with some hidden columns with proper Colors.

ShowUserswho menuitem will sort users based on their status. Here I am just looping through each contact and adding them to ListView based on their status.

The ViewSelectedUserHistory menuitem will show a selected user's history in a new window.

Upload History menuitem will allow us first to select users whose history we want to mail, and later it will mail the selected user's history to the mail id you specified in the textbox. By using this we can view our message history from any system.

The Recentusers menuitem will maintain a list of users you have recently messaged.

HistoryWindow

In Form1, we are copying the message history of the selected user into a string variable, mesghistorydetails, and displaying it in the historywindow textbox. I use this code to get selected user's history:

IMessengerContact selectedcontact = msn.GetContact(
    listView1.SelectedItems[0].SubItems[1].Text,
    listView1.SelectedItems[0].SubItems[3].Text) as IMessengerContact;

IMessengerConversationWnd cw  = msn.InstantMessage(
selectedcontact) as IMessengerConversationWnd;

if(cw.History.ToString()!="")
{
    string mesghistory=cw.History.ToString();
    mesghistory= mesghistory.Replace(msn.MyFriendlyName,"You ");
    mesghistory=mesghistory.Replace(
        selectedcontact.FriendlyName,"He/She ");
    IMessengerWindow window=cw as IMessengerWindow ;
    mesghistoryContactName=selectedcontact.FriendlyName;
    window.Close();
    mesghistorydetails=mesghistory;
    HistoryWindow objform2 = new HistoryWindow();
    objform2.Show();

Here, I am getting a selected user's signname and serviceid from the ListView control. Later, I get his/her history using the IMessengerConversationWnd object.

Alerts Window

Here, I take all the contact's friendly names and add them to a combobox. The method is invoked whenever a contact changes his/her status. In this method, I add his previous and current status to listbox. By using this, we can know the exact time any contact went through a status change. Normally, I use this to keep track status of my Lead. Whenever his status changes to AWAY, I start working more sincerely.

MessageViewer Window

Normally, the message history of any contact will be stored on the local hard disk in the path specified by the MessageLogPath registry key, in the form of an XML file. Here, we have to browse a selected user's message history file using filedialog control. Later, we can view message history based on its date with respect to the current date.

The final Output will be like this:

Screenshot - image005.jpg

Screenshot - image006.jpg

Screenshot - image007.jpg

Screenshot - image008.jpg

We can still enhance this Messsenger by adding little bit of code. I hope this code will be useful for all. I am attaching code for further reference.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here