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

📄 registerdlg.cpp

📁 类似于QQ的聊天工具,分为客户端和服务器端,有共享空间,能发布公告,可传输文件
💻 CPP
字号:
// RegisterDlg.cpp : implementation file
//

#include "stdafx.h"
#include "NetQQ.h"
#include "RegisterDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CRegisterDlg dialog
void CRegisterDlg::RecvProc (CString& strBuff)
{
	long ret = m_bagTool.GetOrderCode(strBuff);
	if(ret == 9999)
	{
		AfxMessageBox("服务器数据库正在维修,请稍候再试!");
		return;
	}

	ret = long (m_bagTool.GetRetStatus(strBuff));
	switch(ret)
	{
		case  0:
		{
			AfxMessageBox("注册失败,请重试!");
			SetDlgItemStatus(true);
			break;
		}
 		case 1:
		{
			CString tempRemark;			
			m_UserID =  m_bagTool.GetDesUserId(strBuff);
			UpdateData(0);
			tempRemark = "您的用户ID是:"  + m_UserID + "您的密码是:" + m_UserPsw + "感谢使用,请牢记帐号和密码!";
			m_stRemark.SetWindowText(tempRemark);

			((pInitRegWnd->GetLoadWnd())->GetDlgItem(IDC_EDIT_UID))->SetWindowText(m_UserID);
			((pInitRegWnd->GetLoadWnd())->GetDlgItem(IDC_EDIT_PSW))->SetFocus();
			break;		
		}

	}
}

void CRegisterDlg::OnNetEvent(WPARAM wParam, LPARAM lParam)
{
	//调用API函数,得到网络事件类型
    int iEvent = WSAGETSELECTEVENT(lParam); 
	switch(iEvent)
	{
		case FD_CLOSE:  //断开事件:
			{
				m_IsCanSubmit = false;
				m_ClntSock.CloseClient();
				//AfxMessageBox("断开");
			
				break;
			}
		case FD_READ:   //网络数据包到达事件
			{
				CString strBuff;
				if(m_ClntSock.OnRecieve(strBuff))
				{
					RecvProc(strBuff);
				}
				break;
			}
		default: break;
	}
}


CRegisterDlg::CRegisterDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CRegisterDlg::IDD, pParent)
{
	pInitRegWnd = (CInitRegDlg*)pParent;

	/*
		DWORD dwIp = htonl(inet_addr("192.168.2.23"));
	((CIPAddressCtrl*)GetDlgItem(IDC_IPADDR_SVR))->SetAddress(dwIp);
	GetDlgItem(IDC_EDIT_UID)->SetFocus();
	*/
	//{{AFX_DATA_INIT(CRegisterDlg)
	m_UserEmail = _T("");
	m_UserName = _T("");
	m_UserTel = _T("");
	m_UserID = _T("");
	m_UserPsw = _T("");
	//}}AFX_DATA_INIT
}


void CRegisterDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CRegisterDlg)
	DDX_Control(pDX, IDC_REMARK, m_stRemark);
	DDX_Control(pDX, IDC_COMBO_UserDptm, m_cmUserDptm);
	DDX_Control(pDX, IDC_COMBO_UserDuty, m_cmUserDuty);
	DDX_Control(pDX, IDC_COMBO_UserSex, m_cmUserSex);
	DDX_Control(pDX, IDC_PIC, m_PicCtrl);
	DDX_Text(pDX, IDC_EDIT_UserEmail, m_UserEmail);
	DDV_MaxChars(pDX, m_UserEmail, 50);
	DDX_Text(pDX, IDC_EDIT_UserName, m_UserName);
	DDV_MaxChars(pDX, m_UserName, 12);
	DDX_Text(pDX, IDC_EDIT_UserTel, m_UserTel);
	DDV_MaxChars(pDX, m_UserTel, 20);
	DDX_Text(pDX, IDC_EDIT_UserID, m_UserID);
	DDV_MaxChars(pDX, m_UserID, 9);
	DDX_Text(pDX, IDC_EDIT_UserPsw, m_UserPsw);
	DDV_MaxChars(pDX, m_UserPsw, 9);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CRegisterDlg, CDialog)
	//{{AFX_MSG_MAP(CRegisterDlg)
	ON_BN_CLICKED(IDC_BUT_SUBMIT, OnButSubmit)
	ON_BN_CLICKED(IDC_BUT_CANCEL, OnButCancel)
	ON_EN_SETFOCUS(IDC_EDIT_UserName, OnSetfocusEDITUserName)
	ON_WM_CTLCOLOR()
	ON_EN_SETFOCUS(IDC_EDIT_UserPsw, OnSetfocusEDITUserPsw)
	ON_EN_SETFOCUS(IDC_EDIT_UserEmail, OnSetfocusEDITUserEmail)
	ON_EN_SETFOCUS(IDC_EDIT_UserTel, OnSetfocusEDITUserTel)
	ON_CBN_SETFOCUS(IDC_COMBO_UserDptm, OnSetfocusCOMBOUserDptm)
	ON_CBN_SETFOCUS(IDC_COMBO_UserDuty, OnSetfocusCOMBOUserDuty)
	ON_CBN_SETFOCUS(IDC_COMBO_UserSex, OnSetfocusCOMBOUserSex)
	ON_BN_CLICKED(IDC_BUT_CLEAR, OnButClear)
	ON_CBN_SELCHANGE(IDC_COMBO_UserSex, OnSelchangeCOMBOUserSex)
	ON_CBN_SELCHANGE(IDC_COMBO_UserDptm, OnSelchangeCOMBOUserDptm)
	ON_CBN_SELCHANGE(IDC_COMBO_UserDuty, OnSelchangeCOMBOUserDuty)
	ON_CBN_KILLFOCUS(IDC_COMBO_UserDptm, OnKillfocusCOMBOUserDptm)
	ON_CBN_KILLFOCUS(IDC_COMBO_UserDuty, OnKillfocusCOMBOUserDuty)
	ON_BN_CLICKED(IDC_BUT_BACK, OnButBack)
	ON_WM_CLOSE()
	ON_WM_LBUTTONDOWN()
	ON_WM_PAINT()
	ON_BN_CLICKED(IDC_CLOSE, OnmyClose)
	ON_BN_CLICKED(IDC_BUT_MIN, OnButMin)
	ON_WM_MOUSEMOVE()
	ON_BN_CLICKED(IDC_BTN_R, OnBtnR)
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_NETEVENT, OnNetEvent)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRegisterDlg message handlers

void CRegisterDlg::OnButSubmit() 
{
	// TODO: Add your control notification handler code here
	m_IsCanSubmit = true;

	//////////////////////////////////////////////////////
	//姓名
	GetDlgItem(IDC_EDIT_UserName)->GetWindowText(m_UserName);
	if(m_UserName.IsEmpty())
	{
		GetDlgItem(IDC_EDIT_UserName)->SetFocus();
		m_stRemark.SetWindowText("您还没有填写姓名!");	
		return;
	}
	//////////////////////////////////////////////////////
	//性别
	if(m_cmUserSex.GetCurSel() == 0)
	{
		m_cmUserSex.SetFocus();
		m_stRemark.SetWindowText("您还没有选择性别!");	
		return;
	}
	//////////////////////////////////////////////////////
	//密码
	GetDlgItem(IDC_EDIT_UserPsw)->GetWindowText(m_UserPsw);
	if(m_UserPsw.IsEmpty())
	{
		GetDlgItem(IDC_EDIT_UserPsw)->SetFocus();
		m_stRemark.SetWindowText("您还没有填写密码!");	
		return;
	}

	//////////////////////////////////////////////////////
	//部门
	char tmp[25] = "";
	m_cmUserDptm.GetWindowText(tmp, 25);
	m_UserDptm = tmp;
	if(m_UserDptm.IsEmpty() || m_cmUserDptm.GetCurSel() == 0)
	{
		m_cmUserDptm.SetFocus();
		m_stRemark.SetWindowText("您还没有填写或选择部门!");	
		return;
	}

	//////////////////////////////////////////////////////
	//职务
	m_cmUserDuty.GetWindowText(tmp, 25);
	m_UserDuty = tmp;
	if(m_UserDuty.IsEmpty() || m_cmUserDuty.GetCurSel() == 0)
	{
		m_cmUserDuty.SetFocus();
		m_stRemark.SetWindowText("您还没有输入或选择职务!");	
		return;
	}	
	//////////////////////////////////////////////////////
	//电话	
	GetDlgItem(IDC_EDIT_UserTel)->GetWindowText(m_UserTel);
	if(m_UserTel.IsEmpty())
	{
		GetDlgItem(IDC_EDIT_UserTel)->SetFocus();
		m_stRemark.SetWindowText("您还没有填写电话号码!");	
		return;
	}
	//////////////////////////////////////////////////////
	//邮箱
	GetDlgItem(IDC_EDIT_UserEmail)->GetWindowText(m_UserEmail);
	if(m_UserEmail.IsEmpty())
	{
		GetDlgItem(IDC_EDIT_UserEmail)->SetFocus();
		m_stRemark.SetWindowText("您还没有填写邮箱!");	
		return;
	}


//	HANDLE handle = CreateThread(NULL, 0, WaitLoadProc, NULL, 0, NULL);
//	CloseHandle(handle);
	//设置服务器端口和IP
	m_strPort = pInitRegWnd->GetPort();
	m_IPAdress = pInitRegWnd->GetIpAddr();

	///////////////////////////////////////////////////////////////////
	//开始创建客户端
	if(!m_ClntSock.CreateClient(m_IPAdress, m_strPort))
	{
		AfxMessageBox("连接服务器失败!");
		return;
	}

	///////////////////////////////////////////////////////////////////
	//注册网络事件
	int ret = WSAAsyncSelect(m_ClntSock.GetSrvSocket(), m_hWnd, 
                              WM_NETEVENT, FD_CLOSE | FD_READ); 
	if(SOCKET_ERROR == ret)
	{
		AfxMessageBox("网络事件注册失败!");
		return;
	}
	
	////////////////////////////////////////
	//打包数据
	UpdateData(true);
	CString strBuff;
	tagPacketParam BagRegister;
	BagRegister.order     = "1001";
	BagRegister.UserName  = m_UserName;
	BagRegister.UserPsw   = m_UserPsw;	
	BagRegister.UserSex   = m_UserSex;
	BagRegister.UserDptm  = m_UserDptm;	
	BagRegister.UserDuty  = m_UserDuty;
	BagRegister.UserTel   = m_UserTel;
	BagRegister.UserEmail = m_UserEmail;
	BagRegister.paramNum  = 7;
	m_bagTool.DataPackage(strBuff, &BagRegister);

	Sleep(50);
	if(!m_IsCanSubmit)
	{
		return;
	}
	int mesgres = MessageBox("是否要提交数据?","提交数据",MB_OKCANCEL|MB_ICONQUESTION);
	if(mesgres == IDOK)
	{
//想实现锁定文本框有就是----变灰色????
		m_ClntSock.OnSend(strBuff);	
		SetDlgItemStatus(false);
	}
	else if(mesgres == IDCANCEL)
		return;
	///////////////////////////////////////
	//锁定文本

}


void CRegisterDlg::OnButCancel() 
{
	// TODO: Add your control notification handler code here
	OnClose();
}


void CRegisterDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
}

void CRegisterDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	m_ClntSock.CloseClient();
	pInitRegWnd->GetLoadWnd()->ShowWindow(true);
	delete pInitRegWnd;
	delete this;
}

