A C++ function from QM source code.
//Returns id of popup menu item from point.
//Returns 0 if fails, eg if the point is not in a menu.
//p must be DPI physical, not logical.
int GetMenuItemFromPointSimple(HWND hwnd, POINT p, DWORD timeout, OUT HMENU* pHmenu/*=0*/)
{
HMENU hm=dlg::HmenuFromHwnd(hwnd, timeout); if(!hm) return 0;
if(call.PhysicalToLogicalPoint_AllOS && !call.PhysicalToLogicalPoint_AllOS(hwnd, &p)) return 0; //unlike most other API, MenuItemFromPoint still uses logical coord on Win10
int i=MenuItemFromPoint(0, hm, p); if(i==-1) return 0;
i=GetMenuItemID(hm, i); if(i==-1 || i==0) return 0;
if(pHmenu) *pHmenu=hm;
return i;
//info: can use GetMenuBarInfo/OBJID_CLIENT instead of MN_GETHMENU, but it also sends MN_GETHMENU, and does not give more useful info, eg owner window handle (hwndMenu is 0).
}
HMENU HmenuFromHwnd(HWND w, DWORD timeout)
{
if(timeout==0) return (HMENU)SEND(w, MN_GETHMENU, 0, 0); //SendMessage
HMENU hm;
if(!SendT(w, MN_GETHMENU, 0, 0, timeout, &hm)) return 0; //SendMessageTimeout
return hm;
}
BOOL (WINAPI* PhysicalToLogicalPoint_AllOS)(HWND hWnd, LPPOINT lpPoint); //XP: 0, Vista-8.0: PhysicalToLogicalPoint, 8.1+: PhysicalToLogicalPointForPerMonitorDPI