- Home /
Make application close to the tray.
Hello, I would like to create an application that alerts me of changes done on my server. I want the application to always close/be in my system tray even when I press the close button and I also want it to display a small pop-up window when a notification happens. Could anyone point me in the direction of decent .dlls or native code that could allow this to happen?
I want my app to minimize into here:
Hello ! Same question here... (I am not looking for "closing to the tray" but more $$anonymous$$i$$anonymous$$e to the tray, but still) I found this http://www.developer.com/net/csharp/article.php/3336751 but it works for a Form class...
Answer by Orion_78 · Jun 09, 2017 at 10:17 AM
Here it is, a way to add a system tray icon : https://alanbondo.wordpress.com/2008/06/22/creating-a-system-tray-app-with-c/
You can completely hide the application with -batchmode (https://forum.unity3d.com/threads/impossible-to-start-a-game-as-a-windows-service.67398/)... keep digging
Here is a way to convert Texture2D to Icon (from https://gist.github.com/zonaryFUND/71b54517056929fa31e0), usefull since System.Drawing.Icon.ExtractAssociatedIcon didn't work for me
public System.Drawing.Icon ConvertTextureToIcon(Texture2D iconTexture)
{
System.IO.MemoryStream memStream = new System.IO.MemoryStream(iconTexture.EncodeToPNG());
memStream.Seek(0, System.IO.SeekOrigin.Begin);
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(memStream);
return System.Drawing.Icon.FromHandle(bitmap.GetHicon());
}
I tried this, using the code from https://alanbondo.wordpress.com/, and if I use System.Windows.Forms.dll from mono, I end up with an extra window. If I use System.Windows.Forms.dll from .Net I can get the 2nd window to hide properly, but with both of them, the unity app window is black until I close the second window, and the system tray. With the .Net dll the unity app window closes too. Also, sometimes it will crash.
I think there is a conflict between some part of Unity and System.Windows.Forms. That might mean that using this method is impossible, but someone with a better knowledge of .Net or $$anonymous$$ono might know better.