I'm using C++ and Win32.
I want my context menu and settings dialog to show up near the tray icon. I think I need the icon's coordinates to do that.
Shell_NotifyIconGetRect wasn't available until Windows 7.
WM_CONTEXTMENU is available starting in Win2k, but only provides coordinates in wParam as of Vista (and when specifying NOTIFYICON_VERSION_4).
To display the menu, all you need is the coords passed to you by WM_CONTEXTMENU or WM_RBUTTONUP (These are of course not normal messages, but something generated by the tray and you therefore don't have to deal with mouse vs keyboard)Shell_NotifyIconGetRect is used if you want to display a toast (custom window) near the tray. On < 7 you can emulate it with findwindow by looking for the TrayNotifyWnd class with Shell_TrayWnd as the parent
The correct way of solving this is to either use the mouse message coordinates, or GetMessagePos for other messages.
Retrieving the click coordinates with GetCursorPos works well: