CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 1999
    Location
    Toulouse - France
    Posts
    135

    Disable an item in the main menu

    Hi!

    How do I disable an item in the main menu of my window?

    Thanks in advance

    Sandrine


  2. #2
    Join Date
    Jun 1999
    Posts
    319

    Re: Disable an item in the main menu

    Add A UpdateCommand handler for the menu ID you want do disable it. In it implementation you may set :
    pCmdUI->Enable(FALSE)
    Let me know if this helps you.
    Best regards,
    Faby


  3. #3

    Re: Disable an item in the main menu

    look at (CMenu:EnableMenuItem (MF_BYPOSITION), (CWindow:GetMenu (from mainframe/AfxGetMainWnd())
    if i remember well before long time i found any asserts in CMenu when i wanted to have action directly from main menu (not submenus)
    maybe this helps you
    t!


  4. #4
    Join Date
    Jul 1999
    Location
    Uitca, NY
    Posts
    120

    Re: Disable an item in the main menu

    Assuming a program named Program created with AppWizard MFC: from file ProgramView.cpp - ID_MENUITEM is the id of the menu item that you want to enable/disable. The ClassWizard bar should be at the top of the source code window in the default configuration. In ClassWizard select ID_MENUITEM from the CProgramView Object ID's list, and UPDATE_COMMAND_UI from the Messages list. Create the function as ClassWizard requests. The function name will be CProgramView::OnUpdateMenuItem. See the example below for a menu item named ID_RETRIEVE_1.

    void CMandelbrotView::OnUpdateRetrieve1(CCmdUI* pCmdUI)
    {
    // Programmer created code
    if ( // Enable condition // )
    pCmdUI->Enable( TRUE );
    else
    pCmdUI->Enable( FALSE );
    // End programmer generated code
    }



    The ClassWizard automatically generates the right pointer, and the call to Enable controls access and grays out the item in a single call. ClassWizard keeps programming errors down and your code consistent. Once you do this a couple of times it gets very fast. This works for all access points to the ID_MENUITEM function, menus, toolbars, etc.


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