Ver código fonte

update 8/14 20

XKSYU2021 2 meses atrás
pai
commit
88f8bff982

+ 6 - 0
Ui for BDS/Function.h

@@ -5,6 +5,8 @@ int Err(HWND hwnd, LPCTSTR message);
 int Err(ATOM atom, LPCTSTR message);
 int Err(LPCTSTR message);
 void ForceErrCheck(LPCTSTR title);
+int Err(std::ifstream* file, LPCTSTR message);
+int Err(std::fstream* file, LPCTSTR message);
 
 void StartBDS();
 void StopBDS();
@@ -12,4 +14,8 @@ void ForceStopBDS();
 
 bool SendCommand(LPCSTR command);
 
+void ClearLog();
+void Log(HWND hwnd);
+
 HWND CreateChildWindow(HWND hFather, LPCWCHAR childTitle, int x, int y, WNDPROC procFunc, LPCWCHAR className, HINSTANCE hInstance);
+HWND CreateNewWindow(LPCWCHAR childTitle, int x, int y, WNDPROC procFunc, LPCWCHAR className, HINSTANCE hInstanceF);

+ 12 - 1
Ui for BDS/ID.h

@@ -18,4 +18,15 @@ extern HWND hWnd;
 #define ID_CMD_OK 20002
 #define ID_CMD_CLEAR 20003
 #define ID_FC_Weather 30100
-#define ID_FC_Time 30200
+#define ID_FC_Wea_SET_1 30101
+#define ID_FC_Wea_SET_2 30102
+#define ID_FC_Wea_SET_3 30103
+#define ID_FC_Wea_ADV 30110
+#define ID_FC_Wea_OK 30120
+#define ID_FC_Time 30200
+#define ID_FC_Time_SET 30201
+#define ID_FC_Time_ADV 30202
+#define ID_FC_Time_MAN 30203
+#define ID_FC_Time_OK 30210
+#define ID_LOG 40001
+#define ID_LOG_OUTPUT 40101

+ 126 - 42
Ui for BDS/MAIN.cpp

@@ -4,6 +4,20 @@
 
 HWND hWnd = NULL;
 
+static HFONT Font()
+{
+    HFONT hFont = CreateFont(
+        -40,
+        0, 0, 0,
+        FW_NORMAL, FALSE, FALSE, FALSE,
+        DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
+        ANTIALIASED_QUALITY,
+        FF_ROMAN,
+        L"Arial"
+    );
+    return hFont;
+}
+
 //Basic info
 static TCHAR szWindowClass[] = _T("ufb"); 
 static TCHAR szTitle[] = TITLE;
@@ -131,6 +145,16 @@ int WINAPI WinMain(
     );
 
 
+    HWND hOpenLog = CreateWindow(
+        L"BUTTON", L"打开日志",
+        WS_VISIBLE | WS_CHILD,
+        302, 500, 110, 40,
+        hWnd, (HMENU)ID_LOG,
+        (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), NULL
+    );
+
+
+
     //Font
     HFONT hFont = CreateFont(
         -40,
@@ -159,8 +183,10 @@ int WINAPI WinMain(
 //Behavior of controls
 InitHWND(hTime); 
 InitHWND(hWeather);
-LRESULT CALLBACK TimeProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); 
-LRESULT CALLBACK WeatherProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
+InitHWND(hLog);
+LRESULT CALLBACK TimeProc(HWND hWnd1, UINT msg, WPARAM wParam, LPARAM lParam); 
+LRESULT CALLBACK WeatherProc(HWND hWnd1, UINT msg, WPARAM wParam, LPARAM lParam);
+LRESULT CALLBACK LogProc(HWND hWnd1, UINT msg, WPARAM wParam, LPARAM lParam);
 
 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 {
@@ -170,6 +196,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 
     switch (message)
     {
+    case WM_CREATE:
+        ClearLog();
+
     case WM_PAINT:
         hdc = BeginPaint(hWnd, &ps);
         TextOut(hdc,
@@ -190,10 +219,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
             StopBDS();
             break;
         case ID_STOP_FORCE:
-            if(MessageBox(hWnd,
-                L"强制关闭服务器是非常危险的操作!\n是否仍要继续?",TITLE, 
-                MB_OKCANCEL | MB_APPLMODAL | MB_ICONWARNING) 
-                == 1 )
+            if (MessageBox(hWnd,
+                L"强制关闭服务器是非常危险的操作!\n是否仍要继续?", TITLE,
+                MB_OKCANCEL | MB_APPLMODAL | MB_ICONWARNING)
+                == 1)
             {
                 ForceStopBDS();
             }
@@ -214,12 +243,12 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
             SetWindowText(GetDlgItem(hWnd, ID_CMD_KEY), _T(" "));
             break;
         case ID_FC_Weather:
-            if(!hWeather)
+            if (!hWeather)
             {
                 HINSTANCE HI_FC_weather = NULL;
                 hWeather = CreateChildWindow(hWnd,
                     _T("天气控制"),
-                    700, 700,
+                    400, 370,
                     WeatherProc, _T("fc_wea"), HI_FC_weather);
             }
             break;
@@ -229,16 +258,25 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
                 HINSTANCE HI_FC_time = NULL;
                 hTime = CreateChildWindow(hWnd,
                     _T("时间控制"),
-                    700, 700,
+                    600, 440,
                     TimeProc, _T("fc_time"), HI_FC_time);
             }
             break;
+        case ID_LOG:
+            if (!hLog)
+            {
+                HINSTANCE HI_Log = NULL;
+                hLog = CreateNewWindow(
+                    _T("日志"),
+                    1000, 620,
+                    LogProc, _T("log"), HI_Log);
+            }
+            break;
         }
-
+        break;
     }
-    break;
-
     case WM_DESTROY:
+        StopBDS();
         PostQuitMessage(0);
         break;
     default:
@@ -249,38 +287,38 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 }
 
 
-
-LRESULT CALLBACK WeatherProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
+LRESULT CALLBACK WeatherProc(HWND hWnd1, UINT msg, WPARAM wParam, LPARAM lParam) {
     switch (msg) {
     case WM_CREATE:
     {
+        HFONT hFont1 = Font();
         HWND hWeaSet = CreateWindow(
             L"BUTTON", L"基础选项",
             WS_VISIBLE | WS_CHILD | BS_GROUPBOX,
             20, 20, 330, 100,
-            hWeather, NULL,
-            (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), NULL
+            hWnd1, NULL,
+            (HINSTANCE)GetWindowLongPtr(hWnd1, GWLP_HINSTANCE), NULL
         );
         HWND hWeaSet_1 = CreateWindow(
             L"BUTTON", L"晴天",
             WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON | WS_GROUP,
             40, 55, 80, 40,
-            hWeather, (HMENU)ID_FC_Wea_SET_1,
-            (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), NULL
+            hWnd1, (HMENU)ID_FC_Wea_SET_1,
+            (HINSTANCE)GetWindowLongPtr(hWnd1, GWLP_HINSTANCE), NULL
         );
         HWND hWeaSet_2 = CreateWindow(
             L"BUTTON", L"雨天",
             WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON,
            140, 55, 80, 40,
-            hWeather, (HMENU)ID_FC_Wea_SET_2,
-            (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), NULL
+            hWnd1, (HMENU)ID_FC_Wea_SET_2,
+            (HINSTANCE)GetWindowLongPtr(hWnd1, GWLP_HINSTANCE), NULL
         );
         HWND hWeaSet_3 = CreateWindow(
             L"BUTTON", L"雷暴",
             WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON,
             240, 55, 80, 40,
-            hWeather, (HMENU)ID_FC_Wea_SET_3,
-            (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), NULL
+            hWnd1, (HMENU)ID_FC_Wea_SET_3,
+            (HINSTANCE)GetWindowLongPtr(hWnd1, GWLP_HINSTANCE), NULL
         );
 
 
@@ -288,16 +326,16 @@ LRESULT CALLBACK WeatherProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
             L"STATIC", L"高级选项",
             WS_VISIBLE | WS_CHILD,
             30, 150, 80, 30,
-            hWeather, NULL,
-            (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), NULL
+            hWnd1, NULL,
+            (HINSTANCE)GetWindowLongPtr(hWnd1, GWLP_HINSTANCE), NULL
         );
 
         HWND hWeaAdv = CreateWindow(
             L"BUTTON", L"天气更替",
             WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX ,
             30, 190, 110, 40,
-            hWeather, (HMENU)ID_FC_Wea_ADV,
-            (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), NULL
+            hWnd1, (HMENU)ID_FC_Wea_ADV,
+            (HINSTANCE)GetWindowLongPtr(hWnd1, GWLP_HINSTANCE), NULL
         );
 
 
@@ -305,8 +343,8 @@ LRESULT CALLBACK WeatherProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
             L"BUTTON", L"提交",
             WS_VISIBLE | WS_CHILD,
             250, 250, 110, 40,
-            hWeather, (HMENU)ID_FC_Wea_OK,
-            (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), NULL
+            hWnd1, (HMENU)ID_FC_Wea_OK,
+            (HINSTANCE)GetWindowLongPtr(hWnd1, GWLP_HINSTANCE), NULL
         );
 
         SendMessage(hWeaSet_1, BM_SETCHECK, BST_CHECKED, 0);
@@ -315,40 +353,86 @@ LRESULT CALLBACK WeatherProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
         break;
 
     case WM_COMMAND:
-        if (IsDlgButtonChecked(hWeather, ID_FC_Wea_ADV) == BST_CHECKED)
-            SendCommand(C(""));
+    {
+        WORD wmId = LOWORD(wParam);
+        switch (wmId)
+        {
+        case ID_FC_Wea_OK:
+            if (IsDlgButtonChecked(hWnd1, ID_FC_Wea_ADV) == BST_CHECKED)
+                SendCommand(C("gamerule doWeatherCycle true"));
+            else SendCommand(C("gamerule doWeatherCycle false"));
 
-        if (IsDlgButtonChecked(hWeather, ID_FC_Wea_SET_1) == BST_CHECKED)
-            SendCommand(C(""));
-        else if (IsDlgButtonChecked(hWeather, ID_FC_Wea_SET_2) == BST_CHECKED)
-            SendCommand(C(""));
-        else SendCommand(C(""));
+            if (IsDlgButtonChecked(hWnd1, ID_FC_Wea_SET_1) == BST_CHECKED)
+                SendCommand(C("weather clear"));
+            else if (IsDlgButtonChecked(hWnd1, ID_FC_Wea_SET_2) == BST_CHECKED)
+                SendCommand(C("weather rain"));
+            else SendCommand(C("weather thunder"));
 
-        MessageBox(hWnd, L"已发送", L"天气控制", MB_OK);
-        DestroyWindow(hWnd);
+            DestroyWindow(hWnd1);
+
+            break;
+
+        default:
+            break;
+        }
+        break;
+    }
+        
 
     case WM_CLOSE:
-        DestroyWindow(hWnd);
+        DestroyWindow(hWnd1);
         break;
     case WM_DESTROY:
         hWeather = NULL;
         break;
     default:
-        return DefWindowProc(hWnd, msg, wParam, lParam);
+        return DefWindowProc(hWnd1, msg, wParam, lParam);
     }
     return 0;
 }
 
-LRESULT CALLBACK TimeProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
+LRESULT CALLBACK TimeProc(HWND hWnd1, UINT msg, WPARAM wParam, LPARAM lParam) {
     switch (msg) {
+    case WM_CREATE:
+    {
+        HFONT hFont1 = Font();
+        break;
+    }
     case WM_CLOSE:
-        DestroyWindow(hWnd);
+        DestroyWindow(hWnd1);
         break;
     case WM_DESTROY:
         hTime = NULL;
         break;
     default:
-        return DefWindowProc(hWnd, msg, wParam, lParam);
+        return DefWindowProc(hWnd1, msg, wParam, lParam);
+    }
+    return 0;
+}
+
+LRESULT CALLBACK LogProc(HWND hWnd1, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+    switch (msg) {
+    case WM_CREATE:
+    {
+        HFONT hFont1 = Font();
+        HWND hLog = CreateWindow(
+            L"EDIT", L"Null",
+            WS_VISIBLE | WS_CHILD | WS_BORDER | WS_VSCROLL | ES_MULTILINE | ES_READONLY | ES_AUTOVSCROLL,
+            30, 30, 910, 510,
+            hWnd1, (HMENU)ID_LOG_OUTPUT,
+            (HINSTANCE)GetWindowLongPtr(hWnd1, GWLP_HINSTANCE), NULL
+        );
+        break;
+    }
+    case WM_CLOSE:
+        DestroyWindow(hWnd1);
+        break;
+    case WM_DESTROY:
+        hLog = NULL;
+        break;
+    default:
+        return DefWindowProc(hWnd1, msg, wParam, lParam);
     }
     return 0;
 }

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

@@ -138,6 +138,7 @@
     <ClCompile Include="childProc.cpp" />
     <ClCompile Include="cmdSend.cpp" />
     <ClCompile Include="errCheck.cpp" />
+    <ClCompile Include="log.cpp" />
     <ClCompile Include="o&amp;c.cpp" />
     <ClCompile Include="MAIN.cpp" />
   </ItemGroup>

+ 3 - 0
Ui for BDS/Ui for BDS.vcxproj.filters

@@ -44,6 +44,9 @@
     <ClCompile Include="childProc.cpp">
       <Filter>源文件</Filter>
     </ClCompile>
+    <ClCompile Include="log.cpp">
+      <Filter>源文件</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="Ui for BDS.rc">

+ 1 - 1
Ui for BDS/Win32.h

@@ -4,7 +4,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <tchar.h>
-// #include <iostream>
+#include <iostream>
 #include <fstream>
 
 #define TEST MessageBox(hWnd,L"Success!",L"step test",MB_OK)

+ 32 - 0
Ui for BDS/childProc.cpp

@@ -32,4 +32,36 @@ HWND CreateChildWindow(HWND hFather, LPCWCHAR childTitle ,int x, int y, WNDPROC
     Err(hChild,
         _T("Create ChildWindow failed!"));
     return hChild;
+}
+
+HWND CreateNewWindow(LPCWCHAR childTitle, int x, int y, WNDPROC procFunc, LPCWCHAR className, HINSTANCE hInstanceF)
+{
+    HWND hChild = NULL;
+    static WNDCLASSEX wcexF;
+    wcexF.cbSize = sizeof(WNDCLASSEX);
+    wcexF.style = CS_HREDRAW | CS_VREDRAW;
+    wcexF.lpfnWndProc = procFunc;
+    wcexF.cbClsExtra = 0;
+    wcexF.cbWndExtra = 0;
+    wcexF.hInstance = hInstanceF;
+    wcexF.hIcon = LoadIcon(wcexF.hInstance, IDI_APPLICATION);
+    wcexF.hCursor = LoadCursor(NULL, IDC_ARROW);
+    wcexF.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
+    wcexF.lpszMenuName = NULL;
+    wcexF.lpszClassName = className;
+    wcexF.hIconSm = LoadIcon(wcexF.hInstance, IDI_APPLICATION);
+    RegisterClassEx(&wcexF);
+
+
+    hChild = CreateWindowEx(
+        NULL,
+        className, childTitle,
+        WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU,
+        700, 300,
+        x, y, NULL , NULL,
+        hInstanceF, NULL
+    );
+    Err(hChild,
+        _T("Create ChildWindow failed!"));
+    return hChild;
 }

+ 19 - 2
Ui for BDS/errCheck.cpp

@@ -16,7 +16,6 @@ int Err(HWND hwnd, LPCTSTR message)
 {
     if (!hwnd)
     {
-        DWORD error = GetLastError();
         MessageBox(NULL, message, GetError(), MB_ICONERROR);
         return 1;
     }
@@ -26,7 +25,6 @@ int Err(ATOM atom, LPCTSTR message)
 {
     if (!atom)
     {
-        DWORD error = GetLastError();
         MessageBox(NULL, message, GetError(), MB_ICONERROR);
         return 1;
     }
@@ -44,4 +42,23 @@ int Err(LPCTSTR message)
 void ForceErrCheck(LPCTSTR title)
 {
        MessageBox(NULL, GetError(), title, MB_ICONWARNING);
+}
+
+int Err(std::ifstream* file, LPCTSTR message)
+{
+    if (!file)
+    {
+        MessageBox(NULL, message, GetError(), MB_ICONERROR);
+        return 1;
+    }
+    return 0;
+}
+int Err(std::fstream* file, LPCTSTR message)
+{
+    if (!file)
+    {
+        MessageBox(NULL, message, GetError(), MB_ICONERROR);
+        return 1;
+    }
+    return 0;
 }

+ 37 - 0
Ui for BDS/log.cpp

@@ -0,0 +1,37 @@
+#include "Win32.h"
+#include "ID.h"
+#include "Function.h"
+
+static void Reflesh(HWND hwnd)
+{
+    std::ifstream read;
+    read.open("log.txt", std::ios::in);
+    Err(&read, _T("Failed to open log.txt"));
+    std::string text(
+        (std::istreambuf_iterator<char>(read)),
+        std::istreambuf_iterator<char>()
+    );
+    read.close();
+    int len = MultiByteToWideChar(CP_ACP, 0, text.c_str(), -1, NULL, 0);
+    std::wstring wtext(len, 0);
+    MultiByteToWideChar(CP_ACP, 0, text.c_str(), -1, &wtext[0], len);
+    SetWindowText(hwnd, wtext.c_str());
+}
+
+static void GetLog()
+{
+    
+}
+
+void ClearLog()
+{
+    std::ofstream output;
+    output.open("log.txt", std::ios::out);
+    output.close();
+}
+
+void Log(HWND hwnd)
+{
+    GetLog();
+    Reflesh(hwnd);
+}

+ 0 - 0
Ui for BDS/log.txt


+ 14 - 7
Ui for BDS/o&c.cpp

@@ -41,6 +41,7 @@ void StartBDS()
     STARTUPINFO si = { sizeof(si) };
     si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
     si.hStdInput = BDSr_key;
+    si.hStdOutput = BDSw_log;
     si.wShowWindow = SW_SHOWMINIMIZED;
 
     if (CreateProcess(
@@ -57,15 +58,21 @@ void StartBDS()
 
 void StopBDS()
 {
-    SendCommand(C("stop"));
-    CloseHandleA();
+    if (pi.hProcess)
+    {
+        SendCommand(C("stop"));
+        CloseHandleA();
+    }
 }
 
 void ForceStopBDS()
 {
-    TerminateProcess(pi.hProcess,0);
-    CloseHandleA();
-    MessageBox(hWnd,
-        _T("已尝试强行停止服务器"), TITLE,
-        MB_OK);
+    if(pi.hProcess)
+    {
+        TerminateProcess(pi.hProcess, 0);
+        CloseHandleA();
+        MessageBox(hWnd,
+            _T("已尝试强行停止服务器"), TITLE,
+            MB_OK);
+    }
 }

+ 0 - 0
Ui for BDS/result.txt