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

📄 logindlg.cpp

📁 网络围棋对战的客户端
💻 CPP
字号:
// LogInDlg.cpp : implementation file
//

#include "stdafx.h"
#include "WeiQiClient.h"
#include "LogInDlg.h"
#include "Client.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CLogInDlg dialog


CLogInDlg::CLogInDlg(CClient* pClient,CWnd* pParent /*=NULL*/)
	: CDialog(CLogInDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CLogInDlg)
	m_NameEdit = _T("");
	m_PassWordEdit = _T("");
	//}}AFX_DATA_INIT
	m_pClient=pClient;
}


void CLogInDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CLogInDlg)
	DDX_Text(pDX, IDC_EDIT_NAME, m_NameEdit);
	DDX_Text(pDX, IDC_EDIT_PASSWORD, m_PassWordEdit);
	DDX_Control(pDX,IDC_BUTTON_LOGIN,m_LogInButton);
	DDX_Control(pDX,IDC_BUTTON_NEWUSER,m_NewUserButton);
	DDX_Control(pDX,IDC_BUTTON_NOTLOGIN,m_ExitButton);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CLogInDlg, CDialog)
	//{{AFX_MSG_MAP(CLogInDlg)
	ON_BN_CLICKED(IDC_BUTTON_LOGIN, OnButtonLogin)
	ON_BN_CLICKED(IDC_BUTTON_NOTLOGIN, OnButtonNotlogin)
	ON_BN_CLICKED(IDC_BUTTON_NEWUSER, OnButtonNewuser)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLogInDlg message handlers

BOOL CLogInDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();

	// TODO: Add extra initialization here

	m_LogInButton.LoadButtonBmp(IDB_BITMAPLOGIN1,IDB_BITMAPLOGIN2,IDB_BITMAPLOGIN3,IDB_BITMAPLOGINBK);
	m_NewUserButton.LoadButtonBmp(IDB_BITMAPNEWUSER1,IDB_BITMAPNEWUSER2,IDB_BITMAPNEWUSER3,IDB_BITMAPNEWUSERBK);
	m_ExitButton.LoadButtonBmp(IDB_BITMAPEXIT1,IDB_BITMAPEXIT2,IDB_BITMAPEXIT3,IDB_BITMAPLOGINBK);
	m_Tip.Create(this);
	m_Tip.AddTool(&m_LogInButton,_T("登陆"));
	m_Tip.AddTool(&m_NewUserButton,_T("新用户"));
	m_Tip.AddTool(&m_ExitButton,_T("退出"));

	m_pClient->m_pLogInDlg=this;

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CLogInDlg::OnButtonLogin() 
{
	// TODO: Add your control notification handler code here
	if(Legality())
	{
		CString Msg=_T("___LOGIN__  ");
		Msg+=m_NameEdit+_T(" ")+m_PassWordEdit;
		m_pClient->SendMsg(Msg);
		m_pClient->m_Player.SetName(m_NameEdit);
	}
}

void CLogInDlg::OnButtonNotlogin() 
{
	// TODO: Add your control notification handler code here
	OnCancel();
}

void CLogInDlg::OnButtonNewuser() 
{
	// TODO: Add your control notification handler code here
	if(Legality())
	{
		CString Msg=_T("__NEWUSER_  ");
		Msg+=m_NameEdit+_T(" ")+m_PassWordEdit;
		m_pClient->SendMsg(Msg);
		m_pClient->m_Player.SetName(m_NameEdit);
	}
}

BOOL CLogInDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	m_Tip.RelayEvent(pMsg);
	if(pMsg->message==WM_KEYDOWN&&pMsg->wParam==13)
	{
		OnButtonLogin();
		return TRUE;
	}

	return CDialog::PreTranslateMessage(pMsg);
}

BOOL CLogInDlg::Legality()
{
	UpdateData(TRUE);
	if(m_NameEdit.IsEmpty())
	{
		MessageBox(_T("名字不能为空"));
		return FALSE;
	}
	if(m_PassWordEdit.IsEmpty())
	{
		MessageBox(_T("密码不能为空"));
		return FALSE;
	}
	if(m_NameEdit.Find(_T(' '))!=-1)
	{
		MessageBox(_T("名字中不许出现空格"));
		return FALSE;
	}
	if(m_PassWordEdit.Find(_T(' '))!=-1)
	{
		MessageBox(_T("密码中不许出现空格"));
		return FALSE;
	}
	if(m_NameEdit.GetLength()>30)
	{
		MessageBox(_T("名字太长"));
		return FALSE;
	}
	if(m_PassWordEdit.GetLength()>30)
	{
		MessageBox(_T("密码太长"));
		return FALSE;
	}
	return TRUE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -