?
Solved

Disableing menuitems on the fly

Posted on 1998-09-08
12
Medium Priority
?
167 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
Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit 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 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

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

770 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