DaveT72
asked on
Dialog menu enabling and disabling items
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.LoadMenu(IDR_F ILE_MENU);
SetMenu(&m_File_menu);
m_File_menu.EnableMenuItem (ID_FILE_C LOSE, MF_BYCOMMAND | MF_GRAYED);
m_File_menu.EnableMenuItem (ID_FILE_S AVE, MF_BYCOMMAND | MF_GRAYED);
m_File_menu.EnableMenuItem (ID_FILE_S AVEAS, MF_BYCOMMAND | MF_GRAYED);
m_File_menu.Detach();
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.LoadMenu(IDR_F ILE_MENU);
m_File_menu.EnableMenuItem (ID_FILE_S AVEAS, MF_BYCOMMAND | MF_ENABLED);
m_File_menu.Detach();
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?
Thanks,
Dave
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.LoadMenu(IDR_F
SetMenu(&m_File_menu);
m_File_menu.EnableMenuItem
m_File_menu.EnableMenuItem
m_File_menu.EnableMenuItem
m_File_menu.Detach();
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.LoadMenu(IDR_F
m_File_menu.EnableMenuItem
m_File_menu.Detach();
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?
Thanks,
Dave
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
the second you should use "Attach" instead of "LoadMenu"