Snowman288
Snowman288

Reputation: 107

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

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

Answers (1)

The Vivandiere
The Vivandiere

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

Related Questions