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. Getting the menu option from CMenu

Getting the menu option from CMenu

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
4 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.
  • L Offline
    L Offline
    Lilian Chan Grant
    wrote on last edited by
    #1

    CRect rect; int x; int l; int y; BSTR string = NULL; pPopupMenu.CreatePopupMenu(); GetWindowRect(&rect); x = rect.right < 0 ? 0 : rect.right; l = rect.left < 0 ? 0: rect.left; if ((x-l) > 700) x = (l+x) / 2; y = rect.bottom; CMenu pPopupMenu; pPopupMenu.CreatePopupMenu(); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option1"); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option2"); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option3"); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option4"); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option5"); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option6"); iStatus = pPopupMenu.TrackPopupMenu(TPM_RIGHTALIGN | TPM_LEFTBUTTON, x, y, m_hWnd); iStatus = pPopupMenu.GetMenuString(1, string, MF_BYPOSITION); Can someone tell me how to get the the position the cursor is on? I need to get which option was chosen. Forever ignorant, Lilian

    N R 2 Replies Last reply
    0
    • L Lilian Chan Grant

      CRect rect; int x; int l; int y; BSTR string = NULL; pPopupMenu.CreatePopupMenu(); GetWindowRect(&rect); x = rect.right < 0 ? 0 : rect.right; l = rect.left < 0 ? 0: rect.left; if ((x-l) > 700) x = (l+x) / 2; y = rect.bottom; CMenu pPopupMenu; pPopupMenu.CreatePopupMenu(); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option1"); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option2"); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option3"); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option4"); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option5"); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option6"); iStatus = pPopupMenu.TrackPopupMenu(TPM_RIGHTALIGN | TPM_LEFTBUTTON, x, y, m_hWnd); iStatus = pPopupMenu.GetMenuString(1, string, MF_BYPOSITION); Can someone tell me how to get the the position the cursor is on? I need to get which option was chosen. Forever ignorant, Lilian

      N Offline
      N Offline
      Niklas L
      wrote on last edited by
      #2

      You don't really need too keep track of the mouse pointer location. Add a command handler for WM_COMMAND and the selection will be sent there. Of course you'll have to set different IDs to AppendMenu(MF_STRING, **WM_OPTION1**, "O1"). These IDs will be sent in the WPARAM (?) to your command handler.

      1 Reply Last reply
      0
      • L Lilian Chan Grant

        CRect rect; int x; int l; int y; BSTR string = NULL; pPopupMenu.CreatePopupMenu(); GetWindowRect(&rect); x = rect.right < 0 ? 0 : rect.right; l = rect.left < 0 ? 0: rect.left; if ((x-l) > 700) x = (l+x) / 2; y = rect.bottom; CMenu pPopupMenu; pPopupMenu.CreatePopupMenu(); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option1"); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option2"); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option3"); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option4"); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option5"); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option6"); iStatus = pPopupMenu.TrackPopupMenu(TPM_RIGHTALIGN | TPM_LEFTBUTTON, x, y, m_hWnd); iStatus = pPopupMenu.GetMenuString(1, string, MF_BYPOSITION); Can someone tell me how to get the the position the cursor is on? I need to get which option was chosen. Forever ignorant, Lilian

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

        The value of iStatus will be the ID of the selected item, or 0 if he mehu was aborted so

        if (iStatus != 0)
        iStatus = pPopupMenu.GetMenuString(iStatus, string, MF_BYCOMMAND);

        Should do the trick You also need to add each item to the menu with a unique ID

        iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option1");
        iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER+1, L"Option2"); // +2...

        Roger Allen Sonork 100.10016 yet to be identified being from the planet Paltinmoriumbanfrettybooter

        L 1 Reply Last reply
        0
        • R Roger Allen

          The value of iStatus will be the ID of the selected item, or 0 if he mehu was aborted so

          if (iStatus != 0)
          iStatus = pPopupMenu.GetMenuString(iStatus, string, MF_BYCOMMAND);

          Should do the trick You also need to add each item to the menu with a unique ID

          iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option1");
          iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER+1, L"Option2"); // +2...

          Roger Allen Sonork 100.10016 yet to be identified being from the planet Paltinmoriumbanfrettybooter

          L Offline
          L Offline
          Lilian Chan Grant
          wrote on last edited by
          #4

          Thanks for the help, y'all. I got something working using the message handler. :)

          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