Menu items

Reply

Join Date: Mar 2005
Posts: 64
Reputation: atrusmre is an unknown quantity at this point 
Solved Threads: 0
atrusmre's Avatar
atrusmre atrusmre is offline Offline
Junior Poster in Training

Menu items

 
0
  #1
Dec 1st, 2005
I have a MFC application that uses a menu, I want the menu disabled by default (easy enough), but what command do I use to reenable it? I tried

  1. GetDlgItem(IDM_FILE_TEST)->EnableWindow(TRUE);

The program runs up until it executes that statement, then it crashes. Any ideas?
Thanx,
Atrus
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: Menu items

 
0
  #2
Dec 1st, 2005
  1. CMenu* menu = GetMenu();
  2. CMenu* submenu = menu->GetSubMenu(0);
  3. submenu->EnableMenuItem(ID_MENUITEM_YOU_WANT_TO_ENABLE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: Menu items

 
0
  #3
Dec 1st, 2005
Just for your information, GetDlgItem is used only for the child windows of the mother dialog. The menu is a separate entity. There for
  1. GetDlgItem(IDM_FILE_TEST)
will return NULL and
  1. GetDlgItem(IDM_FILE_TEST)->EnableWindow()
will fail.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 64
Reputation: atrusmre is an unknown quantity at this point 
Solved Threads: 0
atrusmre's Avatar
atrusmre atrusmre is offline Offline
Junior Poster in Training

Re: Menu items

 
0
  #4
Dec 1st, 2005
I realized before I posted that that was odviously the wrong thing to use, but it was the closest I could think of. (As a side note, my question was about enabling, and you aswnered how to disable, but I figured it out And it works) Just a couple of questions. Why the whole CMenu stuff. Why can't you just do?

  1. EnableMenuItem(ID_MENUITEM_YOU_WANT_TO_ENABLE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
Thanx,
Atrus
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: Menu items

 
0
  #5
Dec 1st, 2005
Originally Posted by atrusmre
(As a side note, my question was about enabling, and you aswnered how to disable, but I figured it out And it works)
Okay. My Bad. I pasted some code I had somewhere so forgot to change it.
Originally Posted by atrusmre
Why the whole CMenu stuff. Why can't you just do?

  1.  
  2. EnableMenuItem(ID_MENUITEM_YOU_WANT_TO_ENABLE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
Well it is like this. You can call CWnd::GetDlgItem directly because it is a member function of the CWnd class. So the appropriate function of your dialog window will be called even if you didnt specify the Object you are calling for.

In Contrast, the CMenu::EnableMenuItem function is not a member of the CWnd Class. It is a member of the CMenu Class. To call this inside the Dialog window, you will have to first get the handle for the object of the desired menu item using CWnd::GetMenu(). Actually what you get here is the pointer for the Menubar. Then use the CMenu::GetSubMenu to get the Menu you want and call the CMenu::EnableMenuItem() function.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 64
Reputation: atrusmre is an unknown quantity at this point 
Solved Threads: 0
atrusmre's Avatar
atrusmre atrusmre is offline Offline
Junior Poster in Training

Re: Menu items

 
0
  #6
Dec 2nd, 2005
ahhhh ok, thanx
Thanx,
Atrus
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC