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

Telnet服务器

开发平台:

Visual C++

  1. // ChatServerDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ChatServer.h"
  5. #include "ChatServerDlg.h"
  6. #include "ServerSocket.h"
  7. #include "ClientSocket.h"
  8. #include "tagHeader.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CAboutDlg dialog used for App About
  16. class CAboutDlg : public CDialog
  17. {
  18. public:
  19. CAboutDlg();
  20. // Dialog Data
  21. //{{AFX_DATA(CAboutDlg)
  22. enum { IDD = IDD_ABOUTBOX };
  23. //}}AFX_DATA
  24. // ClassWizard generated virtual function overrides
  25. //{{AFX_VIRTUAL(CAboutDlg)
  26. protected:
  27. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  28. //}}AFX_VIRTUAL
  29. // Implementation
  30. protected:
  31. //{{AFX_MSG(CAboutDlg)
  32. //}}AFX_MSG
  33. DECLARE_MESSAGE_MAP()
  34. };
  35. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  36. {
  37. //{{AFX_DATA_INIT(CAboutDlg)
  38. //}}AFX_DATA_INIT
  39. }
  40. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  41. {
  42. CDialog::DoDataExchange(pDX);
  43. //{{AFX_DATA_MAP(CAboutDlg)
  44. //}}AFX_DATA_MAP
  45. }
  46. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  47. //{{AFX_MSG_MAP(CAboutDlg)
  48. // No message handlers
  49. //}}AFX_MSG_MAP
  50. END_MESSAGE_MAP()
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CChatServerDlg dialog
  53. CChatServerDlg::CChatServerDlg(CWnd* pParent /*=NULL*/)
  54. : CDialog(CChatServerDlg::IDD, pParent)
  55. {
  56. //{{AFX_DATA_INIT(CChatServerDlg)
  57. // NOTE: the ClassWizard will add member initialization here
  58. //}}AFX_DATA_INIT
  59. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  60. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  61. }
  62. void CChatServerDlg::DoDataExchange(CDataExchange* pDX)
  63. {
  64. CDialog::DoDataExchange(pDX);
  65. //{{AFX_DATA_MAP(CChatServerDlg)
  66. DDX_Control(pDX, IDC_LIST_USER, m_UserList);
  67. //}}AFX_DATA_MAP
  68. }
  69. BEGIN_MESSAGE_MAP(CChatServerDlg, CDialog)
  70. //{{AFX_MSG_MAP(CChatServerDlg)
  71. ON_WM_SYSCOMMAND()
  72. ON_WM_PAINT()
  73. ON_WM_QUERYDRAGICON()
  74. //}}AFX_MSG_MAP
  75. END_MESSAGE_MAP()
  76. /////////////////////////////////////////////////////////////////////////////
  77. // CChatServerDlg message handlers
  78. BOOL CChatServerDlg::OnInitDialog()
  79. {
  80. CDialog::OnInitDialog();
  81. // Add "About..." menu item to system menu.
  82. // IDM_ABOUTBOX must be in the system command range.
  83. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  84. ASSERT(IDM_ABOUTBOX < 0xF000);
  85. CMenu* pSysMenu = GetSystemMenu(FALSE);
  86. if (pSysMenu != NULL)
  87. {
  88. CString strAboutMenu;
  89. strAboutMenu.LoadString(IDS_ABOUTBOX);
  90. if (!strAboutMenu.IsEmpty())
  91. {
  92. pSysMenu->AppendMenu(MF_SEPARATOR);
  93. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  94. }
  95. }
  96. // Set the icon for this dialog.  The framework does this automatically
  97. //  when the application's main window is not a dialog
  98. SetIcon(m_hIcon, TRUE); // Set big icon
  99. SetIcon(m_hIcon, FALSE); // Set small icon
  100. // TODO: Add extra initialization here
  101. ((CEdit *)GetDlgItem(IDC_EDIT_INFO))->ReplaceSel("服务器初始化成功...rn");
  102. return TRUE;  // return TRUE  unless you set the focus to a control
  103. }
  104. void CChatServerDlg::OnSysCommand(UINT nID, LPARAM lParam)
  105. {
  106. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  107. {
  108. CAboutDlg dlgAbout;
  109. dlgAbout.DoModal();
  110. }
  111. else
  112. {
  113. CDialog::OnSysCommand(nID, lParam);
  114. }
  115. }
  116. // If you add a minimize button to your dialog, you will need the code below
  117. //  to draw the icon.  For MFC applications using the document/view model,
  118. //  this is automatically done for you by the framework.
  119. void CChatServerDlg::OnPaint() 
  120. {
  121. if (IsIconic())
  122. {
  123. CPaintDC dc(this); // device context for painting
  124. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  125. // Center icon in client rectangle
  126. int cxIcon = GetSystemMetrics(SM_CXICON);
  127. int cyIcon = GetSystemMetrics(SM_CYICON);
  128. CRect rect;
  129. GetClientRect(&rect);
  130. int x = (rect.Width() - cxIcon + 1) / 2;
  131. int y = (rect.Height() - cyIcon + 1) / 2;
  132. // Draw the icon
  133. dc.DrawIcon(x, y, m_hIcon);
  134. }
  135. else
  136. {
  137. CDialog::OnPaint();
  138. }
  139. }
  140. // The system calls this to obtain the cursor to display while the user drags
  141. //  the minimized window.
  142. HCURSOR CChatServerDlg::OnQueryDragIcon()
  143. {
  144. return (HCURSOR) m_hIcon;
  145. }
  146. void CChatServerDlg::UpdateUser(CClientSocket *pSocket)
  147. {
  148. CString user_info;
  149. if(pSocket != NULL)
  150. {
  151. m_UserList.ResetContent();
  152. CClientSocket *pSock = NULL;
  153. POSITION pos = pSocket->clist->GetHeadPosition();
  154. while(pos != NULL)
  155. {
  156. pSock = (CClientSocket *)pSocket->clist->GetNext(pos);
  157. m_UserList.AddString(pSock->m_strName);
  158. user_info += (pSock->m_strName + "&");
  159. }
  160. Header head;
  161. head.type = LOGIN_IO;
  162. head.len = user_info.GetLength();
  163. POSITION po = pSocket->clist->GetHeadPosition();
  164. while(po != NULL)
  165. {
  166. pSock = (CClientSocket *)pSocket->clist->GetNext(po);
  167. pSock->Send((char *)&head, sizeof(Header));
  168. pSock->Send((LPCTSTR)user_info, user_info.GetLength());
  169. }
  170. }
  171. }