Solved

Submenu items do not appear after I iterate through them

Posted on 2004-03-25
2
407 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
2 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 250 total points
Comment Utility
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
Comment Utility
Thank you very much.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Handling string inputs in C/Linux 23 167
Add content to output file 4 57
sum67 challenge 35 88
canBalance challenge 34 64
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now