Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Cannot change Menu entries state

Posted on 1998-05-19
4
Medium Priority
?
206 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 40 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…
Suggested Courses

604 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