BOOL CRegisterDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	// TODO: Add extra initialization here
	m_cmUserSex.SetCurSel(0);
	m_cmUserDptm.SetCurSel(0);
	m_cmUserDuty.SetCurSel(0);

	GetDlgItem(IDC_EDIT_UserName)->SetFocus();
	//自定义按纽
	m_myButtonClose.AutoLoad(IDC_CLOSE,this);
	m_myButtonBack.AutoLoad(IDC_BUT_BACK,this);
	m_myButtonExit.AutoLoad(IDC_BUT_CANCEL,this);
	m_myButtonMin.AutoLoad(IDC_BUT_MIN,this);
	m_myButtonClear.AutoLoad(IDC_BUT_CLEAR,this);	
	m_myButtonSubmit.AutoLoad(IDC_BUT_SUBMIT,this);

	m_stRemark.SetWindowText("请仔细填写个人资料,其中*为必填内容");	

	m_ttToolTip.CreateToolTip(this);
	return false;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CRegisterDlg::OnSetfocusEDITUserName() 
{
	// TODO: Add your control notification handler code here
	m_stRemark.SetWindowText("请输入您的姓名,以便您的同事认识您");	
}

HBRUSH CRegisterDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	int iIDC = pWnd->GetDlgCtrlID();
	// TODO: Change any attributes of the DC here
	if(iIDC == IDC_REMARK)
		 pDC->SetTextColor(RGB(255,23,33));
	if(iIDC == IDC_EDIT_UserID)
		 pDC->SetTextColor(RGB(255,23,33));
	// TODO: Return a different brush if the default is not desired
	return hbr;
}

void CRegisterDlg::OnSetfocusEDITUserPsw() 
{
	// TODO: Add your control notification handler code here
	m_stRemark.SetWindowText("请输入您的密码,9位以内");		
}

void CRegisterDlg::OnSetfocusEDITUserEmail() 
{
	// TODO: Add your control notification handler code here
	m_stRemark.SetWindowText("请输入常用的邮箱,以便您的同事联系您");		
}

void CRegisterDlg::OnSetfocusEDITUserTel() 
{
	// TODO: Add your control notification handler code here
	m_stRemark.SetWindowText("请输入办公用电话,以便您的同事联系您");		
}

void CRegisterDlg::OnSetfocusCOMBOUserDptm() 
{
	// TODO: Add your control notification handler code here
	if(m_cmUserDptm.GetCurSel() == 0)
	{
		m_cmUserDptm.SetCurSel(-1);
	}
	m_stRemark.SetWindowText("请输入您的部门,以便您的同事认识您");		
}

void CRegisterDlg::OnSetfocusCOMBOUserDuty() 
{
	// TODO: Add your control notification handler code here
	if(m_cmUserDuty.GetCurSel() == 0)
	{
		m_cmUserDuty.SetCurSel(-1);
	}

	m_stRemark.SetWindowText("请输入您的职位,以便您的同事认识您");	
	
}

void CRegisterDlg::OnSetfocusCOMBOUserSex() 
{
	// TODO: Add your control notification handler code here
	m_stRemark.SetWindowText("请输入您的性别,以便您的同事认识您");		
}

void CRegisterDlg::OnButClear() 
{
	// TODO: Add your control notification handler code here

	m_UserEmail="";
	m_UserName="";
	m_UserPsw="";
	m_UserTel="";
	UpdateData(false);

	m_cmUserSex.SetCurSel(0);
	m_cmUserDptm.SetCurSel(0);
	m_cmUserDuty.SetCurSel(0);

	SetDlgItemStatus(true);
	m_ClntSock.CloseClient();
}

void CRegisterDlg::OnSelchangeCOMBOUserSex() 
{
	// TODO: Add your control notification handler code here
	m_cmUserSex.GetLBText(m_cmUserSex.GetCurSel(),m_UserSex);
}

void CRegisterDlg::OnSelchangeCOMBOUserDptm() 
{
	// TODO: Add your control notification handler code here
	m_cmUserDptm.GetLBText(m_cmUserDptm.GetCurSel(),m_UserDptm);	
}

void CRegisterDlg::OnSelchangeCOMBOUserDuty() 
{
	// TODO: Add your control notification handler code here
	m_cmUserDuty.GetLBText(m_cmUserDuty.GetCurSel(),m_UserDuty);	
}


////////////////////////////////////////////////////////
//设置控件状态
void CRegisterDlg::SetDlgItemStatus(bool bStatus)
{
	GetDlgItem(IDC_EDIT_UserName)->EnableWindow(bStatus);
	GetDlgItem(IDC_EDIT_UserPsw)->EnableWindow(bStatus);
	GetDlgItem(IDC_COMBO_UserSex)->EnableWindow(bStatus);
	GetDlgItem(IDC_COMBO_UserDptm)->EnableWindow(bStatus);
	GetDlgItem(IDC_COMBO_UserDuty)->EnableWindow(bStatus);
	GetDlgItem(IDC_EDIT_UserTel)->EnableWindow(bStatus);
	GetDlgItem(IDC_EDIT_UserEmail)->EnableWindow(bStatus);
	GetDlgItem(IDC_BUT_SUBMIT)->EnableWindow(bStatus);

}

void CRegisterDlg::OnKillfocusCOMBOUserDptm() 
{
	// TODO: Add your control notification handler code here
	char tmp[25] = "";
	m_cmUserDptm.GetWindowText(tmp, 20);
	if(strlen(tmp) == 0)
	{
		m_cmUserDptm.SetCurSel(0);
	}
}

void CRegisterDlg::OnKillfocusCOMBOUserDuty() 
{
	// TODO: Add your control notification handler code here
	char tmp[25] = "";
	m_cmUserDuty.GetWindowText(tmp, 20);
	if(strlen(tmp) == 0)
	{
		m_cmUserDuty.SetCurSel(0);
	}

}

void CRegisterDlg::OnButBack() 
{
	// TODO: Add your control notification handler code here
	m_ClntSock.CloseClient();
	ShowWindow(false);
	pInitRegWnd->CenterWindow();
	pInitRegWnd->ShowWindow(true);
}


void CRegisterDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	PostMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(point.x,point.y));	
	CDialog::OnLButtonDown(nFlags, point);
}

void CRegisterDlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	CRgn  m_rgn;
	CRect rcWnd;
	GetWindowRect(rcWnd);

	m_rgn.m_hObject = CreateRoundRectRgn(0,0,rcWnd.Width()+1, rcWnd.Height()+1,16, 16 );

	this->SetWindowRgn(m_rgn,true);	
	// Do not call CDialog::OnPaint() for painting messages
}

void CRegisterDlg::OnmyClose() 
{
	// TODO: Add your control notification handler code here
	OnClose();		
}

void CRegisterDlg::OnButMin() 
{
	// TODO: Add your control notification handler code here
	PostMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0);	
}

void CRegisterDlg::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	m_ttToolTip.AddToolTip("最小化窗口", GetDlgItem(IDC_BUT_MIN));
	m_ttToolTip.AddToolTip("关闭窗口", GetDlgItem(IDC_CLOSE));
	CDialog::OnMouseMove(nFlags, point);
}

BOOL CRegisterDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(m_ttToolTip.GetToolTip().m_hWnd)
		m_ttToolTip.GetToolTip().RelayEvent(pMsg);
	return CDialog::PreTranslateMessage(pMsg);
}

void CRegisterDlg::OnBtnR() 
{
	// TODO: Add your control notification handler code here
	CWnd* pWnd = GetFocus();
	if(pWnd == GetDlgItem(IDC_BUT_BACK))
	{
		OnButBack();
	}
	else if(pWnd == GetDlgItem(IDC_BUT_CLEAR))
	{
		OnButClear();
	}
	else if(pWnd == GetDlgItem(IDC_BUT_CANCEL))
	{
		OnClose();
	}
	else
	{
		OnButSubmit();
	}
}

⌨️ 快捷键说明

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