//第一种方式
int num1,num2,num3;
char ch1[10],ch2[10],ch3[10];
GetDlgItem(IDC_EDIT1)->GetWindowText(ch1,10);
GetDlgItem(IDC_EDIT2)->GetWindowText(ch2,10);
num1 = atoi(ch1);
num2 = atoi(ch2);
num3 = num1 + num2;
itoa(num3,ch3,10);
GetDlgItem(IDC_EDIT3)->SetWindowText(ch3);
//第二种方式
int num1,num2,num3;
char ch1[10],ch2[10],ch3[10];
GetDlgItemText(IDC_EDIT1,ch1,10);
GetDlgItemText(IDC_EDIT2,ch2,10);
num1 = atoi(ch1);
num2 = atoi(ch2);
num3 = num1 + num2;
itoa(num3,ch3,10);
SetDlgItemText(IDC_EDIT3,ch3);
//第三种方式
int num1,num2,num3;
num1 = GetDlgItemInt(IDC_EDIT1);
num2 = GetDlgItemInt(IDC_EDIT2);
num3 = num1 + num2;
SetDlgItemInt(IDC_EDIT3,num3);
//第四种方式(给每个编辑框添加成员变量m_num1(int),m_num2(int),m_num3(int))
//在此,可以设置设置输入数字的大小范围(在ClassWizard),可以对你输入的字符进行校验(比如,要求int类型,你输入了字母)
UpdateData();
m_num3 = m_num1 + m_num2;
UpdateData(FALSE);
//第五种方式(给每个编辑框添加控件变量m_edit1(Category:Control,Variable type:CEdit),m_edit2(Category:Control,Variable type:CEdit),m_edit3(Category:Control,Variable type:CEdit))
int num1,num2,num3;
char ch1[10],ch2[10],ch3[10];
m_edit1.GetWindowText(ch1,10);
m_edit2.GetWindowText(ch2,10);
num1 = atoi(ch1);
num2 = atoi(ch2);
num3 = num1 + num2;
itoa(num3,ch3,10);
m_edit3.SetWindowText(ch3);
//第六种方式
int num1,num2,num3;
char ch1[10],ch2[10],ch3[10];
//::SendMessage(GetDlgItem(IDC_EDIT1)->m_hWnd,WM_GETTEXT,10,(LPARAM)ch1);
//::SendMessage(m_edit1.m_hWnd,WM_GETTEXT,10,(LPARAM)ch1);
GetDlgItem(IDC_EDIT1) ->SendMessage(WM_GETTEXT,10,(LPARAM)ch1);
GetDlgItem(IDC_EDIT2) ->SendMessage(WM_GETTEXT,10,(LPARAM)ch2);
num1 = atoi(ch1);
num2 = atoi(ch2);
num3 = num1 + num2;
itoa(num3,ch3,10);
GetDlgItem(IDC_EDIT3) ->SendMessage(WM_SETTEXT,0,(LPARAM)ch3);
//第七种方式
int num1,num2,num3;
char ch1[10],ch2[10],ch3[10];
SendDlgItemMessage(IDC_EDIT1,WM_GETTEXT,10,(LPARAM)ch1);
SendDlgItemMessage(IDC_EDIT2,WM_GETTEXT,10,(LPARAM)ch2);
num1 = atoi(ch1);
num2 = atoi(ch2);
num3 = num1 + num2;
itoa(num3,ch3,10);
SendDlgItemMessage(IDC_EDIT3,WM_SETTEXT,0,(LPARAM)ch3);
//编辑框复选函数 EM_SETSEL
SendDlgItemMessage(IDC_EDIT3,EM_SETSEL,1/*开始位置*/,3/*结束位置*/);//If the start is 0 and the end is –1, all the text in the edit control is selected. If the start is –1, any current selection is deselected.
//设置编辑框3为当前焦点所在
m_edit3.SetFocus();