Dynamic menu in dialog based application

Posted on 2002-03-23
Last Modified: 2013-11-20
I am using the code snippet below in a dialog based application(MFC) to get dynamic menu items.

pMenu->AppendMenu(MF_STRING | MF_ENABLED, /*cmdID*/ 50001, "New Item");

It throws no errors but doing nothing. i.e. No new menuitem is appended to the existing menu. Can anybody help me. I'll be extremely thankful. And How can i catch the COMMAND messages for newly created menu items ??.

I have implemented the OnInitMenuPopup() also  (as said in ) to test if it has any effect, but Nothing happened.

Please help to sort out these problems...

with Regards

Question by:nathan_rr
  • 3
  • 2
LVL 23

Expert Comment

by:Roshan Davis
ID: 6890572
IDR_MANU1 is the main menu

if u want to add a menu item in any of these menu bar items, u have to select its submenu first

the code look like this

     CMenu menu;
     CMenu* pPopup;

     // the font popup is stored in a resource
     pMenu = menu.GetSubMenu(0);
     pMenu->AppendMenu(MF_STRING | MF_ENABLED, /*cmdID*/ 50001, "New Item");


Author Comment

ID: 6890602
Hi Roshmon
Thankyoo for responding to my question.
Actually, I tried that too, But failed.

As i am lucky enough to get a code snippet from implement the WM_KICKIDLE message. It works fine. But the problem now is, how to catch messages for the new menu items created. Can u spend some of ur valueable time to sort these out.

With Regards
Nathan R.
LVL 23

Expert Comment

by:Roshan Davis
ID: 6890610
Use macro

instead of

u can specify a range of ids that u created dynamically

LVL 23

Accepted Solution

Roshan Davis earned 80 total points
ID: 6890612
   // ...

void CMainFrame::OnFileMenuItems(UINT nID)
   CMenu* mmenu = GetMenu();
   CMenu* submenu = mmenu->GetSubMenu(0);
   submenu->CheckMenuRadioItem(ID_FILE_MENUITEM1, ID_FILE_MENUITEM3,

Author Comment

ID: 6890623
Thankyooooo Very much RoshMon,
Thank you.

Your suggestion works well.

With regards
Nathan R.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unix / Linux grid computing 5 147
while loop over for loop 7 93
building a service to accessed via telnet client, want colors ? 4 82
Thin secure Windows 10 5 75
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: 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 Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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.

910 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

21 Experts available now in Live!

Get 1:1 Help Now