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. [MFC] Menu headaches

[MFC] Menu headaches

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestionlearning
5 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.
  • M Offline
    M Offline
    Maarten Kools
    wrote on last edited by
    #1

    Hi. I'm translating some menu options and I'm running into a problem with it. I have this menu item, which is a popup menu, inside the Edit menu. For setting menu item text, I have made the following function:

    ASSERT( pMenu != NULL);
    ASSERT( ::IsMenu( pMenu->GetSafeHmenu()) != FALSE);

    UINT nFlags = pMenu->GetMenuState( nPos, MF_BYPOSITION);
    UINT_PTR nNewID = 0;
    if( nFlags & MF_POPUP)
    {
    CMenu *pSubMenu = pMenu->GetSubMenu( nPos);
    ASSERT_VALID( pSubMenu);
    nNewID = (UINT_PTR)pSubMenu->GetSafeHmenu();
    }
    else
    {
    nNewID = pMenu->GetMenuItemID( nPos);
    }

    return (pMenu->ModifyMenu( nPos, nFlags | MF_BYPOSITION, nNewID, inText) != 0);

    This function works fine, I've been using the same function to translate some other menu items (I've added an item next to file, edit, etc.). But for some reason these other menu options end up being empty. But when I try to retrieve the text, with GetMenuString, it shows what I entered in the resource... now, what the heck am I doing wrong here??

    R 1 Reply Last reply
    0
    • M Maarten Kools

      Hi. I'm translating some menu options and I'm running into a problem with it. I have this menu item, which is a popup menu, inside the Edit menu. For setting menu item text, I have made the following function:

      ASSERT( pMenu != NULL);
      ASSERT( ::IsMenu( pMenu->GetSafeHmenu()) != FALSE);

      UINT nFlags = pMenu->GetMenuState( nPos, MF_BYPOSITION);
      UINT_PTR nNewID = 0;
      if( nFlags & MF_POPUP)
      {
      CMenu *pSubMenu = pMenu->GetSubMenu( nPos);
      ASSERT_VALID( pSubMenu);
      nNewID = (UINT_PTR)pSubMenu->GetSafeHmenu();
      }
      else
      {
      nNewID = pMenu->GetMenuItemID( nPos);
      }

      return (pMenu->ModifyMenu( nPos, nFlags | MF_BYPOSITION, nNewID, inText) != 0);

      This function works fine, I've been using the same function to translate some other menu items (I've added an item next to file, edit, etc.). But for some reason these other menu options end up being empty. But when I try to retrieve the text, with GetMenuString, it shows what I entered in the resource... now, what the heck am I doing wrong here??

      R Offline
      R Offline
      Roger Allen
      wrote on last edited by
      #2

      Not 100% sure what you mean in your question, but do you need to use the MF_STRING flag in the ModifyMenu call? Roger Allen - Sonork 100.10016 Strong Sad: I am sad I am flying Who is your favorite Strong?

      M 1 Reply Last reply
      0
      • R Roger Allen

        Not 100% sure what you mean in your question, but do you need to use the MF_STRING flag in the ModifyMenu call? Roger Allen - Sonork 100.10016 Strong Sad: I am sad I am flying Who is your favorite Strong?

        M Offline
        M Offline
        Maarten Kools
        wrote on last edited by
        #3

        I've tried that too, result is the same. It's a bit of a strange case. I'm basically translating every menu option, and for the top level menus (file, edit, view, etc.) I'm using the function I posted in my original message. The menu items that are there by standard (file, edit, etc.) are done fine, I can change the translation and it would show up differently. However, I've added one extra item called Production, when using the same function as all the others, I end up having an empty menu option. Let me try to get a screenshot online: Picture Between Tools and Window there's an item missing: Production And at the bottom of the picture, I'm obviously missing text... But like I said, if I change the translation for like tools or something, which uses the same function, it does work..:confused:

        R 1 Reply Last reply
        0
        • M Maarten Kools

          I've tried that too, result is the same. It's a bit of a strange case. I'm basically translating every menu option, and for the top level menus (file, edit, view, etc.) I'm using the function I posted in my original message. The menu items that are there by standard (file, edit, etc.) are done fine, I can change the translation and it would show up differently. However, I've added one extra item called Production, when using the same function as all the others, I end up having an empty menu option. Let me try to get a screenshot online: Picture Between Tools and Window there's an item missing: Production And at the bottom of the picture, I'm obviously missing text... But like I said, if I change the translation for like tools or something, which uses the same function, it does work..:confused:

          R Offline
          R Offline
          Roger Allen
          wrote on last edited by
          #4

          One possible reason is that as your setting the test of a popup menu item, such items always have an ID of -1 or 0 (I forget which). This means that you may be corrupting the item by setting a new WM_COMMAND ID for the popup menu item to something other than -1/0. Also, are you calling DrawMenuBar() after all your changes to the menu as you should do if you change the visual aspect of a menu item. Roger Allen - Sonork 100.10016 Strong Sad: I am sad I am flying Who is your favorite Strong?

          M 1 Reply Last reply
          0
          • R Roger Allen

            One possible reason is that as your setting the test of a popup menu item, such items always have an ID of -1 or 0 (I forget which). This means that you may be corrupting the item by setting a new WM_COMMAND ID for the popup menu item to something other than -1/0. Also, are you calling DrawMenuBar() after all your changes to the menu as you should do if you change the visual aspect of a menu item. Roger Allen - Sonork 100.10016 Strong Sad: I am sad I am flying Who is your favorite Strong?

            M Offline
            M Offline
            Maarten Kools
            wrote on last edited by
            #5

            According to MSDN I'm supposed to pass on a menu handle (HMENU) of the popup for any menu items which have the MF_POPUP flag set. I'm not entirely sure what you mean with the new command ID otherwise? I'm not calling DrawMenuBar(), no. I tried that before, but that didn't seem to make any difference. Everything else works without calling it, so it didn't seem necessary. MSDN says I should, but like I said, there's no difference.

            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