From 3fbbb0fbdc04bab96e0af73ada06ee05b5191280 Mon Sep 17 00:00:00 2001
From: taynpg <taynpg@163.com>
Date: Thu, 26 Dec 2024 10:13:03 +0800
Subject: [PATCH] =?UTF-8?q?add=EF=BC=9A=E4=B8=80=E4=B8=AA=E5=9F=BA?=
 =?UTF-8?q?=E6=9C=AC=E7=9A=84=E6=97=A0=E8=BE=B9=E6=A1=86=E7=AA=97=E5=8F=A3?=
 =?UTF-8?q?=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 CMakeLists.txt  |  2 +-
 MainFrame.cpp   | 36 ++++++++++++++++++++++++++++++++++--
 MainFrame.h     |  9 +++++++++
 README.md       |  3 +++
 monitor.cpp     | 14 ++++++++++++++
 monitor.h       | 19 +++++++++++++++++++
 win_monitor.cpp | 23 +++++++++++++++++++++++
 win_monitor.h   | 14 ++++++++++++++
 8 files changed, 117 insertions(+), 3 deletions(-)
 create mode 100644 README.md
 create mode 100644 monitor.cpp
 create mode 100644 monitor.h
 create mode 100644 win_monitor.cpp
 create mode 100644 win_monitor.h

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8655c44..0970bf1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -19,6 +19,6 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE}
 
 add_subdirectory(ofen)
 find_package(wxWidgets CONFIG REQUIRED)
-add_executable(BMonitor main.cpp MainFrame.h MainFrame.cpp)
+add_executable(BMonitor main.cpp MainFrame.h MainFrame.cpp monitor.h monitor.cpp win_monitor.h win_monitor.cpp)
 target_link_libraries(BMonitor PRIVATE wx::core wx::base Ofen)
 set_target_properties(BMonitor PROPERTIES WIN32_EXECUTABLE TRUE)
\ No newline at end of file
diff --git a/MainFrame.cpp b/MainFrame.cpp
index 0a3fe4a..89ad104 100644
--- a/MainFrame.cpp
+++ b/MainFrame.cpp
@@ -1,5 +1,37 @@
 #include "MainFrame.h"
 
-CMainFrame::CMainFrame(const wxString& title) : wxFrame(NULL, wxID_ANY, title)
+CMainFrame::CMainFrame(const wxString& title)
+    : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(300, 200),
+              wxFRAME_NO_TASKBAR | wxFRAME_SHAPED)
 {
-}
\ No newline at end of file
+    this->Bind(wxEVT_LEFT_DOWN, &CMainFrame::mouse_down, this);
+    this->Bind(wxEVT_MOTION, &CMainFrame::mouse_motion, this);
+    this->Bind(wxEVT_LEFT_UP, &CMainFrame::mouse_leftup, this);
+}
+
+void CMainFrame::mouse_down(wxMouseEvent& event)
+{
+    drag_ = true;
+    ps_ = event.GetPosition();
+    CaptureMouse();
+}
+
+void CMainFrame::mouse_motion(wxMouseEvent& event)
+{
+    if (drag_ && event.Dragging()) {
+        wxPoint mousePos = event.GetPosition();
+        wxPoint screenPos = ClientToScreen(mousePos);
+        wxPoint framePos = screenPos - ps_;
+        Move(framePos);
+    }
+}
+
+void CMainFrame::mouse_leftup(wxMouseEvent& event)
+{
+    if (drag_) {
+        drag_ = false;
+        if (HasCapture()) {
+            ReleaseMouse();
+        }
+    }
+}
diff --git a/MainFrame.h b/MainFrame.h
index 24463d5..131be3e 100644
--- a/MainFrame.h
+++ b/MainFrame.h
@@ -5,4 +5,13 @@ class CMainFrame : public wxFrame
 {
 public:
     explicit CMainFrame(const wxString& title);
+
+private:
+    void mouse_down(wxMouseEvent& event);
+    void mouse_motion(wxMouseEvent& event);
+    void mouse_leftup(wxMouseEvent& event);
+
+private:
+    wxPoint ps_;
+    bool drag_{false};
 };
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..1a7fb93
--- /dev/null
+++ b/README.md
@@ -0,0 +1,3 @@
+# BMonitor
+
+基本的`CPU`、`内存使用率`等监控。
\ No newline at end of file
diff --git a/monitor.cpp b/monitor.cpp
new file mode 100644
index 0000000..32754f5
--- /dev/null
+++ b/monitor.cpp
@@ -0,0 +1,14 @@
+#include "monitor.h"
+
+CMonitor::CMonitor()
+{
+}
+
+CMonitor::~CMonitor()
+{
+}
+
+void CMonitor::get_datetime(wxDateTime& dt)
+{
+    dt = wxDateTime::Now();
+}
diff --git a/monitor.h b/monitor.h
new file mode 100644
index 0000000..25a703b
--- /dev/null
+++ b/monitor.h
@@ -0,0 +1,19 @@
+#pragma once
+#include <wx/wx.h>
+
+enum BatteryState {
+
+};
+
+class CMonitor
+{
+public:
+    CMonitor();
+    virtual ~CMonitor();
+
+public:
+    virtual void get_datetime(wxDateTime& dt);
+    virtual void get_run_datetime(wxDateTime& dt) = 0;
+    virtual int get_cpu_use() = 0;
+    virtual BatteryState get_mem_use() = 0;
+};
\ No newline at end of file
diff --git a/win_monitor.cpp b/win_monitor.cpp
new file mode 100644
index 0000000..e1f8203
--- /dev/null
+++ b/win_monitor.cpp
@@ -0,0 +1,23 @@
+#include "win_monitor.h"
+
+CWinMonitor::CWinMonitor()
+{
+}
+
+CWinMonitor::~CWinMonitor()
+{
+}
+
+void CWinMonitor::get_run_datetime(wxDateTime& dt)
+{
+}
+
+int CWinMonitor::get_cpu_use()
+{
+    return 0;
+}
+
+BatteryState CWinMonitor::get_mem_use()
+{
+    return BatteryState();
+}
diff --git a/win_monitor.h b/win_monitor.h
new file mode 100644
index 0000000..0892a4f
--- /dev/null
+++ b/win_monitor.h
@@ -0,0 +1,14 @@
+#pragma once
+#include "monitor.h"
+
+class CWinMonitor : public CMonitor
+{
+public:
+    CWinMonitor();
+    virtual ~CWinMonitor();
+
+public:
+    void get_run_datetime(wxDateTime& dt) override;
+    int get_cpu_use() override;
+    BatteryState get_mem_use() override;
+};
\ No newline at end of file