Dialog List Problem
-
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
-
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
where does the assert happen ? Cleek | Image Toolkits | Thumbnail maker
-
where does the assert happen ? Cleek | Image Toolkits | Thumbnail maker
-
where does the assert happen ? Cleek | Image Toolkits | Thumbnail maker
-
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
_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
-
_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
-
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
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
-
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
The debug version
ASSERT
s because the window hasn't been created yet. In the release version, theASSERT
doesn't fire, and theSendMessage
call silently fails. In this case, the control eventually gets created, but the string you're looking for isn't there due to the earlierSendMessage
failure.
Software Zen:
delete this;