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. Using Created() CListBox

Using Created() CListBox

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestionc++
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.
  • G Offline
    G Offline
    gokings
    wrote on last edited by
    #1

    I have a rather basic MFC question. It is clear to me how to use the Create() method of a CListBox to create one. It is not clear to me what to do with it after it is created. As far as I know, it does not have a DoModal() method as a CDialog object does or something analogous to the TrackPopupMenu() method of a CMenu object. Does anyone have an example Creating and displaying a CListBox? I want the CListBox to "return" when the user makes a selection, and then to inquire of the CListBox which selection was made. Thanks

    D C 2 Replies Last reply
    0
    • G gokings

      I have a rather basic MFC question. It is clear to me how to use the Create() method of a CListBox to create one. It is not clear to me what to do with it after it is created. As far as I know, it does not have a DoModal() method as a CDialog object does or something analogous to the TrackPopupMenu() method of a CMenu object. Does anyone have an example Creating and displaying a CListBox? I want the CListBox to "return" when the user makes a selection, and then to inquire of the CListBox which selection was made. Thanks

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      My first question would be why are you creating it dynamically instead of making it part of the dialog template? gokings wrote: It is not clear to me what to do with it after it is created. Add items to it, or perhaps I don't quite understand your question. gokings wrote: As far as I know, it does not have a DoModal() method as a CDialog object does or something analogous to the TrackPopupMenu() method of a CMenu object. Why are you comparing it to a CDialog or CMenu object? A listbox is a control that is placed on a dialog and enables the user to choose one option from a list of possibilities. gokings wrote: Does anyone have an example Creating and displaying a CListBox? It's such a common control that examples are everywhere. Search here at CP for starters, and then Google for even more. gokings wrote: I want the CListBox to "return" when the user makes a selection, and then to inquire of the CListBox which selection was made. The analogy of "returning" when the user makes a selection makes no sense. When a selection is made from a listbox, the dialog will receive a LBN_SELCHANGE message. If you are using MFC, the dialog will need a ON_LBN_SELCHANGE handler instead. At that point, you can get the text and/or index of the currently selected item.


      "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

      G 1 Reply Last reply
      0
      • D David Crow

        My first question would be why are you creating it dynamically instead of making it part of the dialog template? gokings wrote: It is not clear to me what to do with it after it is created. Add items to it, or perhaps I don't quite understand your question. gokings wrote: As far as I know, it does not have a DoModal() method as a CDialog object does or something analogous to the TrackPopupMenu() method of a CMenu object. Why are you comparing it to a CDialog or CMenu object? A listbox is a control that is placed on a dialog and enables the user to choose one option from a list of possibilities. gokings wrote: Does anyone have an example Creating and displaying a CListBox? It's such a common control that examples are everywhere. Search here at CP for starters, and then Google for even more. gokings wrote: I want the CListBox to "return" when the user makes a selection, and then to inquire of the CListBox which selection was made. The analogy of "returning" when the user makes a selection makes no sense. When a selection is made from a listbox, the dialog will receive a LBN_SELCHANGE message. If you are using MFC, the dialog will need a ON_LBN_SELCHANGE handler instead. At that point, you can get the text and/or index of the currently selected item.


        "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

        G Offline
        G Offline
        gokings
        wrote on last edited by
        #3

        The crux of the matter is that I want to display a popup menu, but the CMenu class has limitations making it unsuitable for my needs. Someone suggested that I use a Listbox instead of a Menu. From this I assumed that a Listbox could exist independently of a dialog box. Realizing that this is not the case makes everything fall into place. As for not knowing what to do with a Listbox once it was created, in the context of my question I meant how to cause it to interact with the user. It seems to me that it could be attached at run time to any window, such as a FrameWnd, but perhaps it must be part of a dialog as you indicate. As far as examples being everywhere, if what you say is true, there are no examples of doing what I wanted to do, as it can't be done. I don't need an example of creating a Listbox on a dialog, a monkey could figure that out without an example. Yes, I am aware of handling ON_LBN_SELCHANGE, but I was hoping that there was a "modal" alternative. Regards

        D 1 Reply Last reply
        0
        • G gokings

          The crux of the matter is that I want to display a popup menu, but the CMenu class has limitations making it unsuitable for my needs. Someone suggested that I use a Listbox instead of a Menu. From this I assumed that a Listbox could exist independently of a dialog box. Realizing that this is not the case makes everything fall into place. As for not knowing what to do with a Listbox once it was created, in the context of my question I meant how to cause it to interact with the user. It seems to me that it could be attached at run time to any window, such as a FrameWnd, but perhaps it must be part of a dialog as you indicate. As far as examples being everywhere, if what you say is true, there are no examples of doing what I wanted to do, as it can't be done. I don't need an example of creating a Listbox on a dialog, a monkey could figure that out without an example. Yes, I am aware of handling ON_LBN_SELCHANGE, but I was hoping that there was a "modal" alternative. Regards

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          gokings wrote: ...but the CMenu class has limitations making it unsuitable for my needs. What is it that you are needing that a popup menu cannot provide? I'm just curious if there are some other options that can also be explored. gokings wrote: It seems to me that it could be attached at run time to any window, such as a FrameWnd, but perhaps it must be part of a dialog as you indicate. I don't think a dialog is a requirement, but it is the most common.


          "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

          G 1 Reply Last reply
          0
          • G gokings

            I have a rather basic MFC question. It is clear to me how to use the Create() method of a CListBox to create one. It is not clear to me what to do with it after it is created. As far as I know, it does not have a DoModal() method as a CDialog object does or something analogous to the TrackPopupMenu() method of a CMenu object. Does anyone have an example Creating and displaying a CListBox? I want the CListBox to "return" when the user makes a selection, and then to inquire of the CListBox which selection was made. Thanks

            C Offline
            C Offline
            cmk
            wrote on last edited by
            #5

            In context with your previous question and my reply ... Probably the easiest way for you would be to derive a new control from CListBox that handles the various selection (or return, escape, ...) messages and have them set a variable to the selected value then destroy or hide the window. Hiding/showing the window may be preferable if the list has many items, but requires a little more code to set up. ...cmk Save the whales - collect the whole set

            1 Reply Last reply
            0
            • D David Crow

              gokings wrote: ...but the CMenu class has limitations making it unsuitable for my needs. What is it that you are needing that a popup menu cannot provide? I'm just curious if there are some other options that can also be explored. gokings wrote: It seems to me that it could be attached at run time to any window, such as a FrameWnd, but perhaps it must be part of a dialog as you indicate. I don't think a dialog is a requirement, but it is the most common.


              "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

              G Offline
              G Offline
              gokings
              wrote on last edited by
              #6

              I was able to make a CMenu work, thank you. The issue was that the entries to be placed in the menu were dynamically determined at run time. Having a method for each possible message didn't seem clean, and would have limited me to a maximum number of entries in the menu. cmk suggested that I use a method which handled a command range. Being an MFC neophyte, I was unaware of this possibility (and specifically that the command id was a parm to the method). This solved the problem. Thanks.

              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