先是初始化:
CComboBox m_Comline; 
CString str;
for(int i=1;i <=10;i++) 

        str.Format("%d",i);
        m_Comline.AddString(str); 
}
但是利用ON_CBN_SELCHANGE事件后,怎么获得选中的值并转换为int类型?谢谢!!

解决方案 »

  1.   

    最直接的方法是
    m_Comline; 
    CString str; 
    m_Comline.GetWindowText(str);
    int iVal = atoi(str);
      

  2.   

    同意楼上的:m_Comline.GetWindowText(str);
              int iVal = atoi(str);
      

  3.   


    int nIndex = m_Combo.GetCurSel();
    if(nIndex != CB_ERR)
    {
    CString m_str ;
    m_Combo.GetLBText(nIndex , m_str);
    }获取当前选择的项
    int i = atoi(m_str);//转化为整型
      

  4.   

    CString str;
    m_Comline.GetLBText(m_Comline.GetCurSel(), str);
    int i = atoi(str);
      

  5.   

    4楼的代码有点问题,当m_Comline.GetCurSel()返回-1时,程序会报错,3楼的正解。 
      

  6.   

    楼主是在不厚道,用了我的回复,在这里提问,却不给我分,
    连引用的人都给分,看5楼:http://topic.csdn.net/u/20091214/12/ce864d61-4bf9-4e6d-a314-4e3047675172.html