简体   繁体   English

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

[英]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. 问题我有一个简单的文本框,其ID为IDC_FILE_NUMBER_EDIT,单击按钮时如何获取此文本框的值。 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

}

This works for MBCS. 这适用于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 如果需要的话,这应该适用于Unicode并只需进行最小的修改

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 要检查您使用的是Unicode还是MBCS,请转到Project Properties -> General -> Character Set

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM