o&c.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. CloseHandle(pi.hProcess);
  23. CloseHandle(pi.hThread);
  24. BDSr_key = UIw_key = UIr_log = BDSw_log = NULL;
  25. pi.hProcess = pi.hThread = NULL;
  26. }
  27. static void CloseHandleS()
  28. {
  29. CloseHandle(BDSr_key);
  30. CloseHandle(BDSw_log);
  31. }
  32. InitH(BDSr_key); InitH(UIw_key); InitH(BDSw_log); InitH(UIr_log);
  33. void StartBDS()
  34. {
  35. SECURITY_ATTRIBUTES sa = { sizeof(sa),NULL , TRUE };
  36. if(!CreatePipe(&BDSr_key, &UIw_key, &sa, 0))
  37. Err(_T("Failed to create pipe_key"));
  38. if (!CreatePipe(&UIr_log, &BDSw_log, &sa, 0))
  39. Err(_T("Failed to create pipe_log"));
  40. STARTUPINFO si = { sizeof(si) };
  41. si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
  42. si.hStdInput = BDSr_key;
  43. si.hStdOutput = BDSw_log;
  44. //si.wShowWindow = SW_SHOWMINIMIZED;
  45. if (CreateProcess(
  46. L"bedrock_server.exe",
  47. NULL, NULL, NULL, TRUE, NULL, NULL, NULL, &si, &pi))
  48. {
  49. CloseHandleS();
  50. }
  51. else {
  52. Err(_T("Failed to send command to BDS!"));
  53. CloseHandleA();
  54. }
  55. }
  56. void StopBDS()
  57. {
  58. if (pi.hProcess)
  59. {
  60. SendCommand_WhenStop(C("stop"));
  61. }
  62. }
  63. void ForceStopBDS()
  64. {
  65. if(pi.hProcess)
  66. {
  67. TerminateProcess(pi.hProcess, 0);
  68. CloseHandleA();
  69. MessageBox(hWnd,
  70. _T("Òѳ¢ÊÔÇ¿ÐÐÍ£Ö¹·þÎñÆ÷"), TITLE,
  71. MB_OK);
  72. }
  73. }