0
votes

I have MFC dialog that contains Edit Text control. With form wizard I have generated m_edit variable for this control. Variable type is CEdit. How to get string value from m_edit?

I found in some samples from internet that member variable might be CString type that looks more convenient for me. Unfortunately variable selection type is not enabled in form wizard and it is set to CEdit. How to make m_edit a CString type?

I need to use this member variable to get information from Edit Text control

2

2 Answers

0
votes

You can select it as a CString type during the wizard, but you should be careful to choose the type control/value, if you want it to be CString, you should choose Value type.

0
votes

In the DoDataExchange function what was been generated? I presume it was

DDX_Control(pDX, IDC_YOUR_EDIT_BOX, m_edit);

For the DDX_Control the 3rd parameter absolutely needs to be a CWnd-based type and CString is not.

If you want to get the text,

UpdateData();

CString s;
m_edit.GetWindowText(s); 

Now the s variable has the text you want.

If you want to try it directly with a string, you can try to add a CString member variable to your class.

CString m_edit_string;

In your DoDataExchange function add:

DDX_Text(pDX, IDC_YOUR_EDIT_BOX, m_edit_string);

NB it is DDX_Text.

Wherever you need the text call UpdateData(); and then the m_edit_string variable has the text.