Reputation: 107
Question I have simple textbox with an ID called IDC_FILE_NUMBER_EDIT how can I get the value of this text box when I click a button. below is my code any help would be greatly appreciated!
Here is my button when it gets clicked I want to get the text or value from
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
}
Upvotes: 0
Views: 3577
Reputation: 3191
This works for MBCS.
CString tempS;
GetDlgItem(IDC_FILE_NUMBER_EDIT)->GetWindowText(tempS);
CT2CA pszConvertedAnsiString (tempS);
std::string strStd (pszConvertedAnsiString);
This should work for Unicode with minimal modifications if at all necessary
CString tempS;
GetDlgItem(IDC_FILE_NUMBER_EDIT)->GetWindowText(tempS);
std::string s((LPCTSTR)tempS);
To check whether you are using Unicode or MBCS, go to Project Properties -> General -> Character Set
Upvotes: 2