No announcement yet.

Find Menu from its caption

  • Filter
  • Time
  • Show
Clear All
new posts

  • Find Menu from its caption

    I am trying to do something that may be a lil "Bass-Ackwards" but I think may be able to be done. Unfortunately the only clues I have involve the mouse being over the menu.

    What I would like to do is
    • Given I know the text displayed in a menu (either from file or me just knowing the caption)
    • Walk the menu bar until I find a caption that matches
    • Get the position the menu item is in
    • Get the ID of that menu item

    I know each can be gotten separately, but for the life of me, I can not find a way of doing the reverse, when all you have is the caption to go by (at least not without, moving the mouse to that menuitem)

    Am I just missing something? or Mis-Reading the Docs? or can it even be done?????
    Engineer's Motto: If it aint broke take it apart and fix it

    "If at 1st you don't succeed... call it version 1.0"

    "Half of Programming is coding"....."The other 90% is DEBUGGING"

    "Document my code????" .... "WHYYY??? do you think they call it CODE? "

  • #2
    Get handle to menu with GetMenu(hWnd)
    Use GetMenuItemCount() against menu handle.
    For each item, use GetMenuItemInfo() to get text or handle to popup menu item
    If item is a submenu, use GetMenuItemCount + GetMenuItemInfo against those items

    Yes, it is recursive.

    If you don't have an Hwnd, I suppose you could EnumWindows() for all top-level windows, and check 'em all.
    Last edited by Michael Mattias; 12 Jun 2008, 07:14 AM. Reason: Fixed typo and added GetMenuItemCount() to step for submenu
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]