Solved

Dynamic menu in dialog based application

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

pMenu->LoadMenu(IDR_MENU1);
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 www.support.microsoft.com/support/kb/articles/Q242/5/77.asp ) to test if it has any effect, but Nothing happened.

Please help to sort out these problems...

with Regards
Reghunath.

0
Comment
Question by:nathan_rr
  • 3
  • 2
5 Comments
 
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
     menu.LoadMenu(IDR_MENU1);
     pMenu = menu.GetSubMenu(0);
     pMenu->AppendMenu(MF_STRING | MF_ENABLED, /*cmdID*/ 50001, "New Item");


GOOD LUCK
0
 

Author Comment

by:nathan_rr
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 www.codeguru.com/dialog/OnUpdate.shtml..to 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.
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 6890610
Use macro

ON_COMMAND_RANGE
instead of
ON_COMMAND

u can specify a range of ids that u created dynamically

GOOD LUCK
0
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 80 total points
ID: 6890612
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
   //{{AFX_MSG_MAP(CMainFrame)
   // ...
   //}}AFX_MSG_MAP
   ON_COMMAND_RANGE(ID_FILE_MENUITEM1, ID_FILE_MENUITEM3, OnFileMenuItems)
END_MESSAGE_MAP()

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

Author Comment

by:nathan_rr
ID: 6890623
Thankyooooo Very much RoshMon,
Thank you.

Your suggestion works well.


With regards
Nathan R.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
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 …
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

708 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

18 Experts available now in Live!

Get 1:1 Help Now