base.cpp #include #ifndef WX_PRECOMP #include #endif #include #include "base.h" BEGIN_EVENT_TABLE ( MainFrame, wxFrame ) EVT_MENU(MENU_New, MainFrame::NewFile) EVT_MENU(MENU_Open, MainFrame::OpenFile) EVT_MENU(MENU_Close, MainFrame::CloseFile) EVT_MENU(MENU_Save, MainFrame::SaveFile) EVT_MENU(MENU_SaveAs, MainFrame::SaveFileAs) EVT_MENU(MENU_Quit, MainFrame::Quit) EVT_MENU(MENU_Admin,MainFrame::Admin) END_EVENT_TABLE() IMPLEMENT_APP(MainApp) bool MainApp::OnInit() { MainFrame *MainWin = new MainFrame(wxT("Hello World!"), wxPoint(1,1), wxSize(300, 200)); // Create an instance of our frame, or window MainWin->Show(TRUE); // show the window SetTopWindow(MainWin);// and finally, set it as the main window return TRUE; } MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size) : wxFrame((wxFrame *) NULL, -1, title, pos, size) { CreateStatusBar(2); MainMenu = new wxMenuBar(); wxMenu *FileMenu = new wxMenu(); FileMenu->Append(MENU_New, wxT("&New"), wxT("Create a new file")); FileMenu->Append(MENU_Open, wxT("&Open"), wxT("Open an existing file")); FileMenu->Append(MENU_Close, wxT("&Close"), wxT("Close the current document")); FileMenu->Append(MENU_Save, wxT("&Save"), wxT("Save the current document")); FileMenu->Append(MENU_SaveAs, wxT("Save &As"), wxT("Save the current document under a new file name")); FileMenu->Append(MENU_Quit, wxT("&Quit"), wxT("Quit the editor")); MainMenu->Append(FileMenu, wxT("File")); SetMenuBar(MainMenu); MainEditBox = new wxTextCtrl(this, TEXT_Main, wxT("Hi!"), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_RICH , wxDefaultValidator, wxTextCtrlNameStr); Maximize(); } void MainFrame::NewFile(wxCommandEvent& WXUNUSED(event)) { } void MainFrame::OpenFile(wxCommandEvent& WXUNUSED(event)) { if(WxOpenFileDialog1->ShowModal()) { MainEditBox->LoadFile(WxOpenFileDialog1->GetPath()); } } void MainFrame::CloseFile(wxCommandEvent& WXUNUSED(event)) { MainEditBox->Clear(); } void MainFrame::SaveFile(wxCommandEvent& WXUNUSED(event)) { MainEditBox->SaveFile(wxT("base.h")); } void MainFrame::SaveFileAs(wxCommandEvent& WXUNUSED(event)) { } void MainFrame::Quit(wxCommandEvent& WXUNUSED(event)) { Close(TRUE); } base.h #ifndef __BASE_H // Make sure to only declare these classes once #define __BASE_H #include #include class MainApp: public wxApp { public: virtual bool OnInit(); }; class MainFrame: public wxFrame { public: MainFrame( const wxString& title, const wxPoint& pos, const wxSize& size ); wxTextCtrl *MainEditBox; wxMenuBar *MainMenu; void Quit(wxCommandEvent& event); void NewFile(wxCommandEvent& event); void OpenFile(wxCommandEvent& event); void SaveFile(wxCommandEvent& event); void SaveFileAs(wxCommandEvent& event); void CloseFile(wxCommandEvent& event); void Admin(wxCommandEvent& event); DECLARE_EVENT_TABLE() }; enum { TEXT_Main = wxID_HIGHEST + 1, // declares an id which will be used to call our button MENU_New, MENU_Open, MENU_Close, MENU_Save, MENU_SaveAs, MENU_Quit, MENU_Admin }; #endif