Link to home
Start Free TrialLog in
Avatar of ramsay
ramsay

asked on

Disableing menuitems on the fly

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.
Avatar of Bridge
Bridge

CMenu* pMenu = m_pMainWnd->GetMenu();
pMenu->EnableMenuItem( ... )
Avatar of ramsay

ASKER

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);
}

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();
Ignor what I've said. Talking bollocks
Avatar of ramsay

ASKER

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();
 
Avatar of ramsay

ASKER

it didnt work for the ID_FILE_NEW tho.

CMenu* pMenu = GetMenu();
CMenu* pSubMenu = GetSubMenu(0);
pSubMenu->EnableMenuItem(ID_FILE_NEW,MF_GRAYED)
Avatar of ramsay

ASKER

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();

Avatar of ramsay

ASKER

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();

Avatar of ramsay

ASKER

Auto grade is soon.
ASKER CERTIFIED SOLUTION
Avatar of prasanth
prasanth

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ramsay

ASKER

Great Worked like a charm!