o&c.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include "Win32.h"
  2. #include "ID.h"
  3. #include "Function.h"
  4. static void AutoClose(DWORD time, LPCWSTR title)
  5. {
  6. Sleep(time*1000);
  7. HWND box = FindWindow(NULL, title);
  8. if (box)
  9. {
  10. SendMessage(box, WM_CLOSE, 0, 0);
  11. }
  12. }
  13. //Open&Stop
  14. PROCESS_INFORMATION pi;
  15. HWND hBDS;
  16. static void CloseHandleA()
  17. {
  18. CloseHandle(BDSr_key);
  19. CloseHandle(UIw_key);
  20. CloseHandle(UIr_log);
  21. CloseHandle(BDSw_log);
  22. }
  23. static void CloseHandleS()
  24. {
  25. CloseHandle(BDSr_key);
  26. CloseHandle(BDSw_log);
  27. }
  28. InitH(BDSr_key); InitH(UIw_key); InitH(BDSw_log); InitH(UIr_log);
  29. void StartBDS()
  30. {
  31. SECURITY_ATTRIBUTES sa = { sizeof(sa), NULL, TRUE };
  32. if(!CreatePipe(&BDSr_key, &UIw_key, &sa, 0))
  33. Err(_T("Failed to create pipe_key"));
  34. if (!CreatePipe(&UIr_log, &BDSw_log, &sa, 0))
  35. Err(_T("Failed to create pipe_log"));
  36. STARTUPINFO si = { sizeof(si) };
  37. si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
  38. si.hStdInput = BDSr_key;
  39. si.hStdOutput = BDSw_log;
  40. si.wShowWindow = SW_SHOWMINIMIZED;
  41. if (CreateProcess(
  42. L"bedrock_server.exe",
  43. NULL, NULL, NULL, TRUE, NULL, NULL, NULL, &si, &pi))
  44. {
  45. CloseHandleS();
  46. }
  47. else {
  48. Err(_T("Failed to send command to BDS!"));
  49. CloseHandleA();
  50. }
  51. }
  52. void StopBDS()
  53. {
  54. if (pi.hProcess)
  55. {
  56. SendCommand(C("stop"));
  57. CloseHandleA();
  58. }
  59. }
  60. void ForceStopBDS()
  61. {
  62. if(pi.hProcess)
  63. {
  64. TerminateProcess(pi.hProcess, 0);
  65. CloseHandleA();
  66. MessageBox(hWnd,
  67. _T("Òѳ¢ÊÔÇ¿ÐÐÍ£Ö¹·þÎñÆ÷"), TITLE,
  68. MB_OK);
  69. }
  70. }