Solved

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

Posted on 2003-10-30
3
309 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
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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
Decoding 32 bit binary streams 6 53
mixString challenge 36 134
EvenOdd challenge 10 142
Message not shown 5 82
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.

679 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