Visual C ++从Cedit获取字符串 [英] Visual C++ get string from Cedit

查看:185
本文介绍了Visual C ++从Cedit获取字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个非常基本的问题,但我似乎无法理解.我在一个visualC ++项目上工作,我基本上想从GUI中获取一个字符串,然后将其用作文件名.到目前为止,我已经写了以下内容,其中IDC_FILE_NAME是编辑控制框的ID,但是我不确定这是否是实现此目的的方法.

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); 

推荐答案

但是我不确定这是否是实现这一目标的方法.

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

答案是是和否. 是,如果使用得当, 不,不是像您那样做. 除非要强制使用UNICODE或ANSI,否则不要使用UNICLODE/ANSI特定版本的函数. 您的代码应如下所示:

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);

注意 GetDlgItemText

这篇关于Visual C ++从Cedit获取字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