How to get text from a CEdit control

I am a new guy with ATL. So forgive me to ask this question.

Problem Description: One CEdit control is added to the ATL dialog class. It is attached to the dialog initialization function.

//Define the edit control
ATLControls::CEdit  m_txtInput;

//In the OnInitDialog function
m_txtInput.Attach(GetDlgItem(IDC_INPUT_LINE));

m_txtInput.SetWindowText(_T("New directory"));

//In the public memeber function of the dialog GetInput()
//I have tried three kinds of method to get the text. But all of them are throw an 
//assert exception, IsWindow() failed. 
//1.
GetDlgItemText(IDC_INPUT_LINE, input);
//2.
ZeroMemory(m_lptstrInput, MAX_PATH);
m_txtInput.GetLine(0, m_lptstrInput, MAX_PATH);
//3.
BSTR input; 
m_txtInput.GetWindowText(input);

There is a topic on how to get text from CEdit, but it does not work.

Why can a CEdit control be set using the SetWindowText () function, but cannot get text using the GetWindowText () function? It bothers me a lot. Thanks so much if anyone can explain this to me.

+5
source share
2 answers

CEdit ATL. ATLControls? WTL :

    ATLASSERT(Edit.IsWindow()); // Make sure the control holds a handle
    CString sWindowText;
    Edit.GetWindowText(sWindowText);

GetWindowText ATL GetWindowTextLength GetWindowText. MSDN , .

, IsWindow , , , , , .

+6

MFC VS2015:

//
// Get char string/CString from CEdit m_ceDate;
// where
// DDX_Control(pDX, IDC_EDIT_DATE, m_ceDate);

char cdateBuf[128];
UINT nCountOfCharacters = GetDlgItemText(IDC_EDIT_DATE, cdateBuf, 16);
CString csDate = cdateBuf; 
+1

All Articles