dlglogin.cpp

来自「《Visual C++经典编程大全》配套代码」· C++ 代码 · 共 150 行

CPP
150
字号
// DlgLogin.cpp : implementation file
//

#include "stdafx.h"
#include "NClient.h"
#include "DlgLogin.h"
#include "DlgUserReg.h"
#include "DlgServerPara.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDlgLogin dialog


CDlgLogin::CDlgLogin(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgLogin::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgLogin)
	m_bStartLogin = false;
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CDlgLogin::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgLogin)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgLogin, CDialog)
	//{{AFX_MSG_MAP(CDlgLogin)
	ON_BN_CLICKED(IDC_BTN_CANCEL, OnBtnCancel)
	ON_BN_CLICKED(IDC_BTN_REGISTER, OnBtnRegister)
	ON_BN_CLICKED(IDC_BTN_LOGIN, OnBtnLogin)
	ON_BN_CLICKED(IDC_BTN_CONFIG, OnBtnConfig)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgLogin message handlers

void CDlgLogin::OnBtnCancel() 
{
	CDialog::OnCancel();	
}

void CDlgLogin::OnBtnRegister() 
{
	if(!((CNClientApp *)AfxGetApp())->m_IsConnect){
		if(!((CNClientApp *)AfxGetApp())->ToConnect()){
			MessageBox("连接失败!");
			return;
		}
	}

	CDlgUserReg dlg;
	dlg.DoModal();
}

void CDlgLogin::OnBtnLogin() 
{
	if(!((CNClientApp *)AfxGetApp())->m_IsConnect){
		if(!((CNClientApp *)AfxGetApp())->ToConnect()){
			MessageBox("连接失败!");
			return;
		}
	}

	CString strCode = "";
	CString strName = "";

	GetDlgItem(IDC_EDIT_LCODE)->GetWindowText(strCode);
	GetDlgItem(IDC_EDIT_LNAME)->GetWindowText(strName);

	if(strlen(strCode) <= 0 || strlen(strName) <= 0){
		MessageBox("用户编号和用户名称不能为空!");
		return;
	}

	CString nData = "";
	nData.Format("ChkUser#%s#%s#",strCode,strName);
	((CNClientApp *)AfxGetApp())->m_socket->SendData(nData);

	GetDlgItem(IDC_BTN_LOGIN)->EnableWindow(false);
	GetDlgItem(IDC_BTN_REGISTER)->EnableWindow(false);
	GetDlgItem(IDC_BTN_CONFIG)->EnableWindow(false);

	((CNClientApp *)AfxGetApp())->m_status = REQ_CHKUSER;
	((CNClientApp *)AfxGetApp())->m_strLastMsg = "";

	m_bStartLogin = true;

	((CNClientApp *)AfxGetApp())->m_strUserCode = strCode;
	((CNClientApp *)AfxGetApp())->m_strUserName = strName;

	SetTimer(1002,1000,NULL);

//	CDialog::OnOK();	
}

void CDlgLogin::OnBtnConfig() 
{
	CDlgServerPara m_config;
	
	m_config.DoModal();
}

void CDlgLogin::OnTimer(UINT nIDEvent) 
{
	if(nIDEvent == 1002 && m_bStartLogin){
		if(((CNClientApp *)AfxGetApp())->m_status == STA_NORMAL){
			CString tempstr = ((CNClientApp *)AfxGetApp())->m_strLastMsg;
			((CNClientApp *)AfxGetApp())->m_strLastMsg = "";
			int nLen = strlen(tempstr);
			if(nLen >= 11){
				if(strcmp(tempstr,"CheckUserOk") == 0){

					m_bStartLogin = false;

					CDialog::OnOK();

					return;

				}
			}

			GetDlgItem(IDC_BTN_LOGIN)->EnableWindow(true);
			GetDlgItem(IDC_BTN_REGISTER)->EnableWindow(true);
			GetDlgItem(IDC_BTN_CONFIG)->EnableWindow(true);

			m_bStartLogin = false;
			MessageBox("登录失败,请重试!");

		}
	}

	
	CDialog::OnTimer(nIDEvent);
}

⌨️ 快捷键说明

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