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

x
?
Solved

Disableing menuitems on the fly

Posted on 1998-09-08
12
Medium Priority
?
168 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 200 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

636 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