Solved

Cannot change Menu entries state

Posted on 1998-05-19
4
204 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

717 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