Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Submenu items do not appear after I iterate through them

Posted on 2004-03-25
2
Medium Priority
?
418 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 1000 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

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: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

670 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