📄 logindialog.cpp
字号:
// LoginDialog.cpp : implementation file
//
#include "stdafx.h"
#include "chapq2_1.h"
#include "LoginDialog.h"
#include "Public.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CLoginDialog dialog
CLoginDialog::CLoginDialog(CWnd* pParent /*=NULL*/)
: CDialog(CLoginDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(CLoginDialog)
m_szLoginName = _T("");
m_szPassword = _T("");
//}}AFX_DATA_INIT
}
void CLoginDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLoginDialog)
DDX_Text(pDX, IDC_LOGINNAME, m_szLoginName);
DDX_Text(pDX, IDC_PASSWORD, m_szPassword);
DDV_MaxChars(pDX, m_szPassword, 5);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLoginDialog, CDialog)
//{{AFX_MSG_MAP(CLoginDialog)
ON_BN_CLICKED(IDC_STUDENT_D, OnStudentD)
ON_BN_CLICKED(IDC_TEACHER_D, OnTeacherD)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLoginDialog message handlers
int m_Time=0,m_Count=3;
void CLoginDialog::OnOK()
{
// TODO: Add extra validation here
int m_i=GetCheckedRadioButton(IDC_STUDENT_D,IDC_TEACHER_D);
if(!m_i)
{
MessageBox(" 请选择登录方式! ","登录提示!");
return;
}
UpdateData(TRUE);
if(m_szLoginName=="user"&&m_szPassword=="12345")
{
CDialog::OnOK();
}
/*假如用户名或密码错误,且还未超出登陆次数,就进行提示*/
m_Time++;
if((m_szLoginName!="user"||m_szPassword!="12345")&&(m_Time<3)) //假如密码和用户名不正确
{
m_Count--;
CString str;
str.Format("%d",m_Count);
MessageBox("用户名或密码不正确\n 您还有"+str+"次尝试","登录提示",MB_OK);
}
/*假如超出登陆次数,提示并退出系统*/
if(m_Time>=3)
{
MessageBox("登陆错误次数超过3次","登录提示",MB_OK);
AfxGetMainWnd()->PostMessage(WM_QUIT);
CDialog::OnCancel();
}
}
void CLoginDialog::OnCancel()
{
// TODO: Add extra cleanup here
MessageBox("验证失败","登录提示",MB_OK);
AfxGetMainWnd()->PostMessage(WM_QUIT);
CDialog::OnCancel();
}
void CLoginDialog::OnStudentD()
{
// TODO: Add your control notification handler code here
CPublic *app = (CPublic *)AfxGetApp();
app->IS=FALSE;
}
void CLoginDialog::OnTeacherD()
{
// TODO: Add your control notification handler code here
CPublic *app = (CPublic *)AfxGetApp();
app->IS=TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -