Solved

Submenu items do not appear after I iterate through them

Posted on 2004-03-25
2
414 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Suggested Courses

635 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