Forum Discussion

givanft's avatar
givanft
New Contributor
14 years ago

How to get all menu's items?

Hello friends!!!



Please help! I have an MFC application built with VS2010. There is the main menu, sub menu and some items have subsub menu (see Att.1).

After some customization, during execution of the application, it is possible to hide any item from the subsubmenu(see Att.1 red box). So I should check is this item hidden now or not(see Att.2). 

After try to click on hidden item I get error:

--------------------------------------

The control item 'Start' not found.

Total number of items: 6.

Items: '&Start Quick Change', 'Re&lease Quick Change', 'R&evoke Quick Change', '', 'Start Change', 'Retire'.





Tested object:

Aliases.PowerUserU.wndAfx2.Afx

(Sys.Process("PowerUserU").Window("Afx:00400000:800:00010003:00000010:00000000", "", 1).Window("Afx:ToolBar:400000:8:10003:10", "", 1))





--------------------------------------





So I should check if the item "Start" exists before click on it.

As I see the log contains important information about quantity of menu's items and items itself. So my question is  -- how I can get this list of menu's items before click on any one of them?

Or maybe there is exists another way to know about it? THANKS!

2 Replies

  • Hi Ivan,



    You can get the number of items in the Document | Document Workflow submenu using the wButtonCount property of the Aliases.PowerUserU.wndAfx2.Afx object. To get the item captions, use the wButtonText property.



    To check if a specific item exists in a submenu, you can loop through the submenu items and check the corresponding wButtonText property value. Something like this:

    // Select the Document | Document Workflow menu item

    ...



    // Check if the submenu contains the Start item

    var menu = Aliases.PowerUserU.wndAfx2.Afx;

    var found = false;

      for (var i = 0; i < menu.wButtonCount; i++)

      {

        if (menu.wButtonText(i, true) == "Start")

        {

          found = true;

          break;

        }

      }



      if (found)

        Log.Message("The submenu contains the 'Start' item.");

      else

        Log.Message("The submenu does not contain the 'Start' item.");