我正在写一个对话窗口和一些按钮简单的MFC应用程序。 我还添加了编辑控制,以让用户插入一个文本字符串。
我想读这是目前在编辑控件的值,将其存储在一个字符串,但我不知道如何做到这一点。
我没有编译错误,但我一直只是读了“” 标记。
我添加了一个变量名文本编辑控件是filepath1
,这是代码:
// CMFC_1Dlg dialog
class CMFC_1Dlg : public CDialogEx
{
// Construction
public:
CMFC_1Dlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
enum { IDD = IDD_MFC_1_DIALOG };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
HICON m_hIcon;
// Generated message map functions
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnBnClickedButton1();
afx_msg void OnBnClickedButton2();
afx_msg void OnEnChangeEdit1();
CString filePath1;
}
//...
void CMFC_1Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialogEx::OnSysCommand(nID, lParam);
}
}
CMFC_1Dlg::CMFC_1Dlg(CWnd* pParent /*=NULL*/)
: CDialogEx(CMFC_1Dlg::IDD, pParent)
,filePath1(("..\\Experiments\\Dirs\\"))
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMFC_1Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT1, filePath1);
}
// then i try to get the string value with
CString txtname=filePath1;
_cprintf("Value %s\n", txtname); // but i always read just a "."