Solved

Disableing menuitems on the fly

Posted on 1998-09-08
12
165 Views
Last Modified: 2013-11-20
Dear Experts,
How do you make a menu item into a variable?
And how do you disable the menu item while the program is running.
0
Comment
Question by:ramsay
[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
  • 7
  • 4
12 Comments
 
LVL 1

Expert Comment

by:Bridge
ID: 1321885
CMenu* pMenu = m_pMainWnd->GetMenu();
pMenu->EnableMenuItem( ... )
0
 
LVL 1

Author Comment

by:ramsay
ID: 1321886
I have written a program that accepts a double click and is then supposed to disable a menu item.. but the code you gave me produces an assertion error..

any further suggestions..
here is the code below.



void CSCVisTestView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
   
   CMenu* pMenu = GetMenu();
   pMenu->EnableMenuItem(ID_FILE_NEW,MF_GRAYED)
   
      CScrollView::OnLButtonDblClk(nFlags, point);
}

0
 
LVL 1

Expert Comment

by:Bridge
ID: 1321887
Just looking at you code GetMenu probably returns NULL as the menu is associated with the frame. Put ASSERT(pMenu) on the next line to find out.
Try CMenu* pMenu = GetParentFrame()->GetMenu();
0
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!

 
LVL 1

Expert Comment

by:Bridge
ID: 1321888
Ignor what I've said. Talking bollocks
0
 
LVL 1

Author Comment

by:ramsay
ID: 1321889
It worked tho.. ish only for the top items.. not the sub menus.
code so far is:

CMenu* pMenu = GetParentFrame()->GetMenu();
pMenu->EnableMenuItem(ID_SMARTCARD_START,MF_GRAYED);
GetParentFrame()->DrawMenuBar();
 
0
 
LVL 1

Author Comment

by:ramsay
ID: 1321890
it didnt work for the ID_FILE_NEW tho.

0
 
LVL 1

Expert Comment

by:Bridge
ID: 1321891
CMenu* pMenu = GetMenu();
CMenu* pSubMenu = GetSubMenu(0);
pSubMenu->EnableMenuItem(ID_FILE_NEW,MF_GRAYED)
0
 
LVL 1

Author Comment

by:ramsay
ID: 1321892
I used this code.. but it didnt work.. No errors. but the new button wasnt greyed out..
(incase your wondering the ID_SMARTCARD_START) was a direct link of the menu bar and i was greyed out with the previous code)



   CMenu* pMenu =  GetParentFrame()->GetMenu();
   CMenu* pSubMenu = pMenu->GetSubMenu(0);
   pSubMenu->EnableMenuItem(ID_FILE_NEW,MF_GRAYED);
   GetParentFrame()->DrawMenuBar();

0
 
LVL 1

Author Comment

by:ramsay
ID: 1321893
I used this code.. but it didnt work.. No errors. but the new button wasnt greyed out..
(incase your wondering the ID_SMARTCARD_START) was a direct link of the menu bar and i was greyed out with the previous code)



   CMenu* pMenu =  GetParentFrame()->GetMenu();
   CMenu* pSubMenu = pMenu->GetSubMenu(0);
   pSubMenu->EnableMenuItem(ID_FILE_NEW,MF_GRAYED);
   GetParentFrame()->DrawMenuBar();

0
 
LVL 1

Author Comment

by:ramsay
ID: 1321894
Auto grade is soon.
0
 
LVL 2

Accepted Solution

by:
prasanth earned 50 total points
ID: 1321895
I recommend you use the ON_UPDATE_COMMAND_UI MFC macro to do this. Select the view in ClassWizard, select the menu item (ID_FILE_NEW or whatever), and create a handle for ON_UPDATE_COMMAND_UI.

In your doubleclick handler function, keep the disbaled status in a BOOL variable.
Then in the ON_UPDATE_COMMAND_UI handler function you can simply call EnableItem with true or false depending on the state of the BOOL variable.
0
 
LVL 1

Author Comment

by:ramsay
ID: 1321896
Great Worked like a charm!
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Pressing cancel button with C# UI Automation 3 101
WinWaitActive parameters 12 31
sumDigits challenge 9 178
zeroMAx challenge 20 134
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Suggested Courses

739 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