Home > Mobile >  calling MFC edit control GetWindowText member can't compile
calling MFC edit control GetWindowText member can't compile

Time:08-29

my code:

//the auto generated stuff (by right-click on editbox add variable to control option)
CEdit edit_name;

void CSendMessageWithActualDataDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_EDIT_NAME, edit_name);
}

Looks OK so far, right?

void dofoo()

{
     //IDE shows error squiggle at dot "name.GetWi" with no pop-up 
     //details given except the object's blurb text
 
    CString foostring= edit_name.GetWindowTextW(); 
    //error C2661: 'CWnd::GetWindowTextW': no overloaded function takes 0 arguments


    or instead with no parentheses added:

    // no IDE error indication
    CString foostring= edit_name.GetWindowTextW;
    //error C3867: 'CWnd::GetWindowTextW': non-standard syntax; use '&' to create a pointer to member

}

according to:

enter image description here

If you select Value, then you can map it to a CString:

enter image description here

This creates the enter image description here


By the way, you may find this article useful (enter image description here

The above is with the previous rows on the table stripped out.

CodePudding user response:

Apparently, this is all about convenience. Since you already know how to call CWnd::GetWindowText, but find it too cumbersome to use, just wrap everything up in a free function:

CString GetWindowText(CWnd const& wnd) {
    CString s;
    wnd.GetWindowText(s);
    return s;
}

You can call that, passing in any object that (publicly) derives from CWnd (such as the CEdit edit_name) and get a CString object you can use any which way. (C 17 introduced guaranteed copy elision, meaning that s will never need to get copied.)

If you need to pass it into other Windows API functions that expect an LPCTSTR, CString implements operator PCXSTR that implicitly converts things as needed, e.g.

AfxMessageBox(GetWindowText(edit_name));
  • Related