1、新建MFC工程之后会出现一个默认的对话框,然后在对话框中拉出这些控件

2、右键进入类向导,然后给确定按钮添加消息驱动函数,定位到控件找到message那一栏直接双击就可以了!

3、然后进入Member Variables(成员变量框)中设置成员变量的类型为control控件类型

4、然后定位到确定按钮的消息驱动函数中加入以下代码:
void CSecondLoginDlg::OnOk()
{
// TODO: Add your control notification handler code here
CString username;
CString password;
m_Username.GetWindowText(username);
m_Password.GetWindowText(password);
if(username == "333" || password == "666"){
MessageBox(_T("登录成功"), _T("提示"), MB_OK | MB_ICONWARNING);
}
else{
MessageBox(_T("登录失败"), _T("提示"), MB_OK | MB_ICONWARNING);
}
}
void CSecondLoginDlg::OnCancel()
{
// TODO: Add your control notification handler code here
DestroyWindow();
}
5、然后就可以进行编译、链接、运行成功!