LoginDlg.cpp
上传用户:posgewe
上传日期:2013-05-17
资源大小:69k
文件大小:2k
源码类别:

Telnet服务器

开发平台:

Visual C++

  1. // LoginDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "MyChat.h"
  5. #include "LoginDlg.h"
  6. #include "ClientSocket.h"
  7. #include "tagHeader.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. extern CMyChatApp theApp;
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CLoginDlg dialog
  16. CLoginDlg::CLoginDlg(CClientSocket *p_Socket, CWnd* pParent /*=NULL*/)
  17. : CDialog(CLoginDlg::IDD, pParent)
  18. {
  19. ASSERT(p_Socket);
  20. m_pSocket = p_Socket;
  21. //{{AFX_DATA_INIT(CLoginDlg)
  22. m_strName = _T("");
  23. m_strServer = _T("192.168.1.12");
  24. //}}AFX_DATA_INIT
  25. }
  26. void CLoginDlg::DoDataExchange(CDataExchange* pDX)
  27. {
  28. CDialog::DoDataExchange(pDX);
  29. //{{AFX_DATA_MAP(CLoginDlg)
  30. DDX_Text(pDX, IDC_EDIT_NAME, m_strName);
  31. DDX_Text(pDX, IDC_EDIT_SERVER, m_strServer);
  32. //}}AFX_DATA_MAP
  33. }
  34. BEGIN_MESSAGE_MAP(CLoginDlg, CDialog)
  35. //{{AFX_MSG_MAP(CLoginDlg)
  36. //}}AFX_MSG_MAP
  37. END_MESSAGE_MAP()
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CLoginDlg message handlers
  40. void CLoginDlg::OnOK() 
  41. {
  42. // TODO: Add extra validation here
  43. UpdateData();
  44. // m_pSocket->m_strName = this->m_strName;
  45. if(!m_pSocket->Create())
  46. {
  47. AfxMessageBox("网络创建错误!!!");
  48. m_pSocket->Close();
  49. return;
  50. }
  51. if(!m_pSocket->Connect(m_strServer,9999))
  52. {
  53. AfxMessageBox("连接服务器失败!!!");
  54. m_pSocket->Close();
  55. return;
  56. }
  57. Header head;
  58. head.type = LOGIN_IO;
  59. head.len = m_strName.GetLength();
  60. m_pSocket->Send((char *)&head,sizeof(Header));
  61. m_pSocket->Send(m_strName,m_strName.GetLength());
  62. theApp.m_strName = m_strName;
  63. CDialog::OnOK();
  64. }