?
Solved

Dialog menu enabling and disabling items

Posted on 2003-12-03
6
Medium Priority
?
600 Views
Last Modified: 2013-11-20
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_FILE_MENU);
      SetMenu(&m_File_menu);
      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);
      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_FILE_MENU);                  
      m_File_menu.EnableMenuItem(ID_FILE_SAVEAS,      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


0
Comment
Question by:DaveT72
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 1

Expert Comment

by:fyf7262284
ID: 9871637
mabe i am not !i only get your advice,you can try:
the second you should use "Attach" instead of  "LoadMenu"
0
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 252 total points
ID: 9872152
Map ON_UPDATE_COMMAND_UI of ID_FILE_SAVEAS

      void CMyDialog::OnUpdateFileSaveas(CCmdUI* pCmdUI)
      {
         pCmdUI->Enable(m_bEnabled);
      }

keep this value true/false for enable/disable

Good Luck
0
 
LVL 48

Assisted Solution

by:AlexFM
AlexFM earned 248 total points
ID: 9872850
CMenu* pMenu = GetMenu();
CMenu* pSubMenu = pMenu->GetSubMenu(0);   // assuming File popup menu is first i  the dialog menu
pSubMenu->EnableMenuItem(ID_FILE_SAVEAS,     MF_BYCOMMAND | MF_ENABLED);


0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question