Enhanced MSN Messenger in C# using Windows Forms


Introduction:

 

We are using MSN Messenger for past so many years. It has been improved a lot in terms of functionality and UI from its first release up to now. 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 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 than I will explain design and coding of this application.

 

Features present in this Application:

  • Allows to see contact list and message history.
  • Allows to browse message history sorted by date.
  • Allows to mail  message history of selected user.
  • Allows to Monitor any contact status.
  • Automatically reloads contact's status, when the status changes.
  • Maintains a list of recent users, to 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 project's references. This dll is present in code folder in the attachment or you can search for it in Google. Than design the main form as shown below:

 

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

 

History Window:

 

 

Alters Window:

 

 

MessageViewer Window:

 

 

Now, I will explain important steps in coding each form.

 

Main form (Form1.cs):


In form load, I am creating an instance of msn messenger. Later, I am getting path of message history, which will be stored in registry. This registry entry will be different for each computer. You can get path of message history by searching registry with this key MessageLogPath. Later, copy this key path and paste in app.config in value field of key registryPath. Normally, MSN messenger will store each user history in the path stored in MessageLogPath registry entry in the form of xml file with a default xsl file to format it.

 

Later, I am adding a method to be invoked wherever a user changes his status to update ListView Control with 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 Color.

 

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

 

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


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

 

Recentusers menuitem will maintain list of users to whom you messaged recently.

 

HistoryWindow:

 

In Form1, we are copying the message history of selected user into a string variable mesghistorydetails and displaying it in historywindow textbox. I am using 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 selected user's signname and serviceid from ListView control, later getting his/her history using IMessengerConversationWnd object.

 

Alerts Window:

 

Here, I am getting all contact's friendly name and adding it to a combobox. I am adding method to be invoked whenever a contact changes his/her status. In this method, I am adding his previous and current status to listbox. By using this, we can know the exact time of status change of any contact. Normally, I will use this to keep track status of my Lead. Whenever his status changes to AWAY, I will start working more sincerely.

 

MessageViewer Window:

 

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

 

Final Output will be like this:

 

 

 

 

 

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

Up Next
    Ebook Download
    View all
    Learn
    View all