Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2003-10-30
3
Medium Priority
?
312 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 200 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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

722 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