C++如何获取文本框的值?

How to get the value of a text box in c++?

问题 我有一个简单的文本框,其 ID 名为 IDC_FILE_NUMBER_EDIT 如何在单击按钮时获取此文本框的值。下面是我的代码任何帮助将不胜感激!

这是我的按钮,当它被点击时我想从

中获取文本或值
void CJunkView::OnCadkeyButton() 

{  
    //Get text in IDC_FILE_NUMBER_EDIT text box. 

    std::string filenum = IDC_FILE_NUMBER_EDIT->Text;
    //For some reason I cant use this I get this error C2227: left of   '->Text' must point to class/struct/union

}

这适用于 MBCS。

CString tempS;
GetDlgItem(IDC_FILE_NUMBER_EDIT)->GetWindowText(tempS);
CT2CA pszConvertedAnsiString (tempS);
std::string strStd (pszConvertedAnsiString);

如果有必要,这应该适用于 Unicode,只需进行最少的修改

CString tempS;
GetDlgItem(IDC_FILE_NUMBER_EDIT)->GetWindowText(tempS);
std::string s((LPCTSTR)tempS);

要检查您使用的是 Unicode 还是 MBCS,请转至 Project Properties -> General -> Character Set