The operations on the edit box mainly include obtaining the content in the edit box, assigning values to the content in the edit box, and updating the content in the edit box.
There are two main methods:
as shown below, this is dialog
Method 1:
Take Button1 as an example
void CMFCApplication1Dlg::OnBnClickedButton1()
{
// 获取编辑框中1的内容
UpdateData(TRUE);// --刷新控件的值到对应的变量
/*
UpdateData(TRUE) -- 刷新控件的值到对应的变量
UpdateData(FALSE) -- 拷贝变量值到控件显示
*/
// 给编辑框2赋值
m_lucky2 = m_lucky1;
// UpdateData(FALSE); // 与下面一条语句作用一致
GetDlgItem(IDC_EDIT2)->SetWindowText(m_lucky2);
// 给编辑框3赋值
m_lucky3 = "12345";
UpdateData(FALSE);
}
Method 2:
Take Button2 as an example
void CMFCApplication1Dlg::OnBnClickedButton2()
{
// 获取编辑框中1的内容
CString str;
GetDlgItem(IDC_EDIT1)->GetWindowText(str);
// 给编辑框2赋值
m_lucky2 = str;
GetDlgItem(IDC_EDIT2)->SetWindowText(m_lucky2);
// 给编辑框3赋值
m_lucky3 = "12345";
UpdateData(FALSE);
}
The above is the basic operation of the two edit boxes based on MFC.