ClientConnectListWnd.cpp
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:4k
源码类别:

模拟服务器

开发平台:

C/C++

  1. /*****************************************************************************************
  2. Client Connection List Window
  3. Copyright : Kingsoft 2002
  4. Author :   Wooy(Wu yue)
  5. CreateTime: 2002-12-24
  6. *****************************************************************************************/
  7. #include "KEngine.h"
  8. #include "ClientConnectListWnd.h"
  9. #include "SwordOnLineServer.h"
  10. #include <commctrl.h>
  11. KClientConnectListWnd* KClientConnectListWnd::m_pSelf = NULL;
  12. //--------------------------------------------------------------------------
  13. // 功能:窗口函数
  14. //--------------------------------------------------------------------------
  15. LRESULT CALLBACK KClientConnectListWnd::WndProc(HWND hWnd, unsigned int uMsg, unsigned int uParam, int nParam)
  16. {
  17. switch(uMsg)
  18. {
  19. case WM_COMMAND:
  20. switch (LOWORD(uParam))
  21. {
  22. case ID_REFRESH:
  23. if (m_pSelf)
  24. m_pSelf->UpdateData();
  25. break;
  26. case ID_EXPORT:
  27. if (m_pSelf)
  28. m_pSelf->OnExport();
  29. break;
  30. case ID_EXIT:
  31. if (m_pSelf)
  32. Close();
  33. else
  34. ::DestroyWindow(hWnd);
  35. break;
  36. }
  37. break;
  38. }
  39. return 0;
  40. }
  41. KClientConnectListWnd::KClientConnectListWnd()
  42. {
  43. m_hWnd = NULL;
  44. m_hListWnd = NULL;
  45. m_hModule = NULL;
  46. m_pServer = NULL;
  47. }
  48. bool KClientConnectListWnd::Create(HINSTANCE hModule, KSwordOnLineSever* pServer)
  49. {
  50. if (m_pSelf)
  51. {
  52. BringWindowToTop(m_pSelf->m_hWnd);
  53. return true;
  54. }
  55. if (hModule == NULL)
  56. return false;
  57. m_pSelf = new KClientConnectListWnd;
  58. if (m_pSelf)
  59. {
  60. m_pSelf->m_hWnd = ::CreateDialog(hModule,
  61. MAKEINTRESOURCE(IDD), NULL, (DLGPROC)WndProc);
  62. if (m_pSelf->m_hWnd)
  63. {
  64. m_pSelf->m_hModule = hModule;
  65. m_pSelf->m_pServer = pServer;
  66. m_pSelf->OnInitWnd();
  67. m_pSelf->UpdateData();
  68. return true;
  69. }
  70. else
  71. {
  72. delete (m_pSelf);
  73. m_pSelf = NULL;
  74. }
  75. }
  76. return false;
  77. }
  78. void KClientConnectListWnd::OnInitWnd()
  79. {
  80. m_hListWnd = GetDlgItem(m_hWnd, IDC_LIST);
  81. //设置文件列表框的属性与分栏信息
  82. ListView_SetExtendedListViewStyle(m_hListWnd,
  83. ListView_GetExtendedListViewStyle(m_hListWnd) | LVS_EX_FULLROWSELECT);
  84. LVCOLUMN lvc;
  85. char szHeaderText[40];
  86. lvc.mask = LVCF_TEXT | LVCF_WIDTH;
  87. lvc.pszText = szHeaderText;
  88. lvc.cchTextMax = 40;
  89. lvc.cx = 112;
  90. strcpy(szHeaderText, "Client Address");
  91. ListView_InsertColumn(m_hListWnd, 0, &lvc);
  92. lvc.mask |= LVCF_SUBITEM;
  93. lvc.cx = 200;
  94. lvc.iSubItem = 1;
  95. strcpy(szHeaderText, "Character Name");
  96. ListView_InsertColumn(m_hListWnd, 1, &lvc);
  97. ::ShowWindow(m_pSelf->m_hWnd, SW_SHOW);
  98. }
  99. void KClientConnectListWnd::UpdateData()
  100. {
  101. ListView_DeleteAllItems(m_hListWnd);
  102. SetDlgItemInt(m_hWnd, IDC_CLIENT_NUM, 0, false);
  103. SetDlgItemInt(m_hWnd, IDC_CHARACTER_NUM, 0, false);
  104. if (m_pServer && m_hListWnd)
  105. {
  106. int nNumClient = 0;
  107. int nNumCharacter = 0;
  108. int nPos = 0;
  109. char Buffer[32];
  110. LV_ITEM lvi = { 0 };
  111. lvi.mask = LVIF_TEXT;
  112. ClientConnectInfo Info;
  113. lvi.pszText = Buffer;
  114. lvi.cchTextMax = 16;
  115. while(m_pServer->GetClientConnectInfo(&Info, nPos))
  116. {
  117. strcpy(Buffer, Info.AddrInfo);
  118. lvi.iItem       = nNumClient;
  119. lvi.iItem = ListView_InsertItem(m_hListWnd, &lvi);
  120. if (Info.Character[0])
  121. {
  122. nNumCharacter++;
  123. ListView_SetItemText(m_hListWnd, lvi.iItem, 1, Info.Character);
  124. }
  125. nNumClient ++;
  126. }
  127. SetDlgItemInt(m_hWnd, IDC_CLIENT_NUM, nNumClient, false);
  128. SetDlgItemInt(m_hWnd, IDC_CHARACTER_NUM, nNumCharacter, false);
  129. }
  130. }
  131. void KClientConnectListWnd::Close()
  132. {
  133. if (m_pSelf)
  134. {
  135. m_pSelf->m_hListWnd = NULL;
  136. if (m_pSelf->m_hWnd)
  137. {
  138. ::DestroyWindow(m_pSelf->m_hWnd);
  139. m_pSelf->m_hWnd = NULL;
  140. }
  141. m_pSelf->m_pServer = NULL;
  142. m_pSelf->m_hModule = NULL;
  143. delete (m_pSelf);
  144. m_pSelf = NULL;
  145. }
  146. }
  147. void KClientConnectListWnd::OnExport()
  148. {
  149. }