Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
get the ID of the menu item under the mouse cursor
#2
A C++ function from QM source code.
 
Code:
Copy      Help
//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


Messages In This Thread
RE: get the ID of the menu item under the mouse cursor - by Gintaras - 08-21-2026, 04:22 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)