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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Can I get to submenu of a submenu? ( MFC VC 6.0)

Can I get to submenu of a submenu? ( MFC VC 6.0)

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
5 Posts 3 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.
  • V Offline
    V Offline
    Vaclav_
    wrote on last edited by
    #1

    I would like to dynamically create menu items attached to a submenu of a submenu. I can get access to the first level of submenu using GetSubMenu, but cannot get to the second level probably because this function returns CTempMenu. Both submenus are pop-up, but I must be must be missing something else here. Here is my test code snippet which asserts on pSubSubMenu CMenu *pSubMenu,*pSubSubMenu; int iCount = pMenu->GetMenuItemCount(); if (pMenu != NULL && pMenu->GetMenuItemCount() > 0) { pSubMenu = pMenu->GetSubMenu(2); ASSERT(pSubMenu); } pSubSubMenu = pSubMenu->GetSubMenu(0); ASSERT( pSubSubMenu); Any suggestions will be as always appreciated. Cheers Vaclav

    Can I get submenu of a submenu? ( MFC VC 6.0)
    I woul like to dynamically create menu items attached to a submenu of a submenu.
    I can get access to first level of submenu using GetSubMenu, but cannot get to the second level probably because this function returns CTempMenu. Both submenus are pop-up, but I must be must be missing something else here.
    Here is the code snippet which asserts on pSubSubMenu

    CMenu \*pSubMenu,\*pSubSubMenu;
    int iCount = pMenu->GetMenuItemCount();
    

    if (pMenu != NULL && pMenu->GetMenuItemCount() > 0)
    {
    pSubMenu = pMenu->GetSubMenu(2);
    ASSERT(pSubMenu);
    }
    pSubSubMenu = pSubMenu->GetSubMenu(0);
    ASSERT( pSubSubMenu);
    Any suggestions will be as always appreciated.
    Cheers
    Vaclav

    L 1 Reply Last reply
    0
    • V Vaclav_

      I would like to dynamically create menu items attached to a submenu of a submenu. I can get access to the first level of submenu using GetSubMenu, but cannot get to the second level probably because this function returns CTempMenu. Both submenus are pop-up, but I must be must be missing something else here. Here is my test code snippet which asserts on pSubSubMenu CMenu *pSubMenu,*pSubSubMenu; int iCount = pMenu->GetMenuItemCount(); if (pMenu != NULL && pMenu->GetMenuItemCount() > 0) { pSubMenu = pMenu->GetSubMenu(2); ASSERT(pSubMenu); } pSubSubMenu = pSubMenu->GetSubMenu(0); ASSERT( pSubSubMenu); Any suggestions will be as always appreciated. Cheers Vaclav

      Can I get submenu of a submenu? ( MFC VC 6.0)
      I woul like to dynamically create menu items attached to a submenu of a submenu.
      I can get access to first level of submenu using GetSubMenu, but cannot get to the second level probably because this function returns CTempMenu. Both submenus are pop-up, but I must be must be missing something else here.
      Here is the code snippet which asserts on pSubSubMenu

      CMenu \*pSubMenu,\*pSubSubMenu;
      int iCount = pMenu->GetMenuItemCount();
      

      if (pMenu != NULL && pMenu->GetMenuItemCount() > 0)
      {
      pSubMenu = pMenu->GetSubMenu(2);
      ASSERT(pSubMenu);
      }
      pSubSubMenu = pSubMenu->GetSubMenu(0);
      ASSERT( pSubSubMenu);
      Any suggestions will be as always appreciated.
      Cheers
      Vaclav

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Hi, To avoid the temporary handle and CTempMenu you can use CMenu::GetSafeHmenu[^] to get a permanent handle. You would then call CMenu::Attach[^] to attach to a CMenu object and then manipulate the menu. Best Wishes, -David Delaune

      M 1 Reply Last reply
      0
      • L Lost User

        Hi, To avoid the temporary handle and CTempMenu you can use CMenu::GetSafeHmenu[^] to get a permanent handle. You would then call CMenu::Attach[^] to attach to a CMenu object and then manipulate the menu. Best Wishes, -David Delaune

        M Offline
        M Offline
        mistletoe_dean
        wrote on last edited by
        #3

        I think you can try use GetSubMenu() twice to get submenu of a submenu. :)

        V 1 Reply Last reply
        0
        • M mistletoe_dean

          I think you can try use GetSubMenu() twice to get submenu of a submenu. :)

          V Offline
          V Offline
          Vaclav_
          wrote on last edited by
          #4

          Thanks guys, there is a minor "problem" with building / attaching permanent handle - it is already attached to window as m_hMenu data memeber of CMenu. I tryed to use it with same results - the second level always returns NULL. The strange part is that docs saiz if the popup submenu does not exist it will create it. But even than it returns NULL. I would like to use that handle to get to next submenu, but I feel I need to look into what message(s) are being posted when the mouse goes over the menu items and try to process those instead. I also forgot to say that I am using OnInitMenu in main frame which runs only once.

          V 1 Reply Last reply
          0
          • V Vaclav_

            Thanks guys, there is a minor "problem" with building / attaching permanent handle - it is already attached to window as m_hMenu data memeber of CMenu. I tryed to use it with same results - the second level always returns NULL. The strange part is that docs saiz if the popup submenu does not exist it will create it. But even than it returns NULL. I would like to use that handle to get to next submenu, but I feel I need to look into what message(s) are being posted when the mouse goes over the menu items and try to process those instead. I also forgot to say that I am using OnInitMenu in main frame which runs only once.

            V Offline
            V Offline
            Vaclav_
            wrote on last edited by
            #5

            Here is what works, still not sure why I could not use m_hMenu similar way. Basically a copy of MFC code. HMENU hMenu = pSubMenu->GetSafeHmenu(); pSubSubMenu = pSubMenu->FromHandle(hMenu)->GetSubMenu(2); ASSERT(pSubSubMenu); Thanks for all the help I got, you guys are great! Cheers Vaclav

            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