XKSYU2021 2 mēneši atpakaļ
vecāks
revīzija
b36577938f

+ 7 - 3
Ui for BDS/Function.h

@@ -1,12 +1,16 @@
 #pragma once
 #include "Win32.h"
 
-int Err(HWND hwnd, LPCTSTR message, LPCTSTR title);
-int Err(ATOM atom, LPCTSTR message, LPCTSTR title);
+int Err(HWND hwnd, LPCTSTR message);
+int Err(ATOM atom, LPCTSTR message);
 int Err(LPCTSTR title, LPCTSTR message);
 
 void StartBDS();
 void StopBDS();
 void ForceStopBDS();
 
-bool SendCommand(WCHAR command);
+bool SendCommand(LPWSTR command);
+
+HWND CreateChildWindow(HWND hFather, HWND hChild, LPCWCHAR childTitle, int x, int y, WNDPROC procFunc, LPCWCHAR className, HINSTANCE hInstance);
+
+LRESULT CALLBACK WeatherProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

+ 1 - 0
Ui for BDS/ID.h

@@ -1,6 +1,7 @@
 #pragma once
 
 #define InitH(x) HANDLE x = NULL
+#define CWORD(x) (LPWSTR)_T(x "\n")
 extern HANDLE UIw_key, BDSr_key, UIr_log, BDSw_log;
 extern HWND hWnd;
 

+ 17 - 2
Ui for BDS/MAIN.cpp

@@ -32,7 +32,7 @@ int WINAPI WinMain(
     wcex.lpszMenuName = NULL;
     wcex.lpszClassName = szWindowClass;
     wcex.hIconSm = LoadIcon(wcex.hInstance, IDI_APPLICATION);
-    Err(RegisterClassEx(&wcex), szTitle, 
+    Err(RegisterClassEx(&wcex),
         _T("Call to RegisterClassEx failed!"));
    
 
@@ -47,7 +47,7 @@ int WINAPI WinMain(
         530, 560, NULL, NULL,
         hInstance, NULL
     );
-    Err(hWnd, szTitle, 
+    Err(hWnd,
         _T("Call to CreateWindow failed!"));
  
 
@@ -109,6 +109,14 @@ int WINAPI WinMain(
         hWnd, NULL,
         (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), NULL
     );
+    HWND hFCweather = CreateWindow(
+        L"BUTTON", L"切换天气",
+        WS_VISIBLE | WS_CHILD,
+        30, 300, 110, 40,
+        hWnd, (HMENU)ID_FC_Weather,
+        (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), NULL
+    );
+
 
     //Font
     HFONT hFont = CreateFont(
@@ -172,6 +180,13 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
                 ForceStopBDS();
             }
             break;
+        case ID_FC_Weather:
+            HINSTANCE HI_FC_weather = NULL;
+            HWND hWeather = NULL;
+            hWeather = CreateChildWindow(hWnd, hWeather,
+                _T("天气控制"),
+                100, 100,
+                WeatherProc, _T("fc_wea"), HI_FC_weather);
         }
 
     }

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

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

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

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

+ 34 - 0
Ui for BDS/childProc.cpp

@@ -0,0 +1,34 @@
+#include "Win32.h"
+#include "ID.h"
+#include "Function.h"
+
+HWND CreateChildWindow(HWND hFather, HWND hChild, LPCWCHAR childTitle ,int x, int y, WNDPROC procFunc, LPCWCHAR className, HINSTANCE hInstanceF)
+{
+    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);
+    Err(RegisterClassEx(&wcexF),
+        _T("Call to RegisterClassEx failed!"));
+
+    hChild = CreateWindowEx(
+        WS_EX_OVERLAPPEDWINDOW,
+        className, childTitle,
+        WS_CHILD | WS_VISIBLE | WS_BORDER,
+        CW_USEDEFAULT, CW_USEDEFAULT,
+        x, y, NULL, NULL,
+        hInstanceF, NULL
+    );
+    Err(hChild,
+        _T("CreateChildWindow failed!"));
+    return hChild;
+}

+ 6 - 4
Ui for BDS/cmdSend.cpp

@@ -3,10 +3,12 @@
 #include "Function.h"
 
 //Send
-bool SendCommand(const char* command)
+bool SendCommand(LPWSTR command)
 {
-	DWORD written;
-	if (WriteFile(UIw_key, command, strlen(command), &written, NULL) != 0)
+	if (WriteFile(UIw_key, command, sizeof(command), NULL, NULL) != 0)
 		return true;
-	else return false;
+	else {
+		Err(TITLE, _T("Failed to send command!"));
+		return false;
+	}
 }

+ 17 - 10
Ui for BDS/errCheck.cpp

@@ -2,20 +2,32 @@
 #include "ID.h"
 
 
-int Err(HWND hwnd, LPCTSTR title, LPCTSTR message)
+static LPWSTR GetError()
+{
+    DWORD error = GetLastError();
+    LPWSTR errorMsg = NULL;
+    FormatMessage(
+        FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
+        NULL, error, 0, (LPWSTR)&errorMsg, 256, NULL);
+    return errorMsg;
+}
+
+int Err(HWND hwnd, LPCTSTR message)
 {
     if (!hwnd)
     {
-        MessageBox(NULL, message, title, MB_ICONERROR);
+        DWORD error = GetLastError();
+        MessageBox(NULL, message, GetError(), MB_ICONERROR);
         return 1;
     }
     return 0;
 }
-int Err(ATOM atom, LPCTSTR title, LPCTSTR message)
+int Err(ATOM atom, LPCTSTR message)
 {
     if (!atom)
     {
-        MessageBox(NULL, message, title, MB_ICONERROR);
+        DWORD error = GetLastError();
+        MessageBox(NULL, message, GetError(), MB_ICONERROR);
         return 1;
     }
     return 0;
@@ -24,12 +36,7 @@ int Err(LPCTSTR title, LPCTSTR message)
 {
     if (GetLastError() != 0)
     {
-        DWORD error = GetLastError();
-        LPWSTR errorMsg = (LPWSTR)"unknown";
-        FormatMessage(
-            FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 
-            NULL, error, 0, errorMsg, 256, NULL);
-        MessageBox(NULL, message, errorMsg, MB_ICONERROR);
+        MessageBox(NULL, message, GetError(), MB_ICONERROR);
         return 1;
     }
     return 0;

+ 5 - 5
Ui for BDS/o&c.cpp

@@ -41,8 +41,8 @@ void StartBDS()
         L"bedrock_server.exe",
         NULL, NULL, NULL, TRUE, NULL, NULL, NULL, &si, &pi))
     {
-
-        }
+        
+    }
     else {
         Err(TITLE, _T("Failed to send command to BDS!"));
         CloseHandle();
@@ -51,8 +51,8 @@ void StartBDS()
 
 void StopBDS()
 {
-    SendCommand((WCHAR)"stop\n");
-    CloseHandle();
+    SendCommand(CWORD("stop"));
+    //CloseHandle();
 }
 
 void ForceStopBDS()
@@ -60,6 +60,6 @@ void ForceStopBDS()
     TerminateProcess(pi.hProcess,0);
     CloseHandle();
     MessageBox(hWnd,
-        L"脪脩鲁垄脢脭脟驴脨脨脥拢脰鹿路镁脦帽脝梅", TITLE,
+        _T("已尝试强行停止服务器"), TITLE,
         MB_OK);
 }