mainProc.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #include "Win32.h"
  2. #include "ID.h"
  3. #include "Function.h"
  4. #include "SharedValue.h"
  5. InitHW(hTime); InitHW(hWeather); InitHW(hLog); InitHW(hPlayer);
  6. LRESULT CALLBACK TimeProc(HWND hWnd1, UINT msg, WPARAM wParam, LPARAM lParam);
  7. LRESULT CALLBACK WeatherProc(HWND hWnd1, UINT msg, WPARAM wParam, LPARAM lParam);
  8. LRESULT CALLBACK LogProc(HWND hWnd1, UINT msg, WPARAM wParam, LPARAM lParam);
  9. LRESULT CALLBACK PlayerProc(HWND hWnd1, UINT msg, WPARAM wParam, LPARAM lParam);
  10. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  11. {
  12. PAINTSTRUCT ps;
  13. HDC hdc;
  14. TCHAR greeting[] = _T("by xksyu2021\nYou must obey / 您必须遵守 Minecraft EULA.");
  15. switch (message)
  16. {
  17. case WM_CREATE:
  18. {
  19. ClearLog();
  20. //StartBDS();
  21. HINSTANCE HI_Log = NULL;
  22. hLog = CreateLogWindow(
  23. _T("日志"),
  24. 1000, 690,
  25. LogProc, _T("log"), HI_Log);
  26. Log(GetDlgItem(hLog, ID_LOG));
  27. break;
  28. }
  29. case WM_PAINT:
  30. hdc = BeginPaint(hWnd, &ps);
  31. TextOut(hdc,
  32. 5, 5,
  33. greeting, _tcslen(greeting));
  34. EndPaint(hWnd, &ps);
  35. break;
  36. case WM_COMMAND:
  37. {
  38. WORD wmId = LOWORD(wParam);
  39. switch (wmId)
  40. {
  41. case ID_START:
  42. ClearLog();
  43. StartBDS();
  44. break;
  45. case ID_STOP:
  46. StopBDS();
  47. break;
  48. case ID_STOP_FORCE:
  49. if (MessageBox(hWnd,
  50. L"强制关闭服务器是非常危险的操作!\n是否仍要继续?", TITLE,
  51. MB_OKCANCEL | MB_APPLMODAL | MB_ICONWARNING)
  52. == 1)
  53. {
  54. ForceStopBDS();
  55. }
  56. break;
  57. case ID_DUWP:
  58. ShellExecute(
  59. NULL, L"open",
  60. L"C:\\windows\\system32\\cmd.exe",
  61. L"/c start powershell.exe -Command \"Get-ChildItem -Path Registry::'HKCU\\Software\\Classes\\Local Settings\\Software\\Microsoft\\Windows\\CurrentVersion\\AppContainer\\Mappings\\' -name | ForEach-Object {CheckNetIsolation.exe LoopbackExempt -a -p=$_}\"" ,
  62. NULL, SW_SHOWNORMAL
  63. );
  64. break;
  65. case ID_CMD_OK:
  66. {
  67. if (GetWindowTextLength(GetDlgItem(hWnd, ID_CMD_KEY)) > 0)
  68. {
  69. char Command[1024] = { 0 };
  70. GetWindowTextA(GetDlgItem(hWnd, ID_CMD_KEY), Command, 1024);
  71. std::string temp(Command);
  72. temp += "\n";
  73. SendCommand(temp.c_str());
  74. }
  75. break;
  76. }
  77. case ID_CMD_CLEAR:
  78. SetWindowText(GetDlgItem(hWnd, ID_CMD_KEY), _T(" "));
  79. break;
  80. case ID_FC_Weather:
  81. if (!hWeather)
  82. {
  83. HINSTANCE HI_FC_weather = NULL;
  84. hWeather = CreateChildWindow(hWnd,
  85. _T("天气控制"),
  86. 400, 370,
  87. WeatherProc, _T("fc_wea"), HI_FC_weather);
  88. }
  89. break;
  90. case ID_FC_Time:
  91. if (!hTime)
  92. {
  93. HINSTANCE HI_FC_time = NULL;
  94. hTime = CreateChildWindow(hWnd,
  95. _T("时间控制"),
  96. 400, 415,
  97. TimeProc, _T("fc_time"), HI_FC_time);
  98. }
  99. break;
  100. case ID_FS_WT:
  101. SendCommand(C("time query daytime"));
  102. SendCommand(C("weather query"));
  103. break;
  104. case ID_FC_PLAYER:
  105. if (!hPlayer)
  106. {
  107. HINSTANCE HI_FC_player = NULL;
  108. hPlayer = CreateChildWindow(hWnd,
  109. _T("玩家面板"),
  110. 380, 390,
  111. PlayerProc, _T("fc_player"), HI_FC_player);
  112. }
  113. break;
  114. case ID_FS_LIST:
  115. SendCommand(C("list"));
  116. break;
  117. }
  118. break;
  119. }
  120. case WM_CLOSE:
  121. if (MessageBox(hWnd,
  122. L"您正在关闭主程序!\n若服务端正在运行,将被一并正常关闭。\n若有正在执行的任务,将被强行停止。", TITLE,
  123. MB_OKCANCEL | MB_OKCANCEL | MB_ICONWARNING)
  124. == 1)
  125. {
  126. StopBDS();
  127. PostQuitMessage(0);
  128. }
  129. break;
  130. case WM_DESTROY:
  131. PostQuitMessage(0);
  132. break;
  133. default:
  134. return DefWindowProc(hWnd, message, wParam, lParam);
  135. break;
  136. }
  137. return 0;
  138. }