o&c.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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.wShowWindow = SW_SHOWMINIMIZED;
  40. if (CreateProcess(
  41. L"bedrock_server.exe",
  42. NULL, NULL, NULL, TRUE, NULL, NULL, NULL, &si, &pi))
  43. {
  44. CloseHandleS();
  45. }
  46. else {
  47. Err(_T("Failed to send command to BDS!"));
  48. CloseHandleA();
  49. }
  50. }
  51. void StopBDS()
  52. {
  53. SendCommand(C("stop"));
  54. CloseHandleA();
  55. }
  56. void ForceStopBDS()
  57. {
  58. TerminateProcess(pi.hProcess,0);
  59. CloseHandleA();
  60. MessageBox(hWnd,
  61. _T("Òѳ¢ÊÔÇ¿ÐÐÍ£Ö¹·þÎñÆ÷"), TITLE,
  62. MB_OK);
  63. }