Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How do I check or change text in a VS2008 menu bar menu item

How do I check or change text in a VS2008 menu bar menu item

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    soaringpilot
    wrote on last edited by
    #1

    I must be doing something really stupid, but... I cannot get any of the changes to my menu items reflected in visual appearance. If I check a menu item, or change string I can see changes if I test in code, but not when I click on the menu bar. I use standard default bar creation in main frame OnCreate:

    CMFCVisualManager::SetDefaultManager(RUNTIME\_CLASS(CMFCVisualManagerWindows));
    if (!m\_wndMenuBar.Create(this))
    {
    	TRACE0("Failed to create menubar\\n");
    	return -1;      // fail to create
    }
    m\_wndMenuBar.SetPaneStyle(m\_wndMenuBar.GetPaneStyle() | CBRS\_SIZE\_DYNAMIC | CBRS\_TOOLTIPS | CBRS\_FLYBY);
    

    I then create a menu message handler in a view and in it I put something like this:

    MENUITEMINFO info;
    TCHAR buf\[32\];
    
    info.cbSize=sizeof(MENUITEMINFO);
    info.fMask=MIIM\_STATE|MIIM\_ID|MIIM\_STRING;
    info.fType=MFT\_STRING;
    info.dwTypeData=0;
    
    HMENU hMenusafe= ((CMainFrame\*)(AfxGetApp()->m\_pMainWnd))->m\_wndMenuBar.GetHMenu();
    HMENU hMenu=::GetSubMenu(hMenusafe,0);
    DWORD err=GetLastError();
    int er=GetMenuItemInfo(hMenu,3,1,&info);
     err=GetLastError();
     info.cch++;
     if( info.cch > 32)
    	  info.cch = 32;
     info.dwTypeData=buf;
     er=GetMenuItemInfo(hMenu,3,1,&info);
     err=GetLastError();
    
    if(info.fState & MFS\_CHECKED)
    {
    	info.fState &=~MFS\_CHECKED;
    	info.fState|=MFS\_UNCHECKED;
    	\_tcscpy(buf,\_T("Menu is unchecked"));
    	info.cch=\_tcslen(buf)+1;		
    }
    else
    {
    	info.fState &=~MFS\_UNCHECKED;
    	info.fState  |=MFS\_CHECKED;
    	\_tcscpy(buf,\_T("Menu is checked"));
    	info.cch=\_tcslen(buf)+1;
    }
    
    er=SetMenuItemInfo(hMenu,3,1,&info);
    ((CMainFrame\*)(AfxGetApp()->m\_pMainWnd))->DrawMenuBar();
    

    As I click on the menu item I never see a check, nor changed text. However as I am stepping through the code debugging, I see that changes did take place. What am I doing wrong? Any help appreciated Henryk

    _ 1 Reply Last reply
    0
    • S soaringpilot

      I must be doing something really stupid, but... I cannot get any of the changes to my menu items reflected in visual appearance. If I check a menu item, or change string I can see changes if I test in code, but not when I click on the menu bar. I use standard default bar creation in main frame OnCreate:

      CMFCVisualManager::SetDefaultManager(RUNTIME\_CLASS(CMFCVisualManagerWindows));
      if (!m\_wndMenuBar.Create(this))
      {
      	TRACE0("Failed to create menubar\\n");
      	return -1;      // fail to create
      }
      m\_wndMenuBar.SetPaneStyle(m\_wndMenuBar.GetPaneStyle() | CBRS\_SIZE\_DYNAMIC | CBRS\_TOOLTIPS | CBRS\_FLYBY);
      

      I then create a menu message handler in a view and in it I put something like this:

      MENUITEMINFO info;
      TCHAR buf\[32\];
      
      info.cbSize=sizeof(MENUITEMINFO);
      info.fMask=MIIM\_STATE|MIIM\_ID|MIIM\_STRING;
      info.fType=MFT\_STRING;
      info.dwTypeData=0;
      
      HMENU hMenusafe= ((CMainFrame\*)(AfxGetApp()->m\_pMainWnd))->m\_wndMenuBar.GetHMenu();
      HMENU hMenu=::GetSubMenu(hMenusafe,0);
      DWORD err=GetLastError();
      int er=GetMenuItemInfo(hMenu,3,1,&info);
       err=GetLastError();
       info.cch++;
       if( info.cch > 32)
      	  info.cch = 32;
       info.dwTypeData=buf;
       er=GetMenuItemInfo(hMenu,3,1,&info);
       err=GetLastError();
      
      if(info.fState & MFS\_CHECKED)
      {
      	info.fState &=~MFS\_CHECKED;
      	info.fState|=MFS\_UNCHECKED;
      	\_tcscpy(buf,\_T("Menu is unchecked"));
      	info.cch=\_tcslen(buf)+1;		
      }
      else
      {
      	info.fState &=~MFS\_UNCHECKED;
      	info.fState  |=MFS\_CHECKED;
      	\_tcscpy(buf,\_T("Menu is checked"));
      	info.cch=\_tcslen(buf)+1;
      }
      
      er=SetMenuItemInfo(hMenu,3,1,&info);
      ((CMainFrame\*)(AfxGetApp()->m\_pMainWnd))->DrawMenuBar();
      

      As I click on the menu item I never see a check, nor changed text. However as I am stepping through the code debugging, I see that changes did take place. What am I doing wrong? Any help appreciated Henryk

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      You need to create a handler for ON_UPDATE_COMMAND_UI. The handler will have a CCmdUI class pointer as its parameter using which you can check the menu item. Here is an article that does this - Using ON_UPDATE_COMMAND_UI with menu items and controls[^]

      «_Superman_»  _I love work. It gives me something to do between weekends.

      _Microsoft MVP (Visual C++)

      Polymorphism in C

      S 1 Reply Last reply
      0
      • _ _Superman_

        You need to create a handler for ON_UPDATE_COMMAND_UI. The handler will have a CCmdUI class pointer as its parameter using which you can check the menu item. Here is an article that does this - Using ON_UPDATE_COMMAND_UI with menu items and controls[^]

        «_Superman_»  _I love work. It gives me something to do between weekends.

        _Microsoft MVP (Visual C++)

        Polymorphism in C

        S Offline
        S Offline
        soaringpilot
        wrote on last edited by
        #3

        Thanks! that works. I guess it is another disconnect in MFC :( .

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups