Solved

Submenu items do not appear after I iterate through them

Posted on 2004-03-25
2
413 Views
Last Modified: 2013-11-20
Hi there,

I'm trying to make my program update the text of all my menu items dynamically.  I have subclassed CMenu because I need to control the font and colour of the menu items; I followed the method here:

http://www.codeguru.com/Cpp/controls/menu/article.php/c3721

I have the following two functions:

void CMainFrame::updateMenuTexts() {
    CMenu *pMenu = pMyMenu;
    for (int i = 0; i < pMenu->GetMenuItemCount(); i++)      {
        CMenu* subMenu = pMenu->GetSubMenu(i);
        for (int j = 0; j < subMenu->GetMenuItemCount(); j++) {
            UINT id = subMenu->GetMenuItemID(j);
            updateMenuText(subMenu, i, id);
        }
        updateMenuText(pMenu, i, POPUP);
    }

    HMENU hMenu = ::GetMenu(GetSafeHwnd());
    pMyMenu->Detach();
    pMyMenu->Attach(hMenu);
    SetMenu(pMyMenu);
}

void CMainFrame::updateMenuText(CMenu* pMenu, int position, int id) {
    EyeSpeakMenu* menu = (EyeSpeakMenu*)pMenu;
    if (id == POPUP) {
        VERIFY(menu->ModifyMenu(position, MF_BYPOSITION | MF_STRING | MF_POPUP, NULL,
            getMenuText(position, POPUP)));
    } else {
        VERIFY(menu->ModifyMenu(id, MF_BYPOSITION | MF_STRING, id,
            getMenuText(position, id)));
    }
}

The getMenuText function returns the text I want for the menu item; this works fine.

The problem is that once I have called this function, only the top-level menu items appear; when you click on them it seems like they have no submenu.  Why could this be?

Thank you for your help.
0
Comment
Question by:wilsonian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 250 total points
ID: 10684582
CMenu::ModifyMenu

nIDNewItem
Specifies either the command ID of the modified menu item or, if nFlags is set to MF_POPUP, the menu handle (HMENU) of a pop-up menu.

You pass NULL in nIDNewItem. This removes submenus from it.

Other way: in my program I modify popup menu without using of MF_POPUP flag, and it works:

pMenu->ModifyMenu(pos, MF_BYPOSITION | MF_STRING,  0, s);

pMenu - parent menu.
pos - position of popup menu in the parent menu.
0
 

Author Comment

by:wilsonian
ID: 10701175
Thank you very much.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 54
Separate into files by filename 12 92
How to know only "File created" with EventLog 3 35
has77  challenge 9 107
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question