3

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.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Crazyd22
  • 783
  • 5
  • 10
  • 24

1 Answers1

5

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.)

Community
  • 1
  • 1
Simon P Stevens
  • 27,303
  • 5
  • 81
  • 107
  • Yeah I know this, I mean different applications, like iTunes – Crazyd22 Apr 05 '10 at 20:05
  • Oh, you want to minimise other programs to the systray. Ok, to do that you still need to use NotifyIcon to display an icon in the systray, but you would need to find an API call to hide the program taskbar windows. Hang on, I'll see if I can find something. – Simon P Stevens Apr 05 '10 at 20:11
  • +1 interesting question and good answer. This leaves me wondering if there are any measures a developer can take to *prevent* their program's behavior from being altered by another program. (Aside from detecting and reversing the change) – Igby Largeman Apr 05 '10 at 20:33
  • @Charles M: No, there isn't really. These methods don't really do anything serious. Any methods that could pose security risks will require the calling program to be an running as an admin to call. (and actually, I think in C# any API call requires full trust). You always have to remember that the admin/owner of the computer should always have complete control, so provided you keep your PC secure from malicious code, API calls like this won't be likely to cause any problems. – Simon P Stevens Apr 05 '10 at 20:55
  • This seems a bit more complex than I imagined :P, is it more simple to hide an application?, I really just want to make the application 'hidden' from other users, or people looking at the computer. – Crazyd22 Apr 05 '10 at 21:09
  • @Crazyd22: Not really. The problem is that you are trying to muck with another applications window. This kind of functionality isn't provided by the .net framework, so you have to resort to lower level winAPI stuff. Sorry, I can't really think of any other way of doing this. – Simon P Stevens Apr 05 '10 at 21:24
  • Ah kk, thanks for your help :), will try to get this working, but I cant find all of the code in c# – Crazyd22 Apr 05 '10 at 21:37
  • I have found a source code for it ^^ :D http://www.codeproject.com/KB/cs/windowhider.aspx – Crazyd22 Apr 05 '10 at 21:48
  • @Crazyd22: Nice one. I've updated the answer to include the link. – Simon P Stevens Apr 05 '10 at 22:31