如Dialog  中一CListBox 控件   m_listbox   
我在网上很久都说:
CString   strText; 
m_listbox.GetText(m_listbox.GetCurSel(),   strText);
可我用了这方法可是,编译、执行没错误,但运行中的时候就有错误,如图
http://qpic.cn/404NKhO3
本人初学,可能也是本人操作错误,最好写出详细步骤,谢谢各位了!

解决方案 »

  1.   

    估计你这个m_listbox还没有创建,句柄为空;或者m_listbox.GetCurSel()的返回值为-1,根本没有选中内容。
      

  2.   


    CString strText;
    int nIndex = m_listbox.GetCurSel();
    m_listbox.GetText(nIndex, strText);单步调试看看,是哪里出错
    说不定是代码的其他地方
      

  3.   

    请问“m_listbox还没有创建”是不是指CLisBox对其创建(CLisBox m_listbox)?
      

  4.   

    在classwizard里进行变量关联设置就行了
    我还以为你定义好了的呢
      

  5.   

    如果你的代码是这样的:
    CListBox m_listbox;
    m_listbox.GetCurSel();
    那就不行。
    如果你的m_listbox是在对话框类中用classwizard为控件绑定的变量,并且你的这段代码是写在该对话框类的成员函数中的,那么应该没有问题。你自己调试一下就可以了。
      

  6.   

    CString strText;  
    m_listbox.GetText(m_listbox.GetCurSel(), strText);
    楼主这段代码,放在何处了?
    单步调试一下,是执行到这句挂掉的吗?
    GetCurSel返回的是多少?
      

  7.   


    假设你的ListBox的id是:IDC_LIST1,用下面代码即可CListBox _list_box= (CListBox*)GetDlgItem(IDC_LIST1);
    CString strText;  
    _list_box.GetText(_list_box.GetCurSel(), strText);
      

  8.   

    你将listbox的type设置为control就行了