⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logindlg.cpp

📁 用VC开发的背单词小软件
💻 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 + -