Solved

Dialog menu enabling and disabling items

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
deburging in oracle form 12 99
noX challenge 17 115
mapBully challenge 6 128
Problem to App 4 80
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: 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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

776 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