Solved

Cannot change Menu entries state

Posted on 1998-05-19
4
202 Views
Last Modified: 2010-04-10
I did my sceletton application with the MFC AppWizzard. I have a SDI application with several views (splitter windows) and a menu for the mainframe window. Now the problem is: i cannot change the state of pop up menu entries, i've tried:

CWnd* pMainFrame = AfxGetMainWnd();
CMenu* pMainFrameMenu = pMainFrame->GetMenu();
ASSERT(pMainFrameMenu != NULL);
pMainFrameMenu->EnableMenuItem(IDM_COMMPORTSETTINGS_DISCONNECT,
                                                                 MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
I get the right menu pointer, with:
(I tried pMainFrameMenu->GetMenuString(IDM_COMMPORTSETTINGS_DISCONNECT,  ...) i get the menu entry
i want to change, but the state of this menu point does not change, and i do not know why.
The weird thing is also the following: When i edit the menu in the resource editor and set the checkmark for this
menu entry to "grayed" then it appears also grayed in the resource editor. But if i compile my program and run
it then the same menu entry is enabled and not grayed !!!!!
Does anybody knows help? i would appreciate it very much, cause i have no idea where the problem could be
thanks
                                                    Martin
0
Comment
Question by:mruff
  • 3
4 Comments
 
LVL 3

Accepted Solution

by:
tma050898 earned 10 total points
ID: 1164365
You need to add a command ui handler. Details on the way...
0
 
LVL 3

Expert Comment

by:tma050898
ID: 1164366
1. Display ClassWizard
2. Select the class that will contain enough info to decide whether or not the menu item should be enabled or not. For example,let's say that the CMainFrame class has a bool flag that specifies whether the user is connected or not (hence you don't want the IDM_COMMPORTSETTINGS_DISCONNECT menu item enabled).
3. In the Object Ids select the menu item
4. Double click on the UPDATE_COMMAND_UI entry in the Messages list to create a "command ui" handler.
5. Assuming that CMainFrame has that bool flag mentioned earlier, your command ui handler would look something like...

void CMainFrame::OnUpdateCommportsettings_disconnect(CCmdUI* pCmdUI)
{
 pCmdUI->Enable(m_bUserIsConnected);
}

Now if m_bUserIsConnect is TRUE the menu item will be enabled and if the value is FALSE, the menu will be disabled.

HTH,
Tom

0
 
LVL 11

Expert Comment

by:alexo
ID: 1164367
Next time, please post MFC related questions in the "MFC" area.  You'll get more responses
0
 
LVL 3

Expert Comment

by:tma050898
ID: 1164368
mruff,

Did the answer above help you or do I need to provide some additional information?

If the answer above did solve your problem, could you please close it by accepting the answer and grading my help? That way, other programmers having the same problem will have the benefit of this question having been asked and answered.

Thanks,
Tom

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

856 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