不解释,直接上代码 CLoginDlg login; //CLoginDialog为登陆对话框 bool isLogin=false;//用来判断登录是否成功,初始是不成功的 while(!isLogin) { int nLogin; nLogin=login.DoModal(); //显示 if(nLogin==IDOK) { CString tUser=login.m_csUserName; //这里获得输入的帐号和密码 CString tPass=login.m_csPassWord; if(tUser=="aa"&&tPass=="bb") //这里匹配帐号和密码,你可以通过数据库来实现验证只要在这里改下代码而已 { isLogin=true; //如果匹配,则成功 } else { AfxMessageBox("错误的帐号或密码!"); } } else if(nLogin==IDCANCEL) //如果取消登陆,则登陆失败,退出循环,即退出登陆 { isLogin=false; break; } } if(isLogin){ //如果登录成功,则显示主窗口 CtestDlg dlg; m_pMainWnd = &dlg; int nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } }
CLoginDlg login; //CLoginDialog为登陆对话框
bool isLogin=false;//用来判断登录是否成功,初始是不成功的
while(!isLogin)
{
int nLogin;
nLogin=login.DoModal(); //显示
if(nLogin==IDOK)
{
CString tUser=login.m_csUserName; //这里获得输入的帐号和密码
CString tPass=login.m_csPassWord;
if(tUser=="aa"&&tPass=="bb") //这里匹配帐号和密码,你可以通过数据库来实现验证只要在这里改下代码而已
{
isLogin=true; //如果匹配,则成功
}
else
{
AfxMessageBox("错误的帐号或密码!");
}
}
else if(nLogin==IDCANCEL) //如果取消登陆,则登陆失败,退出循环,即退出登陆
{
isLogin=false;
break;
}
} if(isLogin){ //如果登录成功,则显示主窗口
CtestDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
}