Solved

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

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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 tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

17 Experts available now in Live!

Get 1:1 Help Now