Solved

How can I change a menu or submenus caption at runtime?

Posted on 2003-10-30
3
311 Views
Last Modified: 2013-11-20
How can I change a menu or submenus caption at runtime?

I have a submenu items "N = 10", "Cut N", "paste N"
my problem is :
when user right click on submenu item "N = 10" it popup a dialog box like

---------------------------------------------
|   change the value of N : <edit box> |
|             <ok>        <cancle>            |
---------------------------------------------
if you enter 50 then it change the submenu caption "N = 50"

so, How can I change a submenus caption by code at runtime?
0
Comment
Question by:rpatna
[X]
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
3 Comments
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 50 total points
ID: 9655798
If you know its ID
      submenu->RemoveMenu(nCMD, MF_BYCOMMAND);
      submenu->InsertMenu(pos, MF_BYPOSITION, ID_CLOSEFILE, "N=50");


Or
   int pos = FindMenuItem(submenu, "N=10");
   if (pos > -1)
   {
      submenu->RemoveMenu(pos, MF_BYPOSITION);
      submenu->InsertMenu(pos, MF_BYPOSITION, ID_CLOSEFILE, "N=50");
   }

int FindMenuItem(CMenu* Menu, LPCTSTR MenuString)
{
   ASSERT(Menu);
   ASSERT(::IsMenu(Menu->GetSafeHmenu()));

   int count = Menu->GetMenuItemCount();
   for (int i = 0; i < count; i++)
   {
      CString str;
      if (Menu->GetMenuString(i, str, MF_BYPOSITION) &&
         (strcmp(str, MenuString) == 0))
         return i;
   }

   return -1;
}


Good Luck
0
 
LVL 8

Expert Comment

by:martynjpearson
ID: 9656061
You could also override the OnUpdateCmdUI handler for the menu item, then change the text accordingly. So, say for example you store the value of N in a string variable m_strN, you would add the following code to the handler :

pCmdUI->SetText("N=" + m_strN);

Hope this helps
Martyn
0
 

Author Comment

by:rpatna
ID: 9658104
Thanks Roshan.
0

Featured Post

Do you have a plan for Continuity?

It's inevitable. People leave organizations creating a gap in your service. That's where Percona comes in.

See how Pepper.com relies on Percona to:
-Manage their database
-Guarantee data safety and protection
-Provide database expertise that is available for any situation

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

617 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