Solved

Dialog menu enabling and disabling items

Posted on 2003-12-03
6
592 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Get filename and folder into excel 7 79
Process filename extension 3 196
viewing source code from eclipse 13 110
JQuery serialize and unserialize 8 137
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.

827 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