?? logindlg.cpp
字號:
// LoginDlg.cpp : implementation file
//
#include "stdafx.h"
#include "winbdc.h"
#include "LoginDlg.h"
#include "WinBDCDlg.h"
#include "CreateUserDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CLoginDlg dialog
CLoginDlg::CLoginDlg(CWnd* pParent /*=NULL*/)
: CDialog(CLoginDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CLoginDlg)
m_strUserName = _T("");
m_strPassWord = _T("");
//}}AFX_DATA_INIT
}
void CLoginDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLoginDlg)
DDX_Text(pDX, IDC_USERNAME, m_strUserName);
DDV_MaxChars(pDX, m_strUserName, 12);
DDX_Text(pDX, IDC_PASSWORD, m_strPassWord);
DDV_MaxChars(pDX, m_strPassWord, 12);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLoginDlg, CDialog)
//{{AFX_MSG_MAP(CLoginDlg)
ON_EN_CHANGE(IDC_PASSWORD, OnChangePassword)
ON_EN_CHANGE(IDC_USERNAME, OnChangeUsername)
ON_WM_SHOWWINDOW()
ON_BN_CLICKED(IDC_NEWUSER, OnNewuser)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLoginDlg message handlers
void CLoginDlg::OnChangePassword()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
UpdateData(true);
}
void CLoginDlg::OnChangeUsername()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
UpdateData(true);
}
void CLoginDlg::OnOK()
{
// TODO: Add extra validation here
char Directory[100], szUserName[20], szPassWord[20], szGroup[20];
GetCurrentDirectory(100,Directory);
CString str(Directory);
str += "\\User.inf";
FILE *fp;
fp = fopen((LPCTSTR)str, "r");
if(fp == NULL)
{
MessageBox("User.inf文件打開失敗!");
::ExitProcess(0);
}
while(!feof(fp))
{
fscanf(fp, "%s", szUserName);
fscanf(fp, "%s", szPassWord);
fscanf(fp, "%s", szGroup);
pUser = new CUser(szUserName, szPassWord, szGroup);
m_UserList.AddTail(pUser);
}
fclose(fp);
int i = 0;
for(i=0; i<m_UserList.GetCount(); i++)
{
pUser = m_UserList.GetAt(m_UserList.FindIndex(i));
if(pUser->m_UserName.Compare(m_strUserName) == 0 && pUser->m_PassWord.Compare(m_strPassWord) == 0)
{
pUser->m_bIsMe = true;
((CWinBDCDlg *)::AfxGetMainWnd())->m_UserList.RemoveAll();
((CWinBDCDlg *)::AfxGetMainWnd())->m_UserList.AddTail(&m_UserList);
CDialog::OnOK();
break;
}
}
if(i>=m_UserList.GetCount())
{
MessageBox("用戶名或密碼錯誤,請重試");
((CEdit *)GetDlgItem(IDC_USERNAME))->SetWindowText("");
((CEdit *)GetDlgItem(IDC_USERNAME))->SetFocus();
((CEdit *)GetDlgItem(IDC_PASSWORD))->SetWindowText("");
}
}
void CLoginDlg::OnShowWindow(BOOL bShow, UINT nStatus)
{
CDialog::OnShowWindow(bShow, nStatus);
// TODO: Add your message handler code here
((CEdit *)GetDlgItem(IDC_USERNAME))->SetFocus();
}
void CLoginDlg::OnNewuser()
{
// TODO: Add your control notification handler code here
CCreateUserDlg dlg;
if(dlg.DoModal() == IDOK)
{
char Directory[100], szUserName[20], szPassWord[20], szGroup[20];
GetCurrentDirectory(100,Directory);
CString str(Directory);
str += "\\User.inf";
FILE *fp;
fp = fopen((LPCTSTR)str, "r");
while(!feof(fp))
{
fscanf(fp, "%s", szUserName);
fscanf(fp, "%s", szPassWord);
fscanf(fp, "%s", szGroup);
pUser = new CUser(szUserName, szPassWord, szGroup);
m_UserList.AddTail(pUser);
}
fclose(fp);
pUser = new CUser(dlg.m_UserName, dlg.m_PassWord, "Guest");
pUser->m_bIsMe = true;
m_UserList.AddTail(pUser);
((CWinBDCDlg *)::AfxGetMainWnd())->m_UserList.RemoveAll();
((CWinBDCDlg *)::AfxGetMainWnd())->m_UserList.AddTail(&m_UserList);
CDialog::OnOK();
}
else
{
MessageBox("CANCEL");
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -