Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Dynamic menu in dialog based application

Posted on 2002-03-23
5
202 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
windows 10 how make picture as desktop background 2 65
only14 challenge 19 81
MaxSpan challenge 9 105
Fibonacci challenge 11 133
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

856 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