Solved

Dialog menu enabling and disabling items

Posted on 2003-12-03
6
585 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
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 63 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 62 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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 demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now