Solved

Submenu items do not appear after I iterate through them

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
iSeries FTP Exit Program 8 137
How to know only "File created" with EventLog 3 34
move a line in eclipse 3 104
Path of Workbook 3 79
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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

832 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