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. Dynamic menus

Dynamic menus

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialgraphicsquestion
6 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.
  • E Offline
    E Offline
    electronicman_x
    wrote on last edited by
    #1

    I'm trying to implement a dynamic menu system to my program. Currently, i can add and remove the items from the menu, and make the menu items run code that i've premade. for example i can add "section 1" to a section menu, while associating ID_SECTION_1 to the command in the menu. This will call my OnSection1() code when this command is executed. I want this to be boundless (i.e. i dont want to have to make code for OnSection2, OnSection3, OnSection4... , or the strings in the string table, and so on.) I can currently bind each new menu item to the same id, for example section 1, section 2, and section 3 all run the OnSection() command which is bound to ID_SECTION. What i cannot do, is figure out how to determine which of the 3 i called. I would like to basically get the location of the last menu choice i picked, so if section 2 is in the second spot on the menu, i want to know this when i call OnSection(). Any ideas? Jeff Rothenberg Project Engineer Vector CANtech, Inc.

    L R 2 Replies Last reply
    0
    • E electronicman_x

      I'm trying to implement a dynamic menu system to my program. Currently, i can add and remove the items from the menu, and make the menu items run code that i've premade. for example i can add "section 1" to a section menu, while associating ID_SECTION_1 to the command in the menu. This will call my OnSection1() code when this command is executed. I want this to be boundless (i.e. i dont want to have to make code for OnSection2, OnSection3, OnSection4... , or the strings in the string table, and so on.) I can currently bind each new menu item to the same id, for example section 1, section 2, and section 3 all run the OnSection() command which is bound to ID_SECTION. What i cannot do, is figure out how to determine which of the 3 i called. I would like to basically get the location of the last menu choice i picked, so if section 2 is in the second spot on the menu, i want to know this when i call OnSection(). Any ideas? Jeff Rothenberg Project Engineer Vector CANtech, Inc.

      L Offline
      L Offline
      l a u r e n
      wrote on last edited by
      #2

      why dont u store the currently displayed option on the menu as a numeric index somewhere and use a switch staement in the code to determine what to do?


      "traffic lights are for people who can't make their own decisions"
      biz stuff   about me

      E 1 Reply Last reply
      0
      • L l a u r e n

        why dont u store the currently displayed option on the menu as a numeric index somewhere and use a switch staement in the code to determine what to do?


        "traffic lights are for people who can't make their own decisions"
        biz stuff   about me

        E Offline
        E Offline
        electronicman_x
        wrote on last edited by
        #3

        How can i get the currently displayed option? Jeff Rothenberg Project Engineer Vector CANtech, Inc.

        L 1 Reply Last reply
        0
        • E electronicman_x

          How can i get the currently displayed option? Jeff Rothenberg Project Engineer Vector CANtech, Inc.

          L Offline
          L Offline
          l a u r e n
          wrote on last edited by
          #4

          well ur setting the menu text right? so save a value somewhere else when u change the menu text that lets u know which option is showing ?


          "traffic lights are for people who can't make their own decisions"
          biz stuff   about me

          E 1 Reply Last reply
          0
          • L l a u r e n

            well ur setting the menu text right? so save a value somewhere else when u change the menu text that lets u know which option is showing ?


            "traffic lights are for people who can't make their own decisions"
            biz stuff   about me

            E Offline
            E Offline
            electronicman_x
            wrote on last edited by
            #5

            Many options will be showing, and i basically need to record the actual text that shows up in the menu. I cannot save the index value when i set the menu text, because i do not know which item will be chosen. I want the menu text simply to help me figure out which one i actually chose. For example File Edit Sections ->Section 1 I do something and create 3 more sections at runtime modifying the menu. Now the menu looks like this Sections ->Section 1 ->Section 2 ->Section 3 ->Section 4 Each Menu choice is bound to ID_SECTION. ID_SECTION corresponds to OnSection() In my code: void OnSection() { int section; // I need to fill the section variable with // the index of the item i picked from the menu // since all of them have the same ID. If(section==1) handle section 1 If(section==2) handle section 2 If(section==3) handle section 3 If(section==4) handle section 4 } Hopefully this helps. Thanks. Jeff Rothenberg Project Engineer Vector CANtech, Inc.

            1 Reply Last reply
            0
            • E electronicman_x

              I'm trying to implement a dynamic menu system to my program. Currently, i can add and remove the items from the menu, and make the menu items run code that i've premade. for example i can add "section 1" to a section menu, while associating ID_SECTION_1 to the command in the menu. This will call my OnSection1() code when this command is executed. I want this to be boundless (i.e. i dont want to have to make code for OnSection2, OnSection3, OnSection4... , or the strings in the string table, and so on.) I can currently bind each new menu item to the same id, for example section 1, section 2, and section 3 all run the OnSection() command which is bound to ID_SECTION. What i cannot do, is figure out how to determine which of the 3 i called. I would like to basically get the location of the last menu choice i picked, so if section 2 is in the second spot on the menu, i want to know this when i call OnSection(). Any ideas? Jeff Rothenberg Project Engineer Vector CANtech, Inc.

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

              You should be able to use GetCurrentMessage() and interrogate the wParam/lParam values to get the actual command ID of the menu option selecetd. Roger Allen Sonork 100.10016 This is a multiple choice question, choose wisely Why did the hedgehog cross the road? A: To show he had guts? B: To see his flat mate?

              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