Mladen Milankovic wrote:
> Hi.
> 
> I'm new around here. I've programed in php, and decided I'll learn a
> little c++ to broaden my knowledge of the world. :)
> 
> It went well, by learning from a friend, book, net, but I came to a
> problem where I require your help.
> I'm writing MFC code in Visual Studio 2005, on XP machine. I know this
> is an ANSI list, but though I ask anyway maybe somebody had the same
> problem.
> I need to enable/disable some menu items.
> I've found that this function should be the answer for my problem:
> http://msdn2.microsoft.com/en-us/library/h62wh3y1.aspx
> 
> And the code I came up till now:
> 
> CMenu menu;
> CMenu *submenu;
> menu.LoadMenu(IDR_POPUP);
> submenu = menu.GetSubMenu(0);
> submenu->EnableMenuItem(ID_POPUP_CHANGEPASSWORD,MF_DISABLED | MF_GRAYED);
> 
> According to the description of that function this should work...
> except it doesn't.
> The menu is still active.
> 
> Thank you for your time,
> Regards,
> mmlado

Technically, we aren't an ANSI-only list.  There are just very few 
OS-specific questions asked because few people here can handle them.  I 
tend to field the Windows-specific ones.

To answer your question, I'm not sure what the proper answer is since 
I'm not sure what the menu structure itself looks like.  You should be 
checking the return value of EnableMenuItem() to make sure it is 
returning something other than -1.  Try not calling GetSubMenu(). 
Specify MF_BYCOMMAND even though it technically isn't needed (i.e. default).

I assume you are using the menu as a popup and using TrackPopupMenu() or 
similar.  If you are using it, say, as a "IDR_MAINFRAME" (doc/view) sort 
of menu, ON_UPDATE_COMMAND_UI(), even if not specified/declared/defined, 
could be overriding it (see the note in the comments on the webpage you 
provided).

I use MFC quite heavily but I'm not a guru.  The wonderful people over 
at www.codeproject.com in the forums seem to have nothing better to do 
all day but help other people out.  That is a more Windows-centric 
environment worth checking out in addition to this group.  Both this 
group and CodeProject are excellent resources for various aspects of C++ 
programming for Windows.

BTW, good to see you've done your own research.  Few people do that.

-- 
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197

*NEW* MyTaskFocus 1.1
Get on task.  Stay on task.

http://www.CubicleSoft.com/MyTaskFocus/

Reply via email to