o&c.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 = GetConsoleWindow();
  40. Err(hBDS, TITLE,
  41. _T("Failed to find BDS window"));
  42. /*
  43. HMENU hmenu = GetSystemMenu(hBDS, false);
  44. RemoveMenu(hmenu, SC_CLOSE, MF_BYCOMMAND);
  45. LONG style = GetWindowLong(hBDS, GWL_STYLE);
  46. style &= ~(WS_MINIMIZEBOX);
  47. SetWindowLong(hBDS, GWL_STYLE, style);
  48. SetWindowPos(hBDS, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
  49. ShowWindow(hBDS, SW_SHOWNORMAL);
  50. DestroyMenu(hmenu);
  51. */
  52. while (bool condition=0)
  53. {
  54. }
  55. }
  56. else {
  57. Err(TITLE, _T("Failed to send command to BDS!"));
  58. CloseHandle();
  59. }
  60. }
  61. void StopBDS()
  62. {
  63. SendCommand((WCHAR)"stop\n");
  64. CloseHandle();
  65. }
  66. void ForceStopBDS()
  67. {
  68. TerminateProcess(pi.hProcess,0);
  69. CloseHandle();
  70. MessageBox(hWnd,
  71. L"Òѳ¢ÊÔÇ¿ÐÐÍ£Ö¹·þÎñÆ÷", TITLE,
  72. MB_OK);
  73. }