Get tray icon position?

Hi everybody!

I'd like to make an app, that uses tray icon. When you click on that icon, window appears, just like in this picture with sound icon:
http://goo.gl/O2YZsP
No matter where you click it will show up above icon. I don't want to use mouse position to determine where to show window, that solution depends on where you click. I'd like to use icon's position. I couldn't find solution to how to get those coordinates for raw win32 and C/C++, but i found one using windows forms:
http://goo.gl/bvINQg
Maybe sbd knows how to get position of that icon, or at least is able to translate the link I gave to winapi C/C++?

Thanks in advance.
may be a bit hackish, but a combination of GerCursorPos(), WindowFromPoint() , and GetWindowRect()? I'm not 100% certain how the icons are enumerated within the system tray window though. The above may only give you the rect for the system tray itself.
It works brilliantly! I wonder why didn't anybody think about that yet. Altough why do you think it's hackish? Is it unsafe, or is there anything bad about that method, that you can think of? Thanks for the solution.
All the functions are straight Win32 API and reliable, so I don't think it's unsafe. I guess when the best solution I can come up with is simplistic I automatically designate it "hackish" because I assume there is another more complete solution available that I just don't know about.
You just made my day! I was searching the web for 2 days to find it and it turns out it's so simple. Thank you again :)
EDIT:
Unfortunately it might be hackish. Probably WindowFromPoint() returns handle to tray, not to tray icon 'cuz it says that my icon is 104 px wide, wile it's only 24 pixels.
Last edited on
I was worried about that. Could try ChildWindowFromPoint() maybe? I just don't know much about the internal enumerations in the System Tray. I don't know if the different icon areas are actually "windows" per se.
I think they are, they manage different messages, and the only different method for this that I can think of would be through if else statement and mouse position, but it's too stupid, even for guys from MS.
Topic archived. No new replies allowed.