Search code examples
c#system-traysystray

Minimise any program to system tray


Hey, I am trying to make a program that minimises any program to the system tray instead of normally minimising it. Is this possible? I have been looking around on google but cant find anything.


Solution

  • Icons in the system tray are called "Notification Icons".

    To do this to your own application, If your using WinForms you can use the NotifyIcon class to display icons in the system tray. Then all you have to do it set the window to not be displayed in the task bar.

    If you're using WPF there isn't a replacement, you still have to use the old WinForms NotifyIcon class, check out this MSDN sample for more information on this.


    If you want to hide another app, what you need to do is use API calls to make the changes to the state of the applications window.

    You can use FindWindow to get a handle to the window you want to hide, then you can use GetWindowLong to get the windows state. Then you need to remove the WS_EX_APPWINDOW flag from the state and use the SetWindowLong method to apply the new style, this will remove it from the task bar. You can then use the Get/SetWindowState methods to find out the state of the window and hide/minimise it.

    You still just need to use the NotifyIcon class to display your own icon in the systray.

    Good luck with all of that. It's not something I've tried personally, but I've used all these method calls in other ways. If you haven't done API stuff from C# before you might find you need to do a bit of googling to figure out your DllImports for the version API methods. Shouldn't be anything too hard though.


    Crazyd22 has found a codeproject article that uses a slightly different set of API methods but achieves pretty much the same effect. (See comments below.)