update
This commit is contained in:
parent
14706d425a
commit
c6de43f5c1
|
|
@ -6,13 +6,23 @@ set(CMAKE_CXX_STANDARD 17)
|
|||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
# Add For Windows, specify Unicode
|
||||
set(APP_TYPE "")
|
||||
if(WIN32)
|
||||
add_definitions(-DUNICODE -D_UNICODE)
|
||||
set(APP_TYPE WIN32)
|
||||
endif()
|
||||
|
||||
set(wxBUILD_SHARED OFF)
|
||||
|
||||
# Add wxWidgets as a subdirectory
|
||||
add_subdirectory(external/wxWidgets)
|
||||
|
||||
# get_cmake_property(_variableNames VARIABLES)
|
||||
# list(SORT _variableNames)
|
||||
# foreach(_variableName ${_variableNames})
|
||||
# message(STATUS "${_variableName}=${${_variableName}}")
|
||||
# endforeach()
|
||||
|
||||
# Define your source files
|
||||
set(SRC_DIR ${CMAKE_SOURCE_DIR}/src)
|
||||
file(GLOB SRC_FILES ${SRC_DIR}/*.cpp)
|
||||
|
|
@ -20,8 +30,6 @@ file(GLOB SRC_FILES ${SRC_DIR}/*.cpp)
|
|||
# Include directories
|
||||
include_directories(${CMAKE_SOURCE_DIR}/external/wxWidgets/include)
|
||||
|
||||
add_definitions(-D__WXUNIVERSAL__)
|
||||
|
||||
# Link additional libraries
|
||||
set(WX_LIB
|
||||
wx::core
|
||||
|
|
@ -32,7 +40,7 @@ set(WX_LIB
|
|||
)
|
||||
|
||||
# Create the executable
|
||||
add_executable(${PROJECT_NAME} ${SRC_FILES})
|
||||
add_executable(${PROJECT_NAME} ${APP_TYPE} ${SRC_FILES})
|
||||
|
||||
# Link wxWidgets libraries
|
||||
target_link_libraries(${PROJECT_NAME} ${WX_LIB})
|
||||
|
|
|
|||
119
src/main.cpp
119
src/main.cpp
|
|
@ -1,56 +1,117 @@
|
|||
#include <wx/wx.h>
|
||||
#include <wx/aui/aui.h>
|
||||
#include <wx/settings.h>
|
||||
#include <wx/artprov.h>
|
||||
|
||||
class MyApp.compp : public wxApp
|
||||
// Custom frame class
|
||||
class MyFrame : public wxFrame
|
||||
{
|
||||
public:
|
||||
MyFrame(const wxString &title);
|
||||
|
||||
private:
|
||||
wxAuiManager m_mgr;
|
||||
|
||||
void OnExit(wxCommandEvent &event);
|
||||
void OnAbout(wxCommandEvent &event);
|
||||
// void OnToggleTheme(wxCommandEvent &event);
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
ID_Exit = wxID_EXIT,
|
||||
ID_About = wxID_ABOUT,
|
||||
ID_ToggleTheme = wxID_HIGHEST + 1
|
||||
};
|
||||
|
||||
// Application class
|
||||
class MyApp : public wxApp
|
||||
{
|
||||
public:
|
||||
virtual bool OnInit();
|
||||
};
|
||||
|
||||
class MyFrame.comrame : public wxFrame.comame
|
||||
{
|
||||
public:
|
||||
MyFrame.comrame(const wxString& title);
|
||||
|
||||
private:
|
||||
void OnQuit(wxCommandEvent& event);
|
||||
void OnAbout(wxCommandEvent& event);
|
||||
};
|
||||
|
||||
wxIMPLEMENT_APP(MyApp);
|
||||
|
||||
bool MyApp.comnInit()
|
||||
bool MyApp::OnInit()
|
||||
{
|
||||
MyFrame.comrame* frame = new MyFrame.comrame("Advanced wxWidgets Demo");
|
||||
if (!wxApp::OnInit())
|
||||
return false;
|
||||
|
||||
// Create main frame
|
||||
MyFrame *frame = new MyFrame("Modern wxWidgets App");
|
||||
frame->Show(true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
MyFrame.comrame::MyFrame.comnst wxString& title)
|
||||
: wxFrame.comame(NULL, wxID_ANY, title)
|
||||
MyFrame::MyFrame(const wxString &title)
|
||||
: wxFrame(nullptr, wxID_ANY, title, wxDefaultPosition, wxSize(800, 600)),
|
||||
m_mgr(this)
|
||||
{
|
||||
wxMenu* menuFile = new wxMenu;
|
||||
menuFile->Append(wxID_EXIT);
|
||||
// Create menu bar
|
||||
wxMenu *fileMenu = new wxMenu;
|
||||
fileMenu->Append(ID_Exit, "E&xit\tAlt-X", "Quit this program");
|
||||
|
||||
wxMenu* menuHelp = new wxMenu;
|
||||
menuHelp->Append(wxID_ABOUT);
|
||||
wxMenu *helpMenu = new wxMenu;
|
||||
helpMenu->Append(ID_About, "&About\tF1", "Show about dialog");
|
||||
helpMenu->Append(ID_ToggleTheme, "&Toggle Theme\tCtrl-T", "Toggle Dark Mode");
|
||||
|
||||
wxMenuBar* menuBar = new wxMenuBar.com
|
||||
menuBar->Append(menuFile, "&File");
|
||||
menuBar->Append(menuHelp, "&Help");
|
||||
wxMenuBar *menuBar = new wxMenuBar();
|
||||
menuBar->Append(fileMenu, "&File");
|
||||
menuBar->Append(helpMenu, "&Help");
|
||||
|
||||
SetMenuBar(menuBar);
|
||||
|
||||
Bind(wxEVT_MENU, &MyFrame.comrame::OnQuit, this, wxID_EXIT);
|
||||
Bind(wxEVT_MENU, &MyApp.comrame::OnAbout, this, wxID_ABOUT);
|
||||
// Create a toolbar
|
||||
wxToolBar *toolbar = CreateToolBar();
|
||||
toolbar->AddTool(wxID_ANY, "Exit", wxArtProvider::GetBitmap(wxART_QUIT));
|
||||
toolbar->Realize();
|
||||
|
||||
// Create a text control in the center
|
||||
wxTextCtrl *textCtrl = new wxTextCtrl(this, wxID_ANY, "Modern wxWidgets App",
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
wxTE_MULTILINE | wxNO_BORDER);
|
||||
|
||||
// Create a status bar
|
||||
CreateStatusBar(2);
|
||||
SetStatusText("Welcome to wxWidgets!");
|
||||
|
||||
// Manage layout with wxAuiManager (for modern look)
|
||||
m_mgr.SetManagedWindow(this);
|
||||
m_mgr.AddPane(textCtrl, wxAuiPaneInfo().Center().Caption("Editor"));
|
||||
m_mgr.Update();
|
||||
|
||||
// Bind events
|
||||
Bind(wxEVT_MENU, &MyFrame::OnExit, this, ID_Exit);
|
||||
Bind(wxEVT_MENU, &MyFrame::OnAbout, this, ID_About);
|
||||
// Bind(wxEVT_MENU, &MyFrame::OnToggleTheme, this, ID_ToggleTheme);
|
||||
}
|
||||
|
||||
void MyApp.comrame::OnQuit(wxCommandEvent& event)
|
||||
void MyFrame::OnExit(wxCommandEvent &event)
|
||||
{
|
||||
Close(true);
|
||||
}
|
||||
|
||||
void MyApp.comrame::OnAbout(wxCommandEvent& event)
|
||||
void MyFrame::OnAbout(wxCommandEvent &event)
|
||||
{
|
||||
wxMessageBox("This is an advanced wxWidgets demo application.",
|
||||
"About", wxOK | wxICON_INFORMATION);
|
||||
}
|
||||
wxMessageBox("This is a modern wxWidgets app", "About wxWidgets App", wxOK | wxICON_INFORMATION, this);
|
||||
}
|
||||
|
||||
// void MyFrame::OnToggleTheme(wxCommandEvent &event)
|
||||
// {
|
||||
// wxSystemAppearance appearance = wxSystemSettings::GetAppearance();
|
||||
// bool isDarkMode = appearance.IsDark();
|
||||
|
||||
// if (isDarkMode)
|
||||
// {
|
||||
// wxSystemSettings::SetAppearance(wxSystemAppearance::Light);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// wxSystemSettings::SetAppearance(wxSystemAppearance::Dark);
|
||||
// }
|
||||
|
||||
// wxMessageBox(isDarkMode ? "Switched to Light Mode" : "Switched to Dark Mode", "Theme Switch",
|
||||
// wxOK | wxICON_INFORMATION, this);
|
||||
// }
|
||||
|
|
|
|||
Loading…
Reference in New Issue