add:一个基本的无边框窗口。
This commit is contained in:
parent
a82e60b58d
commit
3fbbb0fbdc
@ -19,6 +19,6 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE}
|
|||||||
|
|
||||||
add_subdirectory(ofen)
|
add_subdirectory(ofen)
|
||||||
find_package(wxWidgets CONFIG REQUIRED)
|
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)
|
target_link_libraries(BMonitor PRIVATE wx::core wx::base Ofen)
|
||||||
set_target_properties(BMonitor PROPERTIES WIN32_EXECUTABLE TRUE)
|
set_target_properties(BMonitor PROPERTIES WIN32_EXECUTABLE TRUE)
|
@ -1,5 +1,37 @@
|
|||||||
#include "MainFrame.h"
|
#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)
|
||||||
{
|
{
|
||||||
}
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -5,4 +5,13 @@ class CMainFrame : public wxFrame
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit CMainFrame(const wxString& title);
|
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};
|
||||||
};
|
};
|
14
monitor.cpp
Normal file
14
monitor.cpp
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#include "monitor.h"
|
||||||
|
|
||||||
|
CMonitor::CMonitor()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CMonitor::~CMonitor()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMonitor::get_datetime(wxDateTime& dt)
|
||||||
|
{
|
||||||
|
dt = wxDateTime::Now();
|
||||||
|
}
|
19
monitor.h
Normal file
19
monitor.h
Normal file
@ -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;
|
||||||
|
};
|
23
win_monitor.cpp
Normal file
23
win_monitor.cpp
Normal file
@ -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();
|
||||||
|
}
|
14
win_monitor.h
Normal file
14
win_monitor.h
Normal file
@ -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;
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user