Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 232
  • Last Modified:

Dynamic menu in dialog based application

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
nathan_rr
Asked:
nathan_rr
  • 3
  • 2
1 Solution
 
Roshan DavisCommented:
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
 
nathan_rrAuthor Commented:
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
 
Roshan DavisCommented:
Use macro

ON_COMMAND_RANGE
instead of
ON_COMMAND

u can specify a range of ids that u created dynamically

GOOD LUCK
0
 
Roshan DavisCommented:
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
 
nathan_rrAuthor Commented:
Thankyooooo Very much RoshMon,
Thank you.

Your suggestion works well.


With regards
Nathan R.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now