![]() |
| ||
| Disable/Enable Menu Items and Sub Items How do I disable and Enable Menu Items and Sub Items. if(Selected == "drum" || Selected == "guitar" || Selected == "mic" || Selected == "computer" || Selected == "car" || Selected == "hockey" || Selected == "laptop" || Selected == "watch" ) 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 |
| ||
| Re: Disable/Enable Menu Items and Sub Items 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 :) |
| ||
| Re: Disable/Enable Menu Items and Sub Items Quote:
void CDeptView::OnSortManager() void CDeptView::OnUpdateSortManager(CCmdUI *pCmdUI) 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 |
| ||
| Re: Disable/Enable Menu Items and Sub Items 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 . |
| ||
| Re: Disable/Enable Menu Items and Sub Items Quote:
Yes, that is correct. But I can disable Sort. The code for that is given below. void CDept::DisableSort(void) But the question is how am i suppose to gray out or disable the menu item in the sort. Check out the code bellow //(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. 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 |
| ||
| Re: Disable/Enable Menu Items and Sub Items 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. |
| ||
| Re: Disable/Enable Menu Items and Sub Items Quote:
Vicky |
| ||
| Re: Disable/Enable Menu Items and Sub Items Hope this works.... CMainFrame* pFrame ; // Memeber variable But make sure that u have set the m_bAutoMenuEnable = false; |
| ||
| Re: Disable/Enable Menu Items and Sub Items Quote:
CWnd* pParent = GetParent(); Please help me out :( |
| ||
| Re: Disable/Enable Menu Items and Sub Items 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: ON_UPDATE_COMMAND_UI(IDM_SUBMENU1, OnUpdateSubmenu1) |
| ||
| Re: Disable/Enable Menu Items and Sub Items Thanks for helping me out guys. You are both right which difference piece of code provided. It wasn't this piece of code that was not letting me accomplish the job. I finally figured out where was I making a mistake :-) I am marking this thread as solved. Vicky |
| All times are GMT -4. The time now is 4:21 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC