DCSIMG
How To: Create Windows Live Messenger Addin - Shai Raiten

Shai Raiten

 Subscribe

How To: Create Windows Live Messenger Addin

How To : Create Windows Live Messenger Addin

This is my first post in a series of posts about Addins.

Next : How To : Create SQL Server Management Studio Addin

Let’s Start":

Messenger Addins are not enabled by default, so to enable Addins for Messenger -

Go to HKCU\SOFTWARE\Microsoft\MSNMessenger and add a DWORD value named AddInFeatureEnabled set to 1

reg

Now launch Windows Live Messenger, sign in and go to Tools, Options, Add-ins. You should see this:

addin

The Basics of Live Messenger add-ins

Windows Live Messenger add-ins are written using a managed library called MessengerClient.dll (can be found in %programfiles%\Windows Live\Messenger) which holds the namespace Microsoft.Messenger.
In order to create an add-in, open up Visual Studio 2005/8, create a new Class Library project (e.g. called "MyAddin") and add a reference to the MessengerClient.dll file:

ref

 

Next, change the project properties so that the assembly name equals the (fully qualified) class name of the add-in. This is important to get the add-in to work. In my case the class is defined as follows:

namespace MessengerAddin
{
   public class MyAddin
   {

So, we need the following assembly name:

 

ass

 

Next, import the namespace Microsoft.Messenger and implement the IMessengerAddin interface:

using Microsoft.Messenger;

namespace MessengerAddin
{
  
public class MyAddin : IMessengerAddIn
  
{
     
private MessengerClient messenger;
     
public void Initialize(MessengerClient messenger)
     
{
        
this.messenger = messenger;
     
}
  
}
}

Example : Create New Status

namespace MessengerAddin
{
  
public class MyAddin : IMessengerAddIn
  
{
     
private MessengerClient messenger;
         
      public void Initialize(MessengerClient messenger)
      {
        
this.messenger = messenger;
        
messenger.AddInProperties.Creator = "Shai Raiten";
        
messenger.AddInProperties.Description = "This Is My Addin";
        
messenger.AddInProperties.FriendlyName = "MyAddin";
        
messenger.AddInProperties.PersonalStatusMessage = "Greetings from MyAddin";
        
messenger.AddInProperties.Status = UserStatus.Unknown;
        
messenger.AddInProperties.Url = new Uri("http://blogs.microsoft.co.il/blogs/shair");   
      
}
   
}
}
 
Now compile the project and go to Windows Live Messenger. Load the add-in via Tools, Options, Add-ins:
pick
 
Now you should see something like this:
image
 
Click OK to continue. In the Windows Live Messenger main window, click your nickname and choose "Turn on "MyAddin"":
 
active

Example : Auto Responder

public void Initialize(MessengerClient messenger)
{
  
this.messenger = messenger;
   messenger.OutgoingTextMessage += new EventHandler<OutgoingTextMessageEventArgs>
   (messenger_OutgoingTextMessage)
;
}

Again, the event handler can be stubbed automatically, but of course you need to supply some additional code:

void messenger_IncomingTextMessage(object sender, IncomingTextMessageEventArgs e)
{
  
string s = e.TextMessage;
  
StringBuilder sb = new StringBuilder();
  
for (int i = s.Length - 1; i >= 0; i--)
     
sb.Append(s[i]);
  
string reverse = sb.ToString();
  
messenger.SendTextMessage(reverse, e.UserFrom);
}
 

Example : Birthday Counter + Settings

 

 public class MyAddin: IMessengerAddIn
   
{
       
private MessengerClient messenger;
       
private System.Timers.Timer tmr;
       
private DateTime birthday;

       
public void Initialize(MessengerClient messenger)
       
{
          
this.messenger = messenger;

           
messenger.ShowOptionsDialog += new EventHandler(messenger_ShowOptionsDialog);

          
tmr = new System.Timers.Timer(5000);
          
tmr.Elapsed += new System.Timers.ElapsedEventHandler(tmr_Elapsed);
          
StartTimer();
       
}

       
private void StartTimer()
       
{
          
if (DateTime.TryParse(messenger.SavedState, out birthday))
             
tmr.Start();
       
}
       
void tmr_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
       
{
           
TimeSpan span = DateTime.Now - birthday;
           
messenger.AddInProperties.PersonalStatusMessage = String.Format("{0} days {1} hours {2} minutes {3} seconds on planet Earth", span.Days, span.Hours, span.Minutes, span.Seconds);            
       
}

       
private void messenger_ShowOptionsDialog(object sender, EventArgs e)
       
{
          
tmr.Stop();
          
SettingsDialog settings = new SettingsDialog(birthday);
          
if (settings.ShowDialog() == DialogResult.OK)
             
messenger.SavedState = settings.Birthday.ToShortDateString();
          
StartTimer();
       
}
   
}

For the Settings Dialog create new windows application called : SettingsDialog
2 Buttons (OK & Cancel)
DateTimePicker


wa

public partial class SettingsDialog : Form
   
{
       
DateTime birthday;

       
public SettingsDialog(DateTime m_birthday)
       
{
           
InitializeComponent();
           
birthday = m_birthday;

           
if (birthday != null)
               
this.birthday = DateTime.Now;
       
}

       
private DateTime bd;

       
public DateTime Birthday
       
{
           
get { return bd; }
           
set { bd = value; }
       
}

       
private void btnOK_Click(object sender, EventArgs e)
       
{
           
this.bd = birthday;
           
this.DialogResult = DialogResult.OK;
       
}

       
private void button1_Click(object sender, EventArgs e)
       
{
           
this.Close();
       
}
   
}
 
Time to try out. Usual steps again: exit Live Messenger, compile, start Live Messenger and enable the add-in. Go to Tools, Options, Add-ins and look at the enabled Settings button now:

 

settings

 

When you click it, you'll see the dialog popping up (unfortunately somewhere in the back - have to check this little issue) with a security warning (caused by the CAS feature):

warning

Ignore this for now (you can solve it by strong-naming the add-in and some good deal of CAS knowledge; add-ins in Live Messenger are sandboxed by putting them in the Internet security zone) and set your birthday:

image

Windows Live Messenger will now start counting the days, hours, minutes and seconds we've spent so far on our lovely planet:

work

 

Warning: This might cause a relatively big amount of internet traffic!

Comments

WebWise said:

wow , finally  some good technical post ! :-)

# July 20, 2008 8:30 AM

Shai Raiten said:

Thanks :)

# July 20, 2008 9:38 AM

Shai Raiten said:

How To : Create SQL Server Management Studio Addin In the last post I talked about How To: Create Windows

# July 28, 2008 2:12 AM

johnsonkee said:

good

# August 5, 2008 10:21 AM

Websites tagged "textmessage" on Postsaver said:

Pingback from  Websites tagged "textmessage" on Postsaver

# January 27, 2009 5:33 AM

Bee said:

How can i do this for WLM 9?!!!

nothing of those steps work.

please mail me at base.nime@gmail.com

# April 16, 2009 5:17 PM

NOOR said:

I NEED WINDOW LIVE MESSENGER:)

# June 10, 2009 7:38 PM

Ori said:

Can the add-ins tab be enabled on WLM 2009?

# August 3, 2009 2:14 AM

Angelo said:

How can i do this for WLM 9?!!!

nothing of those steps work.

Thanks

# March 27, 2010 2:59 AM

M.Kunal said:

Just wondering... for which versions of windows live does this work?

Good Post!

Thx.

# March 30, 2010 9:06 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: