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. Dialog List Problem

Dialog List Problem

Scheduled Pinned Locked Moved C / C++ / MFC
debugginghelpquestionlearning
8 Posts 4 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.
  • B Offline
    B Offline
    bugDanny
    wrote on last edited by
    #1

    I’m trying to use a list box control in a windows app I’m writing. I put on the control on my dialog resource, I assign it a member variable: as a control, CListBox. But in my code, when I try to use the function AddString (i.e. dlg.m_variableName.AddString(“Some Letters”) ) I get a debug assertion failure. Maybe I’m missing a step here? Is there more initialization I have to do? I don’t really need the selectability of a list box. I tried just making it an edit box with a scroll bar, but I can’t get each item on a new line. Danny

    C D 2 Replies Last reply
    0
    • B bugDanny

      I’m trying to use a list box control in a windows app I’m writing. I put on the control on my dialog resource, I assign it a member variable: as a control, CListBox. But in my code, when I try to use the function AddString (i.e. dlg.m_variableName.AddString(“Some Letters”) ) I get a debug assertion failure. Maybe I’m missing a step here? Is there more initialization I have to do? I don’t really need the selectability of a list box. I tried just making it an edit box with a scroll bar, but I can’t get each item on a new line. Danny

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      where does the assert happen ? Cleek | Image Toolkits | Thumbnail maker

      B 2 Replies Last reply
      0
      • C Chris Losinger

        where does the assert happen ? Cleek | Image Toolkits | Thumbnail maker

        B Offline
        B Offline
        bugDanny
        wrote on last edited by
        #3

        Chris Losinger wrote: where does the assert happen ? The simple answer? Somewhere in the AddString method. The more complicated answer? The debug pop up tells me the assertion failed at afxwin2.inl at line 669. Danny

        C 1 Reply Last reply
        0
        • C Chris Losinger

          where does the assert happen ? Cleek | Image Toolkits | Thumbnail maker

          B Offline
          B Offline
          bugDanny
          wrote on last edited by
          #4

          Alternatively, the release version works, or rather, survives. It works with the exception of the text that I wanted to put in the list box is not there. Danny

          G 1 Reply Last reply
          0
          • B bugDanny

            Chris Losinger wrote: where does the assert happen ? The simple answer? Somewhere in the AddString method. The more complicated answer? The debug pop up tells me the assertion failed at afxwin2.inl at line 669. Danny

            C Offline
            C Offline
            Chris Losinger
            wrote on last edited by
            #5

            _AFXWIN_INLINE int CListBox::AddString(LPCTSTR lpszItem)
            { ASSERT(::IsWindow(m_hWnd)); return (int)::SendMessage(m_hWnd, LB_ADDSTRING, 0, (LPARAM)lpszItem); }

            it's failing because the CListBox isn't a window (yet). i'm guessing you're calling AddString before the dialog has had a chance to create the list box and/or associate it with your member variable. put a breakpoint on your AddString and one in your dialog's OnInitDialog. if the AddString breakpoint hits first, you need to move it to after the dialog has been initialized. Cleek | Image Toolkits | Thumbnail maker

            B 1 Reply Last reply
            0
            • C Chris Losinger

              _AFXWIN_INLINE int CListBox::AddString(LPCTSTR lpszItem)
              { ASSERT(::IsWindow(m_hWnd)); return (int)::SendMessage(m_hWnd, LB_ADDSTRING, 0, (LPARAM)lpszItem); }

              it's failing because the CListBox isn't a window (yet). i'm guessing you're calling AddString before the dialog has had a chance to create the list box and/or associate it with your member variable. put a breakpoint on your AddString and one in your dialog's OnInitDialog. if the AddString breakpoint hits first, you need to move it to after the dialog has been initialized. Cleek | Image Toolkits | Thumbnail maker

              B Offline
              B Offline
              bugDanny
              wrote on last edited by
              #6

              Thanks! Danny

              1 Reply Last reply
              0
              • B bugDanny

                I’m trying to use a list box control in a windows app I’m writing. I put on the control on my dialog resource, I assign it a member variable: as a control, CListBox. But in my code, when I try to use the function AddString (i.e. dlg.m_variableName.AddString(“Some Letters”) ) I get a debug assertion failure. Maybe I’m missing a step here? Is there more initialization I have to do? I don’t really need the selectability of a list box. I tried just making it an edit box with a scroll bar, but I can’t get each item on a new line. Danny

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

                bugDanny wrote: But in my code, when I try to use the function AddString Make sure you are doing this in the dialog's OnInitDialog() method, after the default method has been called.


                "One must learn from the bite of the fire to leave it alone." - Native American Proverb

                1 Reply Last reply
                0
                • B bugDanny

                  Alternatively, the release version works, or rather, survives. It works with the exception of the text that I wanted to put in the list box is not there. Danny

                  G Offline
                  G Offline
                  Gary R Wheeler
                  wrote on last edited by
                  #8

                  The debug version ASSERTs because the window hasn't been created yet. In the release version, the ASSERT doesn't fire, and the SendMessage call silently fails. In this case, the control eventually gets created, but the string you're looking for isn't there due to the earlier SendMessage failure.


                  Software Zen: delete this;

                  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