Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Powershell based monitoring system 2 137
iSeries FTP Exit Program 8 122
notReplace  challenge 53 115
SQUD PROXY SERVER, UNIX, SLL/HTTPS 5 72
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

948 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

23 Experts available now in Live!

Get 1:1 Help Now