View Single Post
Join Date: Mar 2006
Posts: 14
Reputation: vickzbrit is an unknown quantity at this point 
Solved Threads: 0
vickzbrit vickzbrit is offline Offline
Newbie Poster

Re: Disable/Enable Menu Items and Sub Items

 
0
  #5
Nov 22nd, 2008
Originally Posted by koushal.vv View Post
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.

  1. void CDept::DisableSort(void)
  2. {
  3. CWnd* pParent = GetParent(); // This is a point to the window
  4. // This is a pointer to the menu on that window
  5. CMenu* pMenu = pParent->GetMenu();
  6.  
  7. if (m_pSet->GetRecordCount()==0) {
  8. MessageBox("Error", MB_ICONSTOP);
  9. // This disables the menu item in the 6th position which
  10. is Sort
  11. pMenu->EnableMenuItem(5 , MF_BYPOSITION | MF_GRAYED );
  12. }
  13. m_pSet->MoveFirst();
  14. pParent->DrawMenuBar(); // To redraw the menu
  15. OnSortEmployee(); // To reset the sort back to the “default condition”
  16. }

But the question is how am i suppose to gray out or disable the menu item in the sort. Check out the code bellow
  1. //(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.
  2.  
  3. 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.
Reply With Quote