初学者的问题:自画的基于于CComBoBox为何用GetWindowText()函数不能获得当前选定的文本内容(获取是的乱码),为何?
CString lpStr; pDC.SetBkMode(TRANSPARENT );
  pDC.SetTextColor(TextColor); 
pDC.SelectObject(GetStockObject(DEFAULT_GUI_FONT));
this->GetWindowText(lpStr);
  pDC.DrawText(lpStr,
CRect(rcItem.left+5,rcItem.top,rcItem.right-30,rcItem.bottom),
DT_WORD_ELLIPSIS | DT_SINGLELINE | DT_VCENTER);有MSDN中的方法也是如此:Example
// The pointer to my combo box.
extern CComboBox* pmyComboBox;// Dump all of the items in the combo box.
#ifdef _DEBUG
   CString str, str2;
   int n;
   for (int i=0;i < pmyComboBox->GetCount();i++)
   {
      n = pmyComboBox->GetLBTextLen( i );
      pmyComboBox->GetLBText( i, str.GetBuffer(n) );
      str.ReleaseBuffer();      str2.Format(_T("item %d: %s\r\n"), i, str.GetBuffer(0));
      afxDump << str2;
   }
#endif
谁能帮帮小弟,万分感谢

解决方案 »

  1.   

    MSDN这段代码是有一些问题,我试过没有用,你可以用别的方法来得到,我是这样的.为CComBoBox声明一个CString 的变量,然后用UpdateData(TRUE)得到值,然后自己写函数作处理就行了。
      

  2.   

    CComboBox通常要取用户选择的文本,应该:
    int nCurSel = pComboBox->GetCurSel();
    CString strSelText;
    pComboBox->GetLBText( nCurSel, strSelText );
    //strSelText就是文本内容。
      

  3.   

    TO jmcooler() 
    CComboBox通常要取用户选择的文本,应该:
    int nCurSel = pComboBox->GetCurSel();
    CString strSelText;
    pComboBox->GetLBText( nCurSel, strSelText );
    //strSelText就是文本内容
    结果也一样,也为乱码...为知为何