3dz Soft

Tag: snippet

Changing Yahoo Messenger’s status using C#

by on Aug.31, 2010, under Code snippets

Some people asked me how I change Yahoo Messenger’s status in my application called Emoticon Status Generator. So I’ll make public the code snippet that I used to accomplish this.

[DllImport("USER32.DLL", EntryPoint="FindWindowA",
 CallingConvention=CallingConvention.StdCall)]
private static extern IntPtr FindWindow(string sClassName,
 string sWindowName); 

[DllImport("USER32.DLL", EntryPoint="PostMessageA",
 CallingConvention=CallingConvention.StdCall)]
private static extern bool PostMessage(IntPtr hWnd, uint iMsg,
 long wParam, long lParam);

void ChangeYahooStatus (string newStatus)
{
 // Get the current signed in user
 RegistryKey keyYahooPager =
 Registry.CurrentUser.OpenSubKey("Software\\Yahoo\\Pager");
 string userName = (string)keyYahooPager.GetValue ("Yahoo! User ID");
 keyYahooPager.Close();

 // Now open the current user's profile and set the new	 status message
 // We have to pass true to OpenSubKey to request write access

 RegistryKey keyYahooCustomMessages =
 Registry.CurrentUser.OpenSubKey ("Software\\Yahoo\\Pager\\profiles\\"
 + userName + "\\Custom Msgs", true);

 // Set the 5th message, seems like yahoo messenger has the
 //functionality to move the newly set message up as the first one.

 keyYahooCustomMessages.SetValue ("5_W", newStatus);
 keyYahooCustomMessages.Close ();

 // We are done setting the value in the registry. We now need to notify
 // Yahoo Messenger of this change

 // Find the Messenger window and send it the notification
 // 0x111: WM_COMMAND
 // 0x188: Code 392

 IntPtr hWndY = FindWindow ("YahooBuddyMain", null);
 PostMessage (hWndY, 0x111, 0x188, 0);
}

It should work with Yahoo Messenger 9 and 10, not tested with other versions.
I hope that you’ll find useful this code snippet in developing some nice piece of software.

2 Comments :, , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!