XKSYU2021 2 hónapja
szülő
commit
e5e09710c1
6 módosított fájl, 62 hozzáadás és 37 törlés
  1. 2 2
      Ui for BDS/Function.h
  2. 2 2
      Ui for BDS/ID.h
  3. 32 23
      Ui for BDS/MAIN.cpp
  4. 5 5
      Ui for BDS/childProc.cpp
  5. 1 1
      Ui for BDS/errCheck.cpp
  6. 20 4
      Ui for BDS/log.cpp

+ 2 - 2
Ui for BDS/Function.h

@@ -6,7 +6,7 @@ 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);
+int Err(std::ofstream* file, LPCTSTR message);
 
 void StartBDS();
 void StopBDS();
@@ -18,4 +18,4 @@ 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);
+HWND CreateLogWindow(LPCWCHAR childTitle, int x, int y, WNDPROC procFunc, LPCWCHAR className, HINSTANCE hInstanceF);

+ 2 - 2
Ui for BDS/ID.h

@@ -28,5 +28,5 @@ extern HWND hWnd;
 #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
+#define ID_LOG 40101
+#define ID_LOG_CLEAR 40102

+ 32 - 23
Ui for BDS/MAIN.cpp

@@ -144,17 +144,6 @@ int WINAPI WinMain(
         (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), NULL
     );
 
-
-    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,
@@ -197,7 +186,16 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
     switch (message)
     {
     case WM_CREATE:
+    {
         ClearLog();
+        HINSTANCE HI_Log = NULL;
+        hLog = CreateLogWindow(
+            _T("日志"),
+            1000, 690,
+            LogProc, _T("log"), HI_Log);
+        Log(GetDlgItem(hLog, ID_LOG));
+        break;
+    }
 
     case WM_PAINT:
         hdc = BeginPaint(hWnd, &ps);
@@ -262,16 +260,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
                     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;
     }
@@ -415,20 +403,41 @@ LRESULT CALLBACK LogProc(HWND hWnd1, UINT msg, WPARAM wParam, LPARAM lParam)
     switch (msg) {
     case WM_CREATE:
     {
+        SetTimer(hWnd1, 1, 100, NULL);
         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,
+            hWnd1, (HMENU)ID_LOG,
+            (HINSTANCE)GetWindowLongPtr(hWnd1, GWLP_HINSTANCE), NULL
+        );
+        HWND hLogClear = CreateWindow(
+            L"BUTTON", L"清屏",
+            WS_VISIBLE | WS_CHILD,
+            790, 570, 110, 40,
+            hWnd1, (HMENU)ID_LOG_CLEAR,
             (HINSTANCE)GetWindowLongPtr(hWnd1, GWLP_HINSTANCE), NULL
         );
         break;
     }
+    case WM_COMMAND:
+    {
+        WORD wmId = LOWORD(wParam);
+        switch (wmId)
+        {
+        case ID_LOG_CLEAR:
+            SetWindowText(GetDlgItem(hWnd1, ID_LOG), _T(" "));
+            break;
+        }
+    }
+    case WM_TIMER:
+        Log(GetDlgItem(hLog, ID_LOG));
+        break;
     case WM_CLOSE:
-        DestroyWindow(hWnd1);
         break;
     case WM_DESTROY:
+        KillTimer(hWnd1, 1);
         hLog = NULL;
         break;
     default:

+ 5 - 5
Ui for BDS/childProc.cpp

@@ -24,7 +24,7 @@ HWND CreateChildWindow(HWND hFather, LPCWCHAR childTitle ,int x, int y, WNDPROC
     hChild = CreateWindowEx(
         NULL,
         className, childTitle,
-        WS_POPUP | WS_VISIBLE |  WS_CAPTION | WS_SYSMENU,
+        WS_POPUP | WS_VISIBLE |  WS_CAPTION | WS_SYSMENU ,
         700, 300,
         x, y, hFather, NULL,
         hInstanceF, NULL
@@ -34,12 +34,12 @@ HWND CreateChildWindow(HWND hFather, LPCWCHAR childTitle ,int x, int y, WNDPROC
     return hChild;
 }
 
-HWND CreateNewWindow(LPCWCHAR childTitle, int x, int y, WNDPROC procFunc, LPCWCHAR className, HINSTANCE hInstanceF)
+HWND CreateLogWindow(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.style = CS_HREDRAW | CS_VREDRAW | CS_NOCLOSE;
     wcexF.lpfnWndProc = procFunc;
     wcexF.cbClsExtra = 0;
     wcexF.cbWndExtra = 0;
@@ -56,8 +56,8 @@ HWND CreateNewWindow(LPCWCHAR childTitle, int x, int y, WNDPROC procFunc, LPCWCH
     hChild = CreateWindowEx(
         NULL,
         className, childTitle,
-        WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU,
-        700, 300,
+        WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
+        1000, 400,
         x, y, NULL , NULL,
         hInstanceF, NULL
     );

+ 1 - 1
Ui for BDS/errCheck.cpp

@@ -53,7 +53,7 @@ int Err(std::ifstream* file, LPCTSTR message)
     }
     return 0;
 }
-int Err(std::fstream* file, LPCTSTR message)
+int Err(std::ofstream* file, LPCTSTR message)
 {
     if (!file)
     {

+ 20 - 4
Ui for BDS/log.cpp

@@ -2,8 +2,12 @@
 #include "ID.h"
 #include "Function.h"
 
+static  DWORD size = 0;
+static bool statu = TRUE;
+
 static void Reflesh(HWND hwnd)
 {
+    if (!statu) return;
     std::ifstream read;
     read.open("log.txt", std::ios::in);
     Err(&read, _T("Failed to open log.txt"));
@@ -20,18 +24,30 @@ static void Reflesh(HWND hwnd)
 
 static void GetLog()
 {
-    
+    char log[4096] = { 0 };
+    statu = ReadFile(UIr_log, log, sizeof(log), &size, NULL);
+    if (!statu || size < 4) 
+    {
+        statu = FALSE;
+        return;
+    }
+    std::ofstream write("log.txt", std::ios::app);
+    Err(&write, _T("Failed to open log.txt"));
+    write << log;
+    write.close();
 }
 
 void ClearLog()
 {
-    std::ofstream output;
-    output.open("log.txt", std::ios::out);
-    output.close();
+    std::ofstream clear;
+    Err(&clear, _T("Failed to open log.txt"));
+    clear.open("log.txt", std::ios::out);
+    clear.close();
 }
 
 void Log(HWND hwnd)
 {
     GetLog();
     Reflesh(hwnd);
+    size = 0;
 }