Solved

Disableing menuitems on the fly

Posted on 1998-09-08
12
163 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
  • 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
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.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Expand macro to ask for filename column 8 37
Named range not carried over 10 65
canBalance challenge 34 96
Can not remove SSL certificate on iPhone 6 - iOS10.2 12 814
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. …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

792 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