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

模拟服务器

开发平台:

C/C++

  1. /*****************************************************************************************
  2. Broadcast message Window
  3. Copyright : Kingsoft 2002
  4. Author :   Wooy(Wu yue)
  5. CreateTime: 2002-12-25
  6. *****************************************************************************************/
  7. #include "KEngine.h"
  8. #include "BroadCastWnd.h"
  9. #include "SwordOnLineServer.h"
  10. #include <commctrl.h>
  11. #include "../Core/src/CoreServerShell.h"
  12. #include "../Engine/src/Text.h"
  13. KBroadCastWnd* KBroadCastWnd::m_pSelf = NULL;
  14. //--------------------------------------------------------------------------
  15. // 功能:窗口函数
  16. //--------------------------------------------------------------------------
  17. LRESULT CALLBACK KBroadCastWnd::WndProc(HWND hWnd, unsigned int uMsg, unsigned int uParam, int nParam)
  18. {
  19. switch(uMsg)
  20. {
  21. case WM_COMMAND:
  22. switch (LOWORD(uParam))
  23. {
  24. case IDOK:
  25. if (m_pSelf)
  26. m_pSelf->OnSend();
  27. break;
  28. case IDCANCEL:
  29. if (m_pSelf)
  30. Close();
  31. else
  32. ::DestroyWindow(hWnd);
  33. break;
  34. }
  35. break;
  36. }
  37. return 0;
  38. }
  39. KBroadCastWnd::KBroadCastWnd()
  40. {
  41. m_hWnd = NULL;
  42. m_pServer = NULL;
  43. }
  44. bool KBroadCastWnd::Create(HINSTANCE hModule, KSwordOnLineSever* pServer)
  45. {
  46. if (m_pSelf)
  47. {
  48. BringWindowToTop(m_pSelf->m_hWnd);
  49. return true;
  50. }
  51. if (hModule == NULL)
  52. return false;
  53. m_pSelf = new KBroadCastWnd;
  54. if (m_pSelf)
  55. {
  56. m_pSelf->m_hWnd = ::CreateDialog(hModule,
  57. MAKEINTRESOURCE(IDD), NULL, (DLGPROC)WndProc);
  58. if (m_pSelf->m_hWnd)
  59. {
  60. m_pSelf->m_pServer = pServer;
  61. ::ShowWindow(m_pSelf->m_hWnd, SW_SHOW);
  62. return true;
  63. }
  64. else
  65. {
  66. delete (m_pSelf);
  67. m_pSelf = NULL;
  68. }
  69. }
  70. return false;
  71. }
  72. void KBroadCastWnd::Close()
  73. {
  74. if (m_pSelf)
  75. {
  76. if (m_pSelf->m_hWnd)
  77. {
  78. ::DestroyWindow(m_pSelf->m_hWnd);
  79. m_pSelf->m_hWnd = NULL;
  80. }
  81. m_pSelf->m_pServer = NULL;
  82. delete (m_pSelf);
  83. m_pSelf = NULL;
  84. }
  85. }
  86. void KBroadCastWnd::OnSend()
  87. {
  88. if (m_pServer && m_hWnd)
  89. {
  90. char Message[300] = "";
  91. int nLen;
  92. nLen = ::GetDlgItemText(m_hWnd, IDC_MSG_EDIT, Message, sizeof(Message));
  93. ::SetDlgItemText(m_hWnd, IDC_INFO, "");
  94. if (nLen > 0)
  95. {
  96. if (nLen > 256)
  97. ::SetDlgItemText(m_hWnd, IDC_INFO, "Msg exceed max len.");
  98. else if (m_pServer->OperationRequest(SSOI_BROADCASTING, (unsigned int)Message, nLen))
  99. {
  100. ::SetDlgItemText(m_hWnd, IDC_INFO, "Message has been delivered.");
  101. ::SetDlgItemText(m_hWnd, IDC_MSG_EDIT, "");
  102. }
  103. else
  104. {
  105. ::SetDlgItemText(m_hWnd, IDC_INFO, "Message deliver FAILED!");
  106. }
  107. }
  108. }
  109. }