www.pudn.com > QQ2004_Source_0.01.rar > StartupDlg.cpp


// StartupDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "QQClient.h" 
#include "StartupDlg.h" 
#include "RegistryDlg.h" 
 
#include "QQSocket.h" 
#include "Communication.h" 
#include "xmlparser.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CStartupDlg dialog 
 
 
CStartupDlg::CStartupDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CStartupDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CStartupDlg) 
	_password	= _T(""); 
	_userID		= _T(""); 
	//}}AFX_DATA_INIT 
} 
 
 
void CStartupDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CStartupDlg) 
	DDX_Text(pDX, IDC_EDIT_PASSWORD, _password); 
	DDV_MaxChars(pDX, _password, 8); 
	DDX_Text(pDX, IDC_EDIT_USERID, _userID); 
	DDX_Control(pDX, IDC_IPADDRESS, _IPCtrl); 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CStartupDlg, CDialog) 
	//{{AFX_MSG_MAP(CStartupDlg) 
	ON_BN_CLICKED(IDC_BTN_LOGON, OnBtnLogOn) 
	ON_BN_CLICKED(IDC_BTN_REG, OnBtnReg) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CStartupDlg message handlers 
 
void CStartupDlg::OnBtnLogOn()  
{ 
	// TODO: Add your control notification handler code here 
	UpdateData(TRUE); 
 
	_serverIP = getServerIPAddr(); 
	CCommunication comm; 
	if (comm.init(_serverIP) != S_OK) 
		return ; 
 
	if (comm.sendLogonRequest(_userID, _password) != S_OK) 
		return ; 
	 
	CXMLParser response; 
	HRESULT ret = comm.receiveResponse(response); 
	if (ret != S_OK) 
		return ; 
 
	CElement *root = response.get_root(); 
	_nickname = root->getChildContent(_T("nickname")); 
 
	EndDialog(IDOK); 
} 
 
 
 
void CStartupDlg::OnBtnReg()  
{ 
	// TODO: Add your control notification handler code here 
	CRegistryDlg dlg; 
	if (dlg.DoModal() != IDOK) 
		return ; 
 
	CString serverIP = getServerIPAddr(); 
	CCommunication comm; 
	if (comm.init(serverIP) != S_OK) 
		return ; 
 
	if (comm.sendRegisterRequest(dlg._userID, dlg._password, dlg._nickname) != S_OK) 
		return ; 
 
	CXMLParser response; 
	HRESULT ret = comm.receiveResponse(response); 
	if (ret != S_OK) 
		return ; 
 
	AfxMessageBox(_T("×¢²á³É¹¦")); 
	 
	_userID = dlg._userID; 
	_password = dlg._password; 
	UpdateData(FALSE); 
} 
 
BOOL CStartupDlg::OnInitDialog() 
{ 
	CDialog::OnInitDialog(); 
 
	// TODO:  Add extra initialization here 
	_IPCtrl.SetAddress(127, 0, 0, 1); 
 
	return TRUE;  // return TRUE unless you set the focus to a control 
	// EXCEPTION: OCX Property Pages should return FALSE 
}