Click here to Skip to main content
6,595,444 members and growing! (14,965 online)
Email Password   helpLost your password?
General Programming » Macros and Add-ins » VS.NET Add-ins     Intermediate License: The GNU Lesser General Public License

The most useless plug-in for Visual Studio 2005 and Live Messenger

By tsxy

The most useless plug-in for Visual Studio 2005 and Live Messenger.
C++ (VC6, VC7, VC7.1, VC8.0), C++/CLI, C, Windows, Visual Studio, Dev
Posted:5 Feb 2008
Views:12,412
Bookmarked:14 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
8 votes for this article.
Popularity: 4.02 Rating: 4.45 out of 5

1

2
1 vote, 12.5%
3
3 votes, 37.5%
4
4 votes, 50.0%
5

Introduction

Have you ever wanted to display your next secret project on your Live messenger so your friends can ask about it? Nothing is better than this useless add-in for Visual Studio 2005 that allows you to show "Now editing...." in your Live Messenger.

Using the code

Here are the important parts of this piece of code:

//Define the following in the class
private EnvDTE.WindowEvents winEvents;
//In the OnConnection function, do the following
// Retrieve the event objects from the automation model.
winEvents = (EnvDTE.WindowEvents)events.get_WindowEvents(null);
winEvents.WindowActivated += 
  new _dispWindowEvents_WindowActivatedEventHandler(this.WindowActivated); 
//In the OnDisconnection, make sure you clean up the event handler
winEvents.WindowActivated -= 
  new _dispWindowEvents_WindowActivatedEventHandler(this.WindowActivated);
//To use FindWindowExA and SendMessageA, 
//you have to import those functions from user32.dll
//Do the following in the class

[DllImport("user32", EntryPoint = "SendMessageA")] 
private static extern int SendMessage(int Hwnd, 
               int wMsg, int wParam, int lParam);

[DllImport("user32", EntryPoint = "FindWindowExA")] 
private static extern int FindWindowEx(int hWnd1, 
               int hWnd2, string lpsz1, string lpsz2);

//And Since we use a constant for WM_COPYDATA, we define
private const short WM_COPYDATA = 74;


//This is the actual function that sends message to MSN.
//The exact format for the string can be found in MSN API section of MSDN
private void SendMSNMessage(bool enable, string category, string message)
{
    string buffer = "\\0" + category + "\\0" + 
                   (enable ? "1" : "0") + 
                   "\\0{0}\\0" + message + "\\0\\0\\0\\0\0"; 
    int handle = 0; 
        data.dwData = 0x0547;
        data.lpData = VarPtr(buffer);
        data.cbData = buffer.Length * 2;
        handle = FindWindowEx(0, handle, "MsnMsgrUIManager", null);
        if (handle > 0)
          SendMessage(handle, WM_COPYDATA, 0, VarPtr(data));
}

//Finally the event handling function.
public void WindowActivated(EnvDTE.Window gotFocus,EnvDTE.Window lostFocus)
{
    SendMSNMessage(true, "Music","Coding in Visual Studio: " + 
                   gotFocus.Caption); 
}

While this article is short, so is the code, which is excellent for those interested in developing and extending VS2005. I did the code in 3 hours, including learning VS2005's add-in architecture; I'm sure you can do better.

For more details, checkout the Visual Studio 2005 SDK, which can be downloaded freely from Microsoft's website. Good luck and Enjoy!

Points of interest

There are a few things in this add-in you might be interested in:

  • How to send a window message in C#
  • How to communicate with MSN Messenger's API
  • How to write an add-in for Visual Studio 2005
  • How to handle events in Visual Studio 2005

History

  • Version 1.0 - Use for your own interests.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License

About the Author

tsxy


Member
I am a computer engineering student in University of Toronto, Canada
Occupation: Web Developer
Location: Canada Canada

Other popular Macros and Add-ins articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 5 of 5 (Total in Forum: 5) (Refresh)FirstPrevNext
GeneralHow does this work?? PinmemberMember 25950082:49 31 Aug '09  
GeneralNice example, but project is tagged incorrectly PinmemberC. Bates6:09 6 Jul '09  
GeneralAwesome PinmemberBoinst16:31 6 Feb '08  
GeneralRe: Awesome PinmemberLegoMindstorms1:35 12 Feb '08  
GeneralRe: Awesome Pinmemberpankkk23:08 2 Mar '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 5 Feb 2008
Editor: Smitha Vijayan
Copyright 2008 by tsxy
Everything else Copyright © CodeProject, 1999-2009
Web21 | Advertise on the Code Project