0
votes

The whole day I am trying to solve this simple issue, but without any success. I found a lot of hints in internet, but seems, that none of them is valid for my problem.

My issue is quite simple: I want to change the caption of a menue item while runtime

But it seems, that all solutions I found are very specific.

My requirements are this: - it is a MFC application (VS2010) - It is a SDI application, not MDI - I want to change the caption of a main menu item (like "File"), not an entry of a submenue.

Because of main entry item, there is no ID for the menu item. Therefore solutions with ON_UPDATE_COMMAND_UI will not work!

My problems are: - either the code I tried, is generating an assertion or exception - or the function call returns with false - or the function seems to work well, but I do not see any result (the caption is still unchanged)

Maybe I am using the wrong functions, or the wrong place for calling the functions. Has anybody an example, which would work within my application pre-conditions?

Many, many thanks!

Richard

1
Modify the menu item using its index and including MF_BYPOSITION.user1793036

1 Answers

2
votes

Windows cleverly hides the function to modify a menu under the arcane name of ModifyMenu. I hate it when they do things like that. Really makes me wish for Linux/Unix, with nice clear names like shmdt and mvwaddchnstr. Anyway, getting off my soap box for the moment, you'd call it something like this:

GetParentFrame()->GetMenu()->ModifyMenuW(1, MF_BYPOSITION, 0, L"New Item");
GetParentFrame()->Invalidate();