Visual C ++ gets string from Cedit

This is probably a pretty simple question, but I can't get it. I am working on a visualC ++ project, and basically want to get a string from the GUI and then use it as a file name. I have written the following so far, where IDC_FILE_NAME is the identifier of the edit control block, but I'm not sure if this is even a way to accomplish this.

m_pFileName = (CEdit*)GetDlgItem( IDC_FILE_NAME );

CString fName =_T(" ");
GetDlgItemTextA(IDC_FILE_NAME, fName); 
+1
source share
2 answers

but I'm not sure if this is even a way to do this.

Answer: YES and NO. YES, if used correctly, NO, not the way you do it. Do not use the special UNICLODE / ANSI functions unless you want to force UNICODE or ANSI. Your code should look like this:

    CString csText;
    GetDlgItemText(IDC_FILE_NAME, csText);

NOTE GetDlgItemText

+1

VS2015:

//
// Get string 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

All Articles