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 CloseHandle()
  17. {
  18. CloseHandle(BDSr_key);
  19. CloseHandle(UIw_key);
  20. CloseHandle(UIr_log);
  21. CloseHandle(BDSw_log);
  22. }
  23. InitH(BDSr_key); InitH(UIw_key); InitH(BDSw_log); InitH(UIr_log);
  24. void StartBDS()
  25. {
  26. SECURITY_ATTRIBUTES sa = { sizeof(sa), NULL, TRUE };
  27. if(!CreatePipe(&BDSr_key, &UIw_key, &sa, 0))
  28. Err(TITLE, _T("Failed to create pipe_key"));
  29. if (!CreatePipe(&UIr_log, &BDSw_log, &sa, 0))
  30. Err(TITLE, _T("Failed to create pipe_log"));
  31. STARTUPINFO si = { sizeof(si) };
  32. si.dwFlags = STARTF_USESTDHANDLES;
  33. si.hStdInput = UIw_key;
  34. si.wShowWindow = SW_SHOWMINIMIZED;
  35. if (CreateProcess(
  36. L"bedrock_server.exe",
  37. NULL, NULL, NULL, TRUE, NULL, NULL, NULL, &si, &pi))
  38. {
  39. hBDS = NULL;
  40. Err(hBDS, TITLE,
  41. _T("Failed to find BDS window"));
  42. while (bool condition=0)
  43. {
  44. }
  45. }
  46. else {
  47. Err(TITLE, _T("Failed to send command to BDS!"));
  48. CloseHandle();
  49. }
  50. }
  51. void StopBDS()
  52. {
  53. SendCommand((WCHAR)"stop\n");
  54. CloseHandle();
  55. }
  56. void ForceStopBDS()
  57. {
  58. TerminateProcess(pi.hProcess,0);
  59. CloseHandle();
  60. MessageBox(hWnd,
  61. L"Òѳ¢ÊÔÇ¿ÐÐÍ£Ö¹·þÎñÆ÷", TITLE,
  62. MB_OK);
  63. }