C++语言 实现登录对话框
Login dlg; if(dlg.DoModal()!=IDOK) { OnOK(); } void Login::OnOK() { // TODO: Add extra validation here //CEdit *pEdit1 = (CEdit *)GetDlgItem(IDC_EDIT1); //CEdit *pEdit2 = (CEdit *)GetDlgItem(IDC_EDIT2); //CString e1, e2; //pEdit1->GetWindowText(e1); //pEdit2->GetWindowText(e2); //if(e1=="蟒蛇软件站" && e2 == "pythonschool") //{ // CDialog::OnOK(); //} UpdateData(TRUE); //数据交换 if(m_Name.IsEmpty() || m_Password.IsEmpty()) { MessageBox("用户名或密码不能为空"); return; } num++;
if(num == 3)
{
MessageBox("Password was error three times");
CDialog::OnCancel();
return;
} if(m_Name=="蟒蛇软件站" && m_Password == "pythonschool") { CDialog::OnOK(); } else { MessageBox("用户名或密码不正确"); m_Name = ""; m_Password = ""; UpdateData(FALSE); return; } } BOOL Login::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here CStatic *pStatic1 = (CStatic *)GetDlgItem(IDC_STATIC1); CStatic *pStatic2 = (CStatic *)GetDlgItem(IDC_STATIC2); pStatic1->SetWindowText("用户名:"); pStatic2->SetWindowText("密 码:");
num = 0;
//设置窗口始终在最上面
CRect rect;
GetWindowRect(&rect);
::SetWindowPos(m_hWnd, HWND_TOPMOST, rect.left, rect.top, 0, 0,SWP_NOMOVE||SWP_NOSIZE);
return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
学习笔记转摘于:
丝酷网 http://www.pythonschool.com/