Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Dialog menu enabling and disabling items

Posted on 2003-12-03
6
Medium Priority
?
602 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
3 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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…
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.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Suggested Courses

810 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