mainProc.cpp 5.0 KB

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