Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
get the ID of the menu item under the mouse cursor
#3
Function GetMenuItemIdFromMouse
Code:
Copy      Help
;/
function# [str&itemText] [int&popupMenuHandle]

;Gets id of menu item from mouse.
;The id can be used with QM function men().
;Works only with standard menus.
;Returns 0 if fails, eg if mouse is not on a menu. Also if it opens a submenu (no id).


POINT p; xm p
int h=WindowFromPoint(p.x p.y)
if(GetClassLongW(h GCW_ATOM)!=32768) ret

int hm=SendMessage(h MN_GETHMENU 0 0); if(!hm) ret

dll user32 #PhysicalToLogicalPoint hWnd POINT*lpPoint
dll user32 #PhysicalToLogicalPointForPerMonitorDPI hWnd POINT*lpPoint
if(_winver<0x603) PhysicalToLogicalPoint h &p; else PhysicalToLogicalPointForPerMonitorDPI h &p

int i=MenuItemFromPoint(0 hm p); if(i=-1) ret
i=GetMenuItemID(hm i); if(i=-1) ret

if(&popupMenuHandle) popupMenuHandle=hm
if(&itemText) MenuGetString hm i &itemText

ret i


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

Forum Jump:


Users browsing this thread: 1 Guest(s)