Dialog menu enabling and disabling items
Posted on 2003-12-03
This is an easy question and I'm sure someone else has already asked this but I can't seem to find it so here goes.
I'm adding menus to a dialog box, I probably should have created an SDI project in the first place but its done now. I have no problems creating the menu in the resource editor, I create a CMenu member to make life easy. No problems adding the menu to the dialog box, it shows up quite nicely. I use the following code in my initdialog function:
m_File_menu.EnableMenuItem(ID_FILE_CLOSE, MF_BYCOMMAND | MF_GRAYED);
m_File_menu.EnableMenuItem(ID_FILE_SAVE, MF_BYCOMMAND | MF_GRAYED);
m_File_menu.EnableMenuItem(ID_FILE_SAVEAS, MF_BYCOMMAND | MF_GRAYED);
The problem occurs when later on after the user has performed an action I want to enable certain menu items and disable others. Here's the code I'm using maybe someone can point out why this doesn't work and what I should be doing.
m_File_menu.EnableMenuItem(ID_FILE_SAVEAS, MF_BYCOMMAND | MF_ENABLED);
If I don't "Reload" the menu the Enable crashes, but since I detached from the menu during init that makes sense. So I try to load the menu but it always fails(returns 0). I've tried attaching to the menu, no luck. Any ideas?