dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Thread: EnableMenuItem problem

Threaded View

  1. #1
    Join Date
    Jul 2016
    Posts
    35

    EnableMenuItem problem

    Hello,
    I have an MDI application and having problems disabling or graying an item in the drop-down menu. I am using visual studio 2015

    The drop-down menu is fourth from the left. Zero-based 3. The code is:

    Code:
    CWnd* pMain = AfxGetMainWnd();
    
    if (pMain != NULL)
    {
      CMenu* pMenu = pMain->GetMenu()->GetSubMenu(3);  
    
      // following test count agrees with number of drop-down menu items
      int count = pMenu->GetMenuItemCount();	
    
      if (pMenu != NULL && pMenu->GetMenuItemCount() > 0)
     {
        BOOL res = pMenu->EnableMenuItem(ID_ANALYZE, MF_BYCOMMAND | MF_GRAYED);
    
        pMain->DrawMenuBar();
     }
    BOOL res returns 0 which indicates to me that the EnableMenuItem command was successful.

    But the menu item is not GRAYED!

    I've tried different methods including by position, but nothing works! For example,

    Code:
    BOOL res = pMenu->EnableMenuItem(ID_MENUID, MF_BYCOMMAND | MF_GRAYED |MF_DISABLED);
    
    BOOL res = pMenu->EnableMenuItem(3, MF_POSITION | MF_DISABLED);
    Any suggestions?

    Thank you in advance
    Last edited by 2kaud; March 21st, 2019 at 04:10 AM. Reason: Added code tags

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)