mainProc.cpp 6.0 KB

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