views:

137

answers:

2

hi
can some one show me how to hide/show tray icons of other applications/processes using my application,i want to hide the ''connected to internet''icon(those two computers that turn blue when data is sent/recieved/both) from my app
edit: i can hide system clock using this snippet taken from http://scalabium.com/faq/dct0147.htm

ShowWindow(FindWindowEx(FindWindowEx(FindWindow('Shell_TrayWnd', nil), 0, 'TrayNotifyWnd', nil), 0, 'TrayClockWClass', nil), SW_HIDE);

i guess i can use this code to hide ''internect connection icon''(by the way what is that icon called?) as well by replacing TrayClockWClass but by which class? i have tried to find class name using this tool called windowse but with no luck
edit2: i can hide those icons in windows by leftclicking 'tray window' then selecting properties and on properties windows clicking 'customize' button then changing icons property from 'hide when inactive' to 'always hide' can i do this in delphi or even better can i hide/show(completely) that icon whenever i want(using delphi)

+3  A: 

The API does not expose access to other apps' icons. The only option is to subclass the system tray itself to intercept the window messages that Shell_NotifyIcon() sends to it so you can keep track of which HWNDs are registering which icon IDs.

Remy Lebeau - TeamB
thanks ,see my edit
Omair Iqbal
There is no way to programmably access the OS's built-in "Hide when inactive" and "Always hide" functionality. Again, the **ONLY** way to access and manipulate someone else's icons is to hook into the system tray's window directly and intercept Shell_NotifyIcon()'s WM_COPYDATA messages (look at http://www.codeproject.com/KB/applications/ShellTrayInfo.aspx for the contents of the message) so you can either access the HWNDs and IDs of each icon so you can make your own calls to Shell_NotifyIcon(), or else to simply block the messages so the icons do not reach the system tray at all.
Remy Lebeau - TeamB
thanks that was the sort of answer i was looking for, arent messages like WM_COPYDATA part of windows api?also the example is in c++(which i dont know:-() do you have a link to a delphi example
Omair Iqbal
WM_COPYDATA is a general-purpose message for passing arbitrary blocks of data between windows. The fact that Shell_NotifyIcon() uses it internally is a private implementation detail that Microsoft is free to change in the future without affecting code that uses Shell_NotifyIcon(). But for the time being, it uses WM_COPYDATA and has been for a long time. And no, I do not have a Delphi example of the earlier article I mentioned.
Remy Lebeau - TeamB
A: 

If you're in charge of the computer you're running on, then you just right click the icon and disable it manually. Presumably this writes some settings in registry (use procmon to find out), so you can automate it through Active Directory.

If you're not in charge, meaning it's not yours and just some random computer, and your app voluntarily decides to go ahead and hide icons it doesn't like, then no, there's no API to do that, and screw you for even trying. It's up to user to decide when he wants to hide the icon, not to your super cool program.

himself
What if someone wants to write an application that manages tray icons, for instance let users choose what to show when/where,.. screw him too?
Sertac Akyuz
That application is already written. It's called Explorer. There's interface in it for showing/hiding icons and when/where to show them. Any enhancement that is not part of Explorer already is by definition unstable because it must rely on undocumented features and tricks like windows-searching to make Explorer do what it's not supposed to do. So it's a bad idea anyway. Still, doing it on user permission IS possible because the app can just elevate itself to admin and then do all those dirty tricks. For malicious app, thankfully, this won't work.
himself
@himself - First, while later OSes are a lot flexible about this, former ones are not. Second, shell customization is not unheard of. I see lots of users using 3rd party software that change the appearance/behavior of this or that. Third, explorer is the default shell but there are others, and they implement the functionality of the systray... I'm sure I am not able to think of each and every valid use. The point is, while it is nice for someone here not wanting to help creation of malicious code, it is not easy to be in a position to judge.. Hence I objected to the tone of your answer.
Sertac Akyuz
@Sertac Akyuz: thank you so much for putting some sense in him
Omair Iqbal