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. Addstring function

Addstring function

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
13 Posts 6 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.
  • K khb

    I guess you have to call the CListBox member function Create(...) before adding items to the list. Regards Marcus

    T Offline
    T Offline
    tyagineha
    wrote on last edited by
    #3

    why and how??????????????? NT

    K J 2 Replies Last reply
    0
    • T tyagineha

      why and how??????????????? NT

      K Offline
      K Offline
      khb
      wrote on last edited by
      #4

      Before calling Create(...) no window exists for the list box. And you can't add items to the list before creating a corresponding window. See MSDN for how to use the function. Regards, Marcus.

      1 Reply Last reply
      0
      • T tyagineha

        why and how??????????????? NT

        J Offline
        J Offline
        jhwurmbach
        wrote on last edited by
        #5

        Did your MyListBox class derive from CListBox? Then the Create()-code should already be there and be used. But then you could simply write AddString() in you class function, as "public derivation" means the derived class *IS A* base class in every respect.


        Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
        George Orwell, "Keep the Aspidistra Flying", Opening words

        T 1 Reply Last reply
        0
        • T tyagineha

          i want to diaplay a modeless listbox on button click.i m gvng my listbox which in one class from some other class. i hav made a new class in which i have made my own addstring function which is like this: int CMyList::Addition(LPCTSTR lpszItem) { return CListBox::AddString(lpszItem); } i have declared an object of CMyList as: CMyList myobj; obj.Addition("hye"); but i m getting exception error. can anyone tell me how to rectify this exception. is there any other method to do so?? NT

          K Offline
          K Offline
          KarstenK
          wrote on last edited by
          #6

          Learn to better look at the exception, I think the ASSERT is yelling coz theres is not window. In Window you gotta create first the window and THEN work with them. I do loading often in the CWnd::OnShowWindow(...) function

          Greetings from Germany

          D 1 Reply Last reply
          0
          • J jhwurmbach

            Did your MyListBox class derive from CListBox? Then the Create()-code should already be there and be used. But then you could simply write AddString() in you class function, as "public derivation" means the derived class *IS A* base class in every respect.


            Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
            George Orwell, "Keep the Aspidistra Flying", Opening words

            T Offline
            T Offline
            tyagineha
            wrote on last edited by
            #7

            yes i have derived my new class from CListBox nw do i hav to use create() function???????? NT

            J K 2 Replies Last reply
            0
            • T tyagineha

              yes i have derived my new class from CListBox nw do i hav to use create() function???????? NT

              J Offline
              J Offline
              jhwurmbach
              wrote on last edited by
              #8

              Yes. When you want to Create your Listbox. From your description, that would be the button-click-handler. Remember, though, that a local MyListBox variable would be destroyed on leaving the Button-click-handler. But you wanted your ListBox modeless and staying on the screen even when your program continues. You would possibly need to make a member variable in its parent for it.


              Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
              George Orwell, "Keep the Aspidistra Flying", Opening words

              1 Reply Last reply
              0
              • T tyagineha

                yes i have derived my new class from CListBox nw do i hav to use create() function???????? NT

                K Offline
                K Offline
                khb
                wrote on last edited by
                #9

                It depends. If in your case myobj is a member of your dialog where the list box belongs to and if myobj is associated with that list box, then no. If you created myobj in some function locally, then yes. Maybe you can have a look at the MFC Controls -> List controls section for some sample code to study. Regards Marcus

                1 Reply Last reply
                0
                • K KarstenK

                  Learn to better look at the exception, I think the ASSERT is yelling coz theres is not window. In Window you gotta create first the window and THEN work with them. I do loading often in the CWnd::OnShowWindow(...) function

                  Greetings from Germany

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

                  KarstenK wrote:

                  Learn to better look at the exception, I think the ASSERT...

                  While it very well may be an assertion that fired (i.e., nonexistent window), the OP stated it was an exception that was thrown.


                  "A good athlete is the result of a good and worthy opponent." - David Crow

                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                  1 Reply Last reply
                  0
                  • T tyagineha

                    i want to diaplay a modeless listbox on button click.i m gvng my listbox which in one class from some other class. i hav made a new class in which i have made my own addstring function which is like this: int CMyList::Addition(LPCTSTR lpszItem) { return CListBox::AddString(lpszItem); } i have declared an object of CMyList as: CMyList myobj; obj.Addition("hye"); but i m getting exception error. can anyone tell me how to rectify this exception. is there any other method to do so?? NT

                    J Offline
                    J Offline
                    Jim Crafton
                    wrote on last edited by
                    #11

                    Get a book on MFC. You're not using the class correctly in the first place. All MFC objects that wrap Win32 primitives like HWND, HDC, etc, have a similar pattern: CWnd wnd; //make a new instance or CWnd* wnd = new CWnd(); //"create" the instance wnd.Create(......); or wnd->Create(.....);

                    ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF! VCF Blog

                    T 1 Reply Last reply
                    0
                    • J Jim Crafton

                      Get a book on MFC. You're not using the class correctly in the first place. All MFC objects that wrap Win32 primitives like HWND, HDC, etc, have a similar pattern: CWnd wnd; //make a new instance or CWnd* wnd = new CWnd(); //"create" the instance wnd.Create(......); or wnd->Create(.....);

                      ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF! VCF Blog

                      T Offline
                      T Offline
                      tyagineha
                      wrote on last edited by
                      #12

                      can i use DoModal function... i dnt knw how to use create...can anybody tell me???? NT

                      J 1 Reply Last reply
                      0
                      • T tyagineha

                        can i use DoModal function... i dnt knw how to use create...can anybody tell me???? NT

                        J Offline
                        J Offline
                        Jim Crafton
                        wrote on last edited by
                        #13

                        Again, you're using terms incorrectly. Saying you want to use a "modeless listbox" doesn't make any sense. I suspect what you want is to display a modeless *dialog* with a list box in it. Look up CDialog, and the differences between DoModal and a modeless dialog in MSDN.

                        ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF! VCF Blog

                        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