| | |
Disable/Enable Menu Items and Sub Items
Thread Solved
![]() |
•
•
Join Date: Mar 2006
Posts: 14
Reputation:
Solved Threads: 0
How do I disable and Enable Menu Items and Sub Items.
The above code used to work before having sub menu items to that menu item. After adding sub menu items, the previous code works for sub menu items but it would not work for menu item. Can anyone please help me out with this as where am i going wrong? Thank you
Vicky
C++ Syntax (Toggle Plain Text)
if(Selected == "drum" || Selected == "guitar" || Selected == "mic" || Selected == "computer" || Selected == "car" || Selected == "hockey" || Selected == "laptop" || Selected == "watch" ) { pCmdUI->Enable(Sort == 1); }
The above code used to work before having sub menu items to that menu item. After adding sub menu items, the previous code works for sub menu items but it would not work for menu item. Can anyone please help me out with this as where am i going wrong? Thank you
Vicky
Last edited by vickzbrit; Nov 21st, 2008 at 6:02 pm.
•
•
Join Date: Oct 2008
Posts: 35
Reputation:
Solved Threads: 1
I have faced this problem before....
just go to the menu right click on it ,
say add event handler, Add the ONUpdate
event handler. U will have to enable
Every menu, Sub Menu OnUpdate event handler.
Then its quite simple use the pCMdUI->enable()
method to enable / Disable menu depending upon the condition.
The other method is to create a pop up menu , where the
enabling and disabling of menus will be simpler.
Hope i have solved u r problem , if not reply back here
just go to the menu right click on it ,
say add event handler, Add the ONUpdate
event handler. U will have to enable
Every menu, Sub Menu OnUpdate event handler.
Then its quite simple use the pCMdUI->enable()
method to enable / Disable menu depending upon the condition.
The other method is to create a pop up menu , where the
enabling and disabling of menus will be simpler.
Hope i have solved u r problem , if not reply back here
•
•
Join Date: Mar 2006
Posts: 14
Reputation:
Solved Threads: 0
•
•
•
•
I have faced this problem before....
just go to the menu right click on it ,
say add event handler, Add the ONUpdate
event handler. U will have to enable
Every menu, Sub Menu OnUpdate event handler.
Then its quite simple use the pCMdUI->enable()
method to enable / Disable menu depending upon the condition.
The other method is to create a pop up menu , where the
enabling and disabling of menus will be simpler.
Hope i have solved u r problem , if not reply back here
C++ Syntax (Toggle Plain Text)
void CDeptView::OnSortManager() { Selected = "MANAGER"; // Selected is a variable // Pulling out data from the access table m_pSet->m_strSort="[Managers].[ManagerName]"; m_pSet->Requery(); m_pSet->MoveFirst(); UpdateData(FALSE); }
C++ Syntax (Toggle Plain Text)
void CDeptView::OnUpdateSortManager(CCmdUI *pCmdUI) { // Setting a check to the menu item but it doesn't work now as it has sub menu items pCmdUI->SetCheck(( m_SelectedSort == "MANAGER")? 1 : 0 ); // Bellow is the condition when I want the menu item and its sub item to be disabled. if(Selected == "drum" || Selected == "guitar" || Selected == "mic" || Selected == "computer" || Selected == "car" || Selected == "hockey" || Selected == "laptop" || Selected == "watch" ) { pCmdUI->Enable(Sort == 1); } }
This is how I have my code and it doesn't work. In a menu bar I have Sort. Under Sort I have Manager. Under Manager I have 2 other menu items. Before having thoes 2 menu items, Manager worked with check mark as well as disabling. After having sub menu items it wont. Can anyone help me out with it.
Vicky
•
•
Join Date: Oct 2008
Posts: 35
Reputation:
Solved Threads: 1
So what u r saying is
first the menu looked like this
SORT
|
MANAGER
Here Enabling and Disabling of manager Menu can be done,
now u have updated the manager menu like this :
SORT
|
MANAGER --- SUBMENU1
--- SUBMENU2
here u will not be able to disable the MANAGER menu as u will not be able to add an Valid event for it. Since u have added the SUNBMENU's now , u can again create the ONUPDATE event for them, then try to put the same logic into them and disable both of the sub menus. Here in the MANAGER menu when u click on it no event will be generated. MANAGER menu will be now same as SORT menu where valid event handler's cant be added. hope this helps u .
first the menu looked like this
SORT
|
MANAGER
Here Enabling and Disabling of manager Menu can be done,
now u have updated the manager menu like this :
SORT
|
MANAGER --- SUBMENU1
--- SUBMENU2
here u will not be able to disable the MANAGER menu as u will not be able to add an Valid event for it. Since u have added the SUNBMENU's now , u can again create the ONUPDATE event for them, then try to put the same logic into them and disable both of the sub menus. Here in the MANAGER menu when u click on it no event will be generated. MANAGER menu will be now same as SORT menu where valid event handler's cant be added. hope this helps u .
•
•
Join Date: Mar 2006
Posts: 14
Reputation:
Solved Threads: 0
•
•
•
•
So what u r saying is
first the menu looked like this
SORT
|
MANAGER
Here Enabling and Disabling of manager Menu can be done,
now u have updated the manager menu like this :
SORT
|
MANAGER --- SUBMENU1
--- SUBMENU2
here u will not be able to disable the MANAGER menu as u will not be able to add an Valid event for it. Since u have added the SUNBMENU's now , u can again create the ONUPDATE event for them, then try to put the same logic into them and disable both of the sub menus. Here in the MANAGER menu when u click on it no event will be generated. MANAGER menu will be now same as SORT menu where valid event handler's cant be added. hope this helps u .
Yes, that is correct. But I can disable Sort. The code for that is given below.
C++ Syntax (Toggle Plain Text)
void CDept::DisableSort(void) { CWnd* pParent = GetParent(); // This is a point to the window // This is a pointer to the menu on that window CMenu* pMenu = pParent->GetMenu(); if (m_pSet->GetRecordCount()==0) { MessageBox("Error", MB_ICONSTOP); // This disables the menu item in the 6th position which is Sort pMenu->EnableMenuItem(5 , MF_BYPOSITION | MF_GRAYED ); } m_pSet->MoveFirst(); pParent->DrawMenuBar(); // To redraw the menu OnSortEmployee(); // To reset the sort back to the “default condition” }
But the question is how am i suppose to gray out or disable the menu item in the sort. Check out the code bellow
C++ Syntax (Toggle Plain Text)
//(5) is the position of the sort, (MF_BYPOSITION ) is saying that it can be done by position of the Sort which is 5, (MF_GRAYED) means it grays out the SORT. pMenu->EnableMenuItem(5 , MF_BYPOSITION | MF_GRAYED );
Now the problem is I can not do the same thing for the sub menu of Sort. But I don't know the position for that. If there is another piece of code to get the job done, then I have no idea about it. This is where I am stuck.
Vicky
Last edited by vickzbrit; Nov 22nd, 2008 at 2:25 pm.
•
•
Join Date: Mar 2006
Posts: 14
Reputation:
Solved Threads: 0
•
•
•
•
use the same logic for disabling the MANAGER menu also, Here u r graying it i think this shud also work for MANAGER. i will also try to write a dummy pgm and test this.
Vicky
•
•
Join Date: Oct 2008
Posts: 35
Reputation:
Solved Threads: 1
Hope this works....
But make sure that u have set the m_bAutoMenuEnable = false;
C++ Syntax (Toggle Plain Text)
CMainFrame* pFrame ; // Memeber variable pFrame = (CMainFrame*) AfxGetMainWnd(); pFrame->GetMenu() ->EnableMenuItem(ID_SORT_MANAGER,MF_GRAYED);
But make sure that u have set the m_bAutoMenuEnable = false;
•
•
Join Date: Mar 2006
Posts: 14
Reputation:
Solved Threads: 0
•
•
•
•
Hope this works....
C++ Syntax (Toggle Plain Text)
CMainFrame* pFrame ; // Memeber variable pFrame = (CMainFrame*) AfxGetMainWnd(); pFrame->GetMenu() ->EnableMenuItem(ID_SORT_MANAGER,MF_GRAYED);
But make sure that u have set the m_bAutoMenuEnable = false;
C++ Syntax (Toggle Plain Text)
CWnd* pParent = GetParent(); CMenu* pMenu = pParent->GetMenu(); CMenu* submenu = pMenu->GetSubMenu(0); submenu->EnableMenuItem(0, MF_BYPOSITION | MF_GRAYED );
Please help me out
Last edited by vickzbrit; Nov 23rd, 2008 at 4:06 pm.
•
•
Join Date: Nov 2007
Posts: 978
Reputation:
Solved Threads: 208
Wouldn't it be easiest to add 'standard' ON_UPDATE_COMMAND_UI handlers for those two sub-menus, i.e. you'd have something along the lines of:
C++ Syntax (Toggle Plain Text)
ON_UPDATE_COMMAND_UI(IDM_SUBMENU1, OnUpdateSubmenu1) ON_UPDATE_COMMAND_UI(IDM_SUBMENU2, OnUpdateSubmenu2) ... void SomeClass::OnUpdateSubmenu1(CCmdUI* pCmdUI) { pCmdUI->Enable( ... ) } void SomeClass::OnUpdateSubmenu2(CCmdUI* pCmdUI) { pCmdUI->Enable( ... ) }
![]() |
Similar Threads
- Enable Menu items (VB.NET)
- How do I get rid of/disable drag to disc (Windows NT / 2000 / XP)
- Hijack This log for Buffer Overrun error.. (Viruses, Spyware and other Nasties)
- cant acess some websites and some programs wont connect to the net. (Viruses, Spyware and other Nasties)
- Trojan Horse - HELP PLEASE (Viruses, Spyware and other Nasties)
- WIN98SE protection (Viruses, Spyware and other Nasties)
- How can I delete Hosts: 1159680172 auto.search.msn.com? (Viruses, Spyware and other Nasties)
- PC crashes (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: Incorrect output file: c++ (i/o) question
- Next Thread: Quick question -
| Thread Tools | Search this Thread |
api application array based binary bitmap c# c++ c/c++ char class classes code coding compile compression console conversion count cpm delete deploy deque desktop developer dialog directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer introductory java lib linkedlist linkednodes linker loop looping loops map math matrix memory multiple news node numbertoword output parameter pointer problem program programming project python random read recursion reference rpg security sorting string strings temperature template test text text-file tree url variable vector video whyisthiscodecausingsegmentationfault win32 windows winsock wordfrequency wxwidgets





