Solved

Cannot change Menu entries state

Posted on 1998-05-19
4
203 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

730 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