From 948deb14080ff3e62abeeef5a97bf23688f32ffc Mon Sep 17 00:00:00 2001 From: taynpg Date: Mon, 5 Aug 2024 17:31:26 +0800 Subject: [PATCH] =?UTF-8?q?base=EF=BC=9A=E6=9C=80=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E7=9A=84=E5=8F=AF=E4=BB=A5=E8=B7=91=E8=B5=B7=E6=9D=A5=E7=9A=84?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 4 +++- MainUi.cpp | 30 ++++++++++++++++++++++++++++++ MainUi.h | 20 ++++++++++++++++++++ main.cpp | 8 +++----- 4 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 MainUi.cpp create mode 100644 MainUi.h diff --git a/CMakeLists.txt b/CMakeLists.txt index aa82237..226fdea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,8 @@ endif() find_package(wxWidgets REQUIRED COMPONENTS core base) include(${wxWidgets_USE_FILE}) -add_executable(LinuxPack main.cpp) +add_executable(LinuxPack main.cpp + MainUi.h + MainUi.cpp) target_link_libraries(LinuxPack PRIVATE ${wxWidgets_LIBRARIES}) set_target_properties(LinuxPack PROPERTIES WIN32_EXECUTABLE TRUE) diff --git a/MainUi.cpp b/MainUi.cpp new file mode 100644 index 0000000..0c0286d --- /dev/null +++ b/MainUi.cpp @@ -0,0 +1,30 @@ +#include "MainUi.h" + +bool CLinuxPack::OnInit() +{ + auto* frame = new CMainFrame(wxT("Linux二进制打包工具")); + frame->Show(true); + return true; +} + +void CMainFrame::OnQuit(wxCommandEvent& event) +{ + Close(); +} + +CMainFrame::CMainFrame(const wxString& title) : wxFrame(nullptr, wxID_ANY, title) +{ + auto* button = new wxButton(this, wxID_OK, wxT("OK"), wxPoint(100, 100)); + + wxSize screenSize = wxGetDisplaySize(); + wxSize initSize(screenSize.GetWidth() / 2, screenSize.GetHeight() / 2); + + SetSize(initSize); + + // 计算窗口的位置,使其居中 + int x = (screenSize.GetWidth() - initSize.GetWidth()) / 2; + int y = (screenSize.GetHeight() - initSize.GetHeight()) / 2; + + // 设置窗口的位置 + SetPosition(wxPoint(x, y)); +} diff --git a/MainUi.h b/MainUi.h new file mode 100644 index 0000000..bea3201 --- /dev/null +++ b/MainUi.h @@ -0,0 +1,20 @@ +#ifndef MAIN_UI +#define MAIN_UI + +#include +#define USE_DYNAMIC_CONNECT + +class CLinuxPack : public wxApp +{ +public: + bool OnInit() override; +}; + +class CMainFrame : public wxFrame +{ +public: + explicit CMainFrame(const wxString& title); + void OnQuit(wxCommandEvent& event); +}; + +#endif \ No newline at end of file diff --git a/main.cpp b/main.cpp index 4f9de56..8f174ce 100644 --- a/main.cpp +++ b/main.cpp @@ -1,7 +1,5 @@ #include +#include "MainUi.h" -int main() -{ - std::cout << "Hello, World!" << std::endl; - return 0; -} +IMPLEMENT_APP(CLinuxPack); +DECLARE_APP(CLinuxPack); \ No newline at end of file