How do I position a notification (tray) icon context menu on Windows XP?


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


The correct way of solving this is to either use the mouse message coordinates, or <a href="http://msdn.microsoft.com/en-us/library/ms644938%28v=vs.85%29.aspx" rel="nofollow">GetMessagePos</a> for other messages.


Retrieving the click coordinates with GetCursorPos works well:

// Inside WndProc's switch(message)... case WM_APP_NOTIFYCALLBACK: switch (LOWORD(lParam)) { case WM_CONTEXTMENU: // XP and later { POINT pt = {}; if( GetCursorPos(&pt) ) ShowContextMenu(hWnd, pt, iStatus); } break; // ... } // ...


<strike>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)</strike>

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


  • Bind a DataGrid to the selectedrow object of a second datagrid, WPF Caliburn.Micro
  • if statement in SQL to calculate age
  • AVAssetExportSession using AVAssetExportPresetPassthrough breaking output
  • Combining Reports that use subreports already
  • Not able to read Object values in Freemarker Template
  • Robocopy and get Copied file name
  • Simple DLL created in Visual Studio 2017 doesn't load in XP [duplicate]
  • C++ DLL returning pointer to std::list
  • Programmatically closing a dialog box - win32
  • DefWindowProc() issue
  • Use NativeWindow to disable screensaver
  • COM object to create a “Open File” dialog under Vista?
  • Trying to return value from Message c++ mfc
  • what are the specifics of setting up PHP so that integers will be 64-bit?
  • Get Windows Version
  • System.OutOfMemoryException: Out of memory (GDI)
  • php studio
  • Preventing executables with invalid Authenticode signatures from running
  • Windows service showing a GUI when no user is logged in
  • SQL Server 2008 R2 - Islands and Gaps [closed]
  • Retrieving a double from a JTextArea while solving for X
  • Is there an easy way to associate an event with a ListViewItem?
  • Calling java project from Mathematica
  • Prevent parent page from scrolling when mouse is over embedded iframe
  • Load Same ACF Map Twice on Same Page
  • Adding directive inside the directive programatically
  • Is there a way to choose which files are displayed to the user via the standard OPENFILE dialogs?
  • How do you remove the JComboBox 'click and see dropdown' functionality?
  • How to save a record and immediately use its GUID
  • Android device acting as an accessory
  • Implicit joins and Where in Doctrine - how?
  • Web.config system.webserver errors
  • Retrieve list of sent friend requests from friend_request FQL table
  • NHibernate Validation Localization with S#arp Architecture
  • How can I send an e-mail from a vbs script
  • Accessing IRQ description array within a module and displaying action names
  • Function pointer “assignment from incompatible pointer type” only when using vararg ellipsis
  • 0x202A in filename: Why?
  • Getting Messege Twice Using IMvxMessenger
  • File not found error Google Drive API