Visual C++ get string from Cedit

爱⌒轻易说出口 提交于 2019-12-11 11:18:55

问题


This is probably a pretty basic question, but I can't seem to get it. I am working on a visualC++ project and I basically want to get a string from a GUI and then use that as a filename. I have written the following thus far, where IDC_FILE_NAME is the ID of the edit control box but I'm not sure if that is even the way to accomplish this.

m_pFileName = (CEdit*)GetDlgItem( IDC_FILE_NAME );

CString fName =_T(" ");
GetDlgItemTextA(IDC_FILE_NAME, fName); 

回答1:


but I'm not sure if that is even the way to accomplish this.

The answer is YES and NO. YES if properly used, NO, not as you do it. Do not use UNICLODE/ANSI specific versions of functions unless you want to force UNICODE or ANSI. Your code should look like:

    CString csText;
    GetDlgItemText(IDC_FILE_NAME, csText);

NOTE GetDlgItemText




回答2:


This has been tested with 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; 


来源:https://stackoverflow.com/questions/10662946/visual-c-get-string-from-cedit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!