Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Getting the text off notifyIcons (tray icons)

I'm crafting this "what you are listening to" - plugin for learning purposes that displays the current Spotify or Winamp song as a message in an IM client.

So far it's really simple, I'm merely getting the song played from the title like so

Process.GetProcessesByName("spotify");

and then just pick out the song part ("Spotify - < song title >")

proc.MainWindowTitle.Substring(10);

However, most people don't keep the main window open or minimized to the taskbar, but have it visible only as a tray icon. I'd like to get the text from there (the one displayed when hovering above it).

Is there any easy way of doing this?

Thanks

like image 309
pastapockets Avatar asked Jan 17 '10 16:01

pastapockets


1 Answers

Setting the tooltip text for the icon requires Shell_NotifyIcon() with the NIM_UPDATE message, setting the NOTIFYICONDATA.szTip member.

The showstopper is that you can't find out what hWnd and uID values you need to use if you don't own the tray icon. Windows doesn't support enumerating tray icons. Which also prevents getting the tooltip text.

like image 106
Hans Passant Avatar answered Oct 10 '22 19:10

Hans Passant