Solved

Cannot change Menu entries state

Posted on 1998-05-19
4
200 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
Comment Utility
You need to add a command ui handler. Details on the way...
0
 
LVL 3

Expert Comment

by:tma050898
Comment Utility
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
Comment Utility
Next time, please post MFC related questions in the "MFC" area.  You'll get more responses
0
 
LVL 3

Expert Comment

by:tma050898
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

763 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

6 Experts available now in Live!

Get 1:1 Help Now