Hiding another Tray Icon with C/C++

somamasta
somamasta used Ask the Experts™
on
Hi experts
(Sorry for my english)

I have a problem and I've searched very much to get a solution. But i didn't hav one
I want to hida any trayicon in my taskbar
e.g. i want to hide the tray icon of the program GetRight
How can i do this?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
cup

Commented:
Do you want to put it in the system tray or hide it from the task bar or put it on the toolbar which shares the task bar.
Author of the Year 2009

Commented:
If you know the hWnd and the ID of the targettted taskbar icon, this is easy:  

Just call Shell_NotifyIcon.  You can pass  NIM_DELETE as the dwMessage.  Or perhaps you can pass NIM_MODIFY and in the NOTIFYICONDATA structure, set the hIcon to NULL or an blank Icon.

However, I know of no way to enumerate the icons in the tray, and thus, no way to obtain the HWND and uID of some external program.  You can get the hWnd via FindWindow() API, but the uID is private to each program.  Most programs only monkey with their own icons...

Also, try checking around in the GetRight program settings.  There is probably a user option that will let you hide the Tray Icon.

-- Dan
Author of the Year 2009

Commented:
Actually, there may be a way.  One can get the handle to the tray notification window (the area next to the clock) and it is a window of class ToolbarWindow32 which is a Windows Common Control, which hosts an ImageList.  With that in mind, it *might* be possible to send messages to it that will delete an icon or even lean something about it from the item data.  That's a longshot though, and even then, you would need to know the relative position of the icon (third from the left, etc).

An alternative would be to get the hWnd of the target program, and send Shell_NotifyTray(NIM_DELETE,...) messages passing in uIDs starting with 0 and working your way up to 4294967295.

I see that you are new here.  This is just to let you know that you must respond to comments if you want an Expert to help you.

-- Dan
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Author

Commented:
äähhhm

i meant,  i want to hide any icon from the trayiconlist in mytaskbar
e.g i want to hide Norton Antivirus tray icon
haw can i do this?

Author

Commented:
ok

this is my problem...
how can i get the hwnd from the  program?
i know the tag that stands over the icon when the mouse is over it. i think it must be possible to get it with this information.

thanx Dan for your answers
Author of the Year 2009

Commented:
Here's the deal:
The icon that is in the tray is displayed by the system and it does not have its own window.  But the system associates a window with that icon.  And when you click that icon or hover the mouse over it, the system sends a notification to the owning window.  But there is now ayt to ask the system "please tell me which window is responsible for ahndling this icon"

However, since you know that there is such a window, you can work in reverse.  In this case, the title of the owning window is probably something like "Norton AntiVirus blah bla blah"  So you can use the FindWindow API function to get an HWND of that window.  That is the first step and your first task.

A tool that will help you is called Spy++ which is available in the Tools memu in the VC++ IDE.  Try it.  See if you can find the Norton Window (even if it is not displayed on screen, it should be ther in the Spy++ list).

-- Dan

Author

Commented:
You said:

An alternative would be to get the hWnd of the target program, and send Shell_NotifyTray(NIM_DELETE,...) messages passing in uIDs starting with 0 and working your way up to 4294967295.

how can i get the uid?
and does this help me ti just hide the tray icon?
the tray icon is a child window of the the programm (Norton antivirus)?
is this right?

Author

Commented:
You said:

An alternative would be to get the hWnd of the target program, and send Shell_NotifyTray(NIM_DELETE,...) messages passing in uIDs starting with 0 and working your way up to 4294967295.

how can i get the uid?
and does this help me ti just hide the tray icon?
the tray icon is a child window of the the programm (Norton antivirus)?
is this right?
Author of the Year 2009

Commented:
>>the tray icon is a child window of the the programm (Norton antivirus)?
No it is not... as I specifically stated in my post.  Why not take a minute and read it?

I have already suggested what to do.  Why not do it?  

Use Spy++ to get started.  Then write some code that uses FindWindow.  When that is working, report back here.

-- Dan

Author

Commented:
Yeah ok
found Norton antivirus

but wich of it is the tray icon?
i used findwindow to find the norton antivirus window and that worked
i can show the original norton antivirus window

but how can i get the hwnd of the icon in the tray then
or what should i do now?

/*i read all your messages but my english is not so good as yours*/

thx

somamasta
Author of the Year 2009

Commented:
You cannot get the HWND of the icon in the tray, because id does not have an HWND (as I stated above).  About the only thing you can do is try calling

    Shell_NotifyTray(NIM_DELETE, ... )

You must set the data in the NOTIFYICONDATA structure to identify the desired tray icon to delete.  To identify the tray icon, you must use the HWND that you obtained from FindWindow and you must also specify an ID number.  

Alas, you don't know the correct ID number.  But you can figure it out by using Spy++ (and monitoring the messages that get sent to thr Norton Window when you click the Norton tray icon).  Or you can just try lots of different numbers (in a loop) until one of them works.

-- Dan  

Author

Commented:
ok

and how can i do this?
i have the hwnd of the window

can u send me some code ?
pls

somamasta
Author of the Year 2009

Commented:
First try this:
Use Spy++ and set it to display all messages that are sent to the Norton Window.  While the messages are displayed, right-click on the Norton Tray Icon.  Report the messages that are recieved.  There should be a series of private messages sent to the Norton Window.  The WPARAM and LPARAM values will be significant -- on of them will be the uID value.

-- Dan

P.S.  Don't expect me to write your program for you for 75 points.

Author

Commented:
Don't expect me to write your program for you for 75 points.

i don't expect it

ok when i have the wparam ad lparam
what shoould i do with it

when i close the program and the icon dissapears there are some messages
are these useful for me?
Author of the Year 2009
Commented:
The WPARAM of one of those notifs will be the uID of the tray icon.  So now you need to write code that will call Shell_NotifyTray(NIM_DELETE, ... ) and pass in the hWnd and the uID.

There is no certainty that it will work, but its worth a try.

-- Dan

Author

Commented:
i didn't made it yet but i'll keep trying
i don't understand your last answer but now u will get your 75pts
sorry that i've taken your time

somamasta

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial