CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    May 1999
    Location
    Oklahoma
    Posts
    263

    EnableMenuItem() - Need Help

    I am trying to do something as simple as changing a submenu item on the IDR_MAINFRAME menu from Enabled to grayed. I contuiue to have problems of stupid proportions and have just about given up. Can someone give me an idea as to how to do this? If I were to create a MFC app, from the app wizard, no frills or thrills, can you tell me where and what code I need to add to enable/disable (gray it out) any command of your choosing on the FILE menu? If you could post the segment of code, I would be very greatful.

    Thanks!

    John Hagen



  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: EnableMenuItem() - Need Help

    Check out ON_UPDATE_COMMAND_UI in the message map section. Class wizard gives you the option of including this message in the message map. The implementation is usually this (assume ID_FILE_TESTING is my menu ID):

    BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
    //{{AFX_MSG_MAP(CMainFrame)
    ON_WM_CREATE()
    ON_UPDATE_COMMAND_UI(ID_FILE_TESTING, OnUpdateFileTesting)
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()

    ...
    BOOL MyEnableValue; // Used in my app to determine if menu item should be enabled
    ...

    void CMainFrame::OnUpdateFileTesting(CCmdUI* pCmdUI)
    {
    // Set Menu to Enabled /Disabled depending on MyEnableValue setting
    pCmdUI->Enable(MyEnableValue);
    }

    Regards,

    Paul McKenzie



  3. #3
    Join Date
    May 1999
    Location
    Houston - TX - US
    Posts
    29

    Re: EnableMenuItem() - Need Help

    Hi ,

    1) In MainFrame.cpp set bAutoMenuEnable to false as below.

    CMainFrame::CMainFrame()
    {

    m_bAutoMenuEnable = FALSE ;
    ...

    }


    2) IN ur View class on UpadateCommand enabel or disabel as required :

    void CMyView::OnUpdateUtilitiesStatistics(CCmdUI* pCmdUI)
    {
    if ( pCmdUI->m_pMenu != NULL )
    {
    CMenu * pm = pCmdUI->m_pMenu ;

    if ( !m_Pause )
    pm->EnableMenuItem( 0 , MF_BYPOSITION|MF_GRAYED) ;
    else
    pm->EnableMenuItem( 0 , MF_BYPOSITION|MF_ENABLED) ;
    }
    }



    Hope this helps you.
    Good Luck.
    Yash.


  4. #4
    Join Date
    May 1999
    Location
    Oklahoma
    Posts
    263

    Re: EnableMenuItem() - Need Help

    Thanks for your help, Yash. It's now working.



  5. #5
    Join Date
    May 1999
    Location
    Oklahoma
    Posts
    263

    Re: EnableMenuItem() - Need Help

    Thanks for your help, Paul. It's now working.



  6. #6
    Join Date
    Oct 2002
    Posts
    36
    why i got the error -&gt unidentified??? ehmmm hope u all can help me yah ...thank ur reply nad help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured