XKSYU2021 2 місяців тому
батько
коміт
4f1c8c30b7
4 змінених файлів з 62 додано та 23 видалено
  1. 1 3
      Ui for BDS/Function.h
  2. 3 0
      Ui for BDS/ID.h
  3. 49 12
      Ui for BDS/MAIN.cpp
  4. 9 8
      Ui for BDS/childProc.cpp

+ 1 - 3
Ui for BDS/Function.h

@@ -11,6 +11,4 @@ void ForceStopBDS();
 
 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);
+HWND CreateChildWindow(HWND hFather, LPCWCHAR childTitle, int x, int y, WNDPROC procFunc, LPCWCHAR className, HINSTANCE hInstance);

+ 3 - 0
Ui for BDS/ID.h

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

+ 49 - 12
Ui for BDS/MAIN.cpp

@@ -10,7 +10,6 @@ static TCHAR szTitle[] = TITLE;
 HINSTANCE hInst;
 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
 
-
 int WINAPI WinMain(
     _In_ HINSTANCE hInstance,
     _In_opt_ HINSTANCE hPrevInstance,
@@ -35,8 +34,6 @@ int WINAPI WinMain(
     Err(RegisterClassEx(&wcex),
         _T("Call to RegisterClassEx failed!"));
    
-
-
     //Create window
     hInst = hInstance;
     hWnd = CreateWindowEx(
@@ -50,7 +47,6 @@ int WINAPI WinMain(
     Err(hWnd,
         _T("Call to CreateWindow failed!"));
  
-
     //Create controls
     HWND hLabel_1 = CreateWindow(
         L"STATIC", L"基础操作",
@@ -110,12 +106,19 @@ int WINAPI WinMain(
         (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), NULL
     );
     HWND hFCweather = CreateWindow(
-        L"BUTTON", L"切换天气",
+        L"BUTTON", L"天气控制",
         WS_VISIBLE | WS_CHILD,
         30, 300, 110, 40,
         hWnd, (HMENU)ID_FC_Weather,
         (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), NULL
     );
+    HWND hFCtime = CreateWindow(
+        L"BUTTON", L"时间控制",
+        WS_VISIBLE | WS_CHILD,
+        160, 300, 110, 40,
+        hWnd, (HMENU)ID_FC_Time,
+        (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), NULL
+    );
 
 
     //Font
@@ -144,6 +147,11 @@ 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);
+
 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 {
     PAINTSTRUCT ps;
@@ -181,12 +189,25 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
             }
             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);
+            if(!hWeather)
+            {
+                HINSTANCE HI_FC_weather = NULL;
+                hWeather = CreateChildWindow(hWnd,
+                    _T("天气控制"),
+                    700, 700,
+                    WeatherProc, _T("fc_wea"), HI_FC_weather);
+            }
+            break;
+        case ID_FC_Time:
+            if (!hTime)
+            {
+                HINSTANCE HI_FC_time = NULL;
+                hTime = CreateChildWindow(hWnd,
+                    _T("时间控制"),
+                    700, 700,
+                    TimeProc, _T("fc_time"), HI_FC_time);
+            }
+            break;
         }
 
     }
@@ -202,13 +223,29 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
     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);
+        hWeather = NULL;
+        break;
+    default:
+        return DefWindowProc(hWnd, msg, wParam, lParam);
+    }
+    return 0;
+}
+
+LRESULT CALLBACK TimeProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
+    switch (msg) {
+    case WM_CLOSE:
+        DestroyWindow(hWnd);
+        break;
+    case WM_DESTROY:
+        hTime = NULL;
         break;
     default:
         return DefWindowProc(hWnd, msg, wParam, lParam);

+ 9 - 8
Ui for BDS/childProc.cpp

@@ -2,8 +2,9 @@
 #include "ID.h"
 #include "Function.h"
 
-HWND CreateChildWindow(HWND hFather, HWND hChild, LPCWCHAR childTitle ,int x, int y, WNDPROC procFunc, LPCWCHAR className, HINSTANCE hInstanceF)
+HWND CreateChildWindow(HWND hFather, 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;
@@ -17,18 +18,18 @@ HWND CreateChildWindow(HWND hFather, HWND hChild, LPCWCHAR childTitle ,int x, in
     wcexF.lpszMenuName = NULL;
     wcexF.lpszClassName = className;
     wcexF.hIconSm = LoadIcon(wcexF.hInstance, IDI_APPLICATION);
-    Err(RegisterClassEx(&wcexF),
-        _T("Call to RegisterClassEx failed!"));
+    RegisterClassEx(&wcexF);
+ 
 
     hChild = CreateWindowEx(
-        WS_EX_OVERLAPPEDWINDOW,
+        NULL,
         className, childTitle,
-        WS_CHILD | WS_VISIBLE | WS_BORDER,
-        CW_USEDEFAULT, CW_USEDEFAULT,
-        x, y, NULL, NULL,
+        WS_POPUP | WS_VISIBLE |  WS_CAPTION | WS_SYSMENU,
+        700, 300,
+        x, y, hFather, NULL,
         hInstanceF, NULL
     );
     Err(hChild,
-        _T("CreateChildWindow failed!"));
+        _T("Create ChildWindow failed!"));
     return hChild;
 }