LoginDlg.cpp
资源名称:xcchat.rar [点击查看]
上传用户:posgewe
上传日期:2013-05-17
资源大小:69k
文件大小:2k
源码类别:
Telnet服务器
开发平台:
Visual C++
- // LoginDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "MyChat.h"
- #include "LoginDlg.h"
- #include "ClientSocket.h"
- #include "tagHeader.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- extern CMyChatApp theApp;
- /////////////////////////////////////////////////////////////////////////////
- // CLoginDlg dialog
- CLoginDlg::CLoginDlg(CClientSocket *p_Socket, CWnd* pParent /*=NULL*/)
- : CDialog(CLoginDlg::IDD, pParent)
- {
- ASSERT(p_Socket);
- m_pSocket = p_Socket;
- //{{AFX_DATA_INIT(CLoginDlg)
- m_strName = _T("");
- m_strServer = _T("192.168.1.12");
- //}}AFX_DATA_INIT
- }
- void CLoginDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CLoginDlg)
- DDX_Text(pDX, IDC_EDIT_NAME, m_strName);
- DDX_Text(pDX, IDC_EDIT_SERVER, m_strServer);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CLoginDlg, CDialog)
- //{{AFX_MSG_MAP(CLoginDlg)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CLoginDlg message handlers
- void CLoginDlg::OnOK()
- {
- // TODO: Add extra validation here
- UpdateData();
- // m_pSocket->m_strName = this->m_strName;
- if(!m_pSocket->Create())
- {
- AfxMessageBox("网络创建错误!!!");
- m_pSocket->Close();
- return;
- }
- if(!m_pSocket->Connect(m_strServer,9999))
- {
- AfxMessageBox("连接服务器失败!!!");
- m_pSocket->Close();
- return;
- }
- Header head;
- head.type = LOGIN_IO;
- head.len = m_strName.GetLength();
- m_pSocket->Send((char *)&head,sizeof(Header));
- m_pSocket->Send(m_strName,m_strName.GetLength());
- theApp.m_strName = m_strName;
- CDialog::OnOK();
- }