Răsfoiți Sursa

update 25/8/11

XKSYU2021 3 luni în urmă
părinte
comite
8834156192

+ 5 - 1
Ui for BDS/Function.h

@@ -5,4 +5,8 @@ int Err(HWND hwnd, LPCTSTR message, LPCTSTR title);
 int Err(ATOM atom, LPCTSTR message, LPCTSTR title);
 int Err(LPCTSTR title, LPCTSTR message);
 
-void StartBDS();
+void StartBDS();
+void StopBDS();
+void ForceStopBDS();
+
+bool SendCommand(WCHAR command);

+ 9 - 4
Ui for BDS/ID.h

@@ -1,11 +1,16 @@
 #pragma once
 
-extern HANDLE UIw, BDSr, UIr, BDSw;
+#define InitH(x) HANDLE x = NULL
+extern HANDLE UIw_key, BDSr_key, UIr_log, BDSw_log;
 extern HWND hWnd;
 
 #define TITLE _T("UI for BDS")
 // #define ID_
 
-#define ID_START 1001
-#define ID_STOP 1002
-#define ID_STOP_FROCE 1003
+#define ID_START 10001
+#define ID_STOP 10002
+#define ID_STOP_FORCE 10003
+#define ID_CMD_KEY 20001
+#define ID_CMD_OK 20002
+#define ID_FC_Weather 30100
+#define ID_FC_Time 30200

+ 67 - 4
Ui for BDS/MAIN.cpp

@@ -67,13 +67,48 @@ int WINAPI WinMain(
         (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), NULL
     );
     HWND hStop = CreateWindow(
-        L"BUTTON", L"启动",
+        L"BUTTON", L"停止",
         WS_VISIBLE | WS_CHILD,
-        30, 100, 70, 40,
-        hWnd, (HMENU)ID_START,
+        120, 100, 70, 40,
+        hWnd, (HMENU)ID_STOP,
+        (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), NULL
+    );
+    HWND hStopForce = CreateWindow(
+        L"BUTTON", L"强行停止",
+        WS_VISIBLE | WS_CHILD,
+        210, 100, 110, 40,
+        hWnd, (HMENU)ID_STOP_FORCE,
         (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), NULL
     );
 
+    HWND hLabel_2 = CreateWindow(
+        L"STATIC", L"命令输入",
+        WS_VISIBLE | WS_CHILD,
+        30, 155, 90, 30,
+        hWnd, NULL,
+        (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), NULL
+    );
+    HWND hCmdKey = CreateWindow(
+        L"EDIT", NULL,
+        WS_VISIBLE | WS_CHILD | WS_BORDER | ES_LEFT | ES_MULTILINE | ES_AUTOHSCROLL,
+        30, 200, 350, 40,
+        hWnd, (HMENU)ID_CMD_KEY,
+        (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), NULL
+    );
+    HWND hCmdSend = CreateWindow(
+        L"BUTTON", L"执行",
+        WS_VISIBLE | WS_CHILD,
+        400, 200, 70, 40,
+        hWnd, (HMENU)ID_CMD_OK,
+        (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), NULL
+    );
+    HWND hLabel_3 = CreateWindow(
+        L"STATIC", L"快捷命令",
+        WS_VISIBLE | WS_CHILD,
+        30, 255, 90, 30,
+        hWnd, NULL,
+        (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), NULL
+    );
 
     //Font
     HFONT hFont = CreateFont(
@@ -105,7 +140,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 {
     PAINTSTRUCT ps;
     HDC hdc;
-    TCHAR greeting[] = _T("by xksyu2021");
+    TCHAR greeting[] = _T("by xksyu2021\nYou must obey Minecraft EULA.");
 
     switch (message)
     {
@@ -124,7 +159,21 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
         {
         case ID_START:
             StartBDS();
+            break;
+        case ID_STOP:
+            StopBDS();
+            break;
+        case ID_STOP_FORCE:
+            if(MessageBox(hWnd,
+                L"强制关闭服务器是非常危险的操作!\n是否仍要继续?",TITLE, 
+                MB_OKCANCEL | MB_APPLMODAL | MB_ICONWARNING) 
+                == 1 )
+            {
+                ForceStopBDS();
+            }
+            break;
         }
+
     }
     break;
 
@@ -136,4 +185,18 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
         break;
     }
     return 0;
+}
+
+LRESULT CALLBACK WeatherProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
+    switch (msg) {
+    case WM_CLOSE:
+        DestroyWindow(hWnd);
+        break;
+    case WM_DESTROY:
+        PostQuitMessage(0);
+        break;
+    default:
+        return DefWindowProc(hWnd, msg, wParam, lParam);
+    }
+    return 0;
 }

+ 3 - 1
Ui for BDS/Ui for BDS.vcxproj

@@ -135,7 +135,9 @@
     <ClInclude Include="Win32.h" />
   </ItemGroup>
   <ItemGroup>
-    <ClCompile Include="func.cpp" />
+    <ClCompile Include="cmdSend.cpp" />
+    <ClCompile Include="errCheck.cpp" />
+    <ClCompile Include="o&amp;c.cpp" />
     <ClCompile Include="MAIN.cpp" />
   </ItemGroup>
   <ItemGroup>

+ 7 - 1
Ui for BDS/Ui for BDS.vcxproj.filters

@@ -32,7 +32,13 @@
     <ClCompile Include="MAIN.cpp">
       <Filter>源文件</Filter>
     </ClCompile>
-    <ClCompile Include="func.cpp">
+    <ClCompile Include="o&amp;c.cpp">
+      <Filter>源文件</Filter>
+    </ClCompile>
+    <ClCompile Include="errCheck.cpp">
+      <Filter>源文件</Filter>
+    </ClCompile>
+    <ClCompile Include="cmdSend.cpp">
       <Filter>源文件</Filter>
     </ClCompile>
   </ItemGroup>

+ 4 - 0
Ui for BDS/Win32.h

@@ -4,6 +4,10 @@
 #include <stdlib.h>
 #include <string.h>
 #include <tchar.h>
+// #include <iostream>
+#include <fstream>
+
+#define TEST MessageBox(hWnd,L"Success!",L"step test",MB_OK)
 
 #ifdef _UNICODE
 #if defined _M_IX86

+ 9 - 0
Ui for BDS/cmdSend.cpp

@@ -0,0 +1,9 @@
+#include "Win32.h"
+#include "ID.h"
+#include "Function.h"
+
+//Send
+bool SendCommand(WCHAR command)
+{
+	return false;
+}

+ 31 - 0
Ui for BDS/errCheck.cpp

@@ -0,0 +1,31 @@
+#include "Win32.h"
+#include "ID.h"
+
+
+int Err(HWND hwnd, LPCTSTR title, LPCTSTR message)
+{
+    if (!hwnd)
+    {
+        MessageBox(NULL, message, title, MB_ICONERROR);
+        return 1;
+    }
+    return 0;
+}
+int Err(ATOM atom, LPCTSTR title, LPCTSTR message)
+{
+    if (!atom)
+    {
+        MessageBox(NULL, message, title, MB_ICONERROR);
+        return 1;
+    }
+    return 0;
+}
+int Err(LPCTSTR title, LPCTSTR message)
+{
+    if (GetLastError() != 0)
+    {
+        MessageBox(NULL, message, title, MB_ICONERROR);
+        return 1;
+    }
+    return 0;
+}

+ 0 - 73
Ui for BDS/func.cpp

@@ -1,73 +0,0 @@
-#include "Win32.h"
-#include "ID.h"
-
-//Error check&output
-int Err(HWND hwnd, LPCTSTR title, LPCTSTR message)
-{
-    if (!hwnd)
-    {
-        MessageBox(NULL,message,title, MB_ICONERROR);
-        return 1;
-    }
-    return 0;
-}
-int Err(ATOM atom, LPCTSTR message, LPCTSTR title)
-{
-    if (!atom)
-    {
-        MessageBox(NULL, message, title, MB_ICONERROR);
-        return 1;
-    }
-    return 0;
-}
-int Err(LPCTSTR title, LPCTSTR message)
-{
-    if (GetLastError() != 0)
-    {
-        MessageBox(NULL, message, title, MB_ICONERROR);
-        return 1;
-    }
-    return 0;
-}
-
-//
-static void AutoClose(DWORD time, LPCWSTR title)
-{
-    Sleep(time*1000); 
-    HWND box = FindWindow(NULL, title);
-    if (box) 
-    {
-        SendMessage(box, WM_CLOSE, 0, 0); 
-    }
-}
-
-//Open&Stop
-HANDLE BDSr_key = NULL;
-HANDLE UIw_key = NULL;
-void StartBDS()
-{
-    SECURITY_ATTRIBUTES sa = { sizeof(sa), NULL, TRUE };
-    if(!CreatePipe(&BDSr_key, &UIw_key, &sa, 0))
-        Err(TITLE, _T("Failed to create pipe"));
-    STARTUPINFO si = { sizeof(si) };
-    si.dwFlags = STARTF_USESTDHANDLES;
-    si.hStdInput = UIw_key;
-    si.wShowWindow = SW_SHOWMINIMIZED;
-    PROCESS_INFORMATION pi;
-
-    if (CreateProcess(
-        L"bedrock_server.exe",
-        NULL, NULL, NULL, TRUE, NULL, NULL, NULL, &si, &pi))
-    {
-        HWND hBox = NULL;
-        MessageBoxW(hWnd,
-            _T("开始启动服务器\n5s后弹窗自动关闭"), L"Info",
-            MB_OK);
-        AutoClose(5, L"Info");
-    }
-    else {
-        Err(TITLE, _T("Failed to send command to BDS!"));
-        CloseHandle(BDSr_key);
-        CloseHandle(UIw_key);
-    }
-}

+ 81 - 0
Ui for BDS/o&c.cpp

@@ -0,0 +1,81 @@
+#include "Win32.h"
+#include "ID.h"
+#include "Function.h"
+
+
+static void AutoClose(DWORD time, LPCWSTR title)
+{
+    Sleep(time*1000); 
+    HWND box = FindWindow(NULL, title);
+    if (box) 
+    {
+        SendMessage(box, WM_CLOSE, 0, 0); 
+    }
+}
+
+//Open&Stop
+PROCESS_INFORMATION pi;
+HWND hBDS;
+
+static void CloseHandle()
+{
+    CloseHandle(BDSr_key);
+    CloseHandle(UIw_key);
+    CloseHandle(UIr_log);
+    CloseHandle(BDSw_log);
+}
+InitH(BDSr_key); InitH(UIw_key); InitH(BDSw_log); InitH(UIr_log);
+void StartBDS()
+{
+    SECURITY_ATTRIBUTES sa = { sizeof(sa), NULL, TRUE };
+    if(!CreatePipe(&BDSr_key, &UIw_key, &sa, 0))
+        Err(TITLE, _T("Failed to create pipe_key"));
+    if (!CreatePipe(&UIr_log, &BDSw_log, &sa, 0))
+        Err(TITLE, _T("Failed to create pipe_log"));
+    STARTUPINFO si = { sizeof(si) };
+    si.dwFlags = STARTF_USESTDHANDLES;
+    si.hStdInput = UIw_key;
+    si.wShowWindow = SW_SHOWMINIMIZED;
+
+    if (CreateProcess(
+        L"bedrock_server.exe",
+        NULL, NULL, NULL, TRUE, NULL, NULL, NULL, &si, &pi))
+    {
+        hBDS = GetConsoleWindow();
+        Err(hBDS, TITLE,
+            _T("Failed to find BDS window"));
+        /*
+        HMENU hmenu = GetSystemMenu(hBDS, false);
+        RemoveMenu(hmenu, SC_CLOSE, MF_BYCOMMAND);
+        LONG style = GetWindowLong(hBDS, GWL_STYLE);
+        style &= ~(WS_MINIMIZEBOX);
+        SetWindowLong(hBDS, GWL_STYLE, style);
+        SetWindowPos(hBDS, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
+        ShowWindow(hBDS, SW_SHOWNORMAL);
+        DestroyMenu(hmenu);
+        */
+        while (bool condition=0)
+        {
+
+        }
+    }
+    else {
+        Err(TITLE, _T("Failed to send command to BDS!"));
+        CloseHandle();
+    }
+}
+
+void StopBDS()
+{
+    SendCommand((WCHAR)"stop\n");
+    CloseHandle();
+}
+
+void ForceStopBDS()
+{
+    TerminateProcess(pi.hProcess,0);
+    CloseHandle();
+    MessageBox(hWnd,
+        L"Òѳ¢ÊÔÇ¿ÐÐÍ£Ö¹·þÎñÆ÷", TITLE,
+        MB_OK);
+}