How to get text from CEdit control

前端 未结 2 1642
不思量自难忘°
不思量自难忘° 2021-02-09 18:55

I\'m a new guy with ATL. So forgive me to ask this question.

Problem description: One CEdit control is added into a ATL dialog class. It\'s

相关标签:
2条回答
  • 2021-02-09 19:21

    CEdit is not an ATL class. Where the namespace ATLControls comes from? There is a WTL class with this name and getting text from it is easy:

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

    The method GetWindowText is coming from ATL however and wraps GetWindowTextLength and GetWindowText API. The latter MSDN article also has a code snippet showing typical usage.

    Since you mention that IsWindow does not work for you, the most likely problem is that your edit control wrapper class variable just does not have a handle of a real control, and hence getting text from nothing is impossible.

    0 讨论(0)
  • 2021-02-09 19:24

    This has been tested with 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; 
    
    0 讨论(0)
提交回复
热议问题