#include <wx/wxprec.h>
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
const int ID_message1 = 1;
const int ID_message2 = 2;
const int ID_messages = 3;
const int ID_exit = 4;
const int ID_about = 5;
class MainFrame;
class SampleApp : public wxApp
{
private:
virtual bool OnInit();
MainFrame * frmMain;
};
IMPLEMENT_APP (SampleApp)
class MainFrame : public wxFrame
{
public:
MainFrame (const wxString & title,
const wxPoint & position,
const wxSize & size);
void OnFileMessage1 (wxCommandEvent &);
void OnFileMessage2 (wxCommandEvent &);
void OnFileExit (wxCommandEvent &);
void OnHelpAbout (wxCommandEvent &);
private:
DECLARE_EVENT_TABLE ()
};
bool SampleApp::OnInit()
{
frmMain = new MainFrame ("Sample Application",
wxPoint(20,20),
wxSize(200,150));
frmMain->Show (true);
SetTopWindow (frmMain);
return true;
}
BEGIN_EVENT_TABLE (MainFrame, wxFrame)
EVT_MENU (ID_message1, MainFrame::OnFileMessage1)
EVT_MENU (ID_message2, MainFrame::OnFileMessage2)
EVT_MENU (ID_exit, MainFrame::OnFileExit)
EVT_MENU (ID_about, MainFrame::OnHelpAbout)
END_EVENT_TABLE ()
MainFrame::MainFrame (const wxString & title,
const wxPoint & position,
const wxSize & size)
: wxFrame (NULL, -1, title, position, size)
{
wxMenuBar * menuBar = new wxMenuBar; // main menu bar
wxMenu * menuFile = new wxMenu; // menu items and submenus
wxMenu * menuHelp = new wxMenu;
wxMenu * menuMessages = new wxMenu;
menuMessages->Append (ID_message1, "Message 1");
menuMessages->Append (ID_message2, "Message 2");
menuFile->Append (ID_messages, "Display &Message",
menuMessages);
menuFile->AppendSeparator();
menuFile->Append (ID_exit, "E&xit\tCtrl-Q");
menuHelp->Append (ID_about, "&About");
menuBar->Append (menuFile, "&File");
menuBar->Append (menuHelp, "&Help");
SetMenuBar (menuBar);
}
void MainFrame::OnFileMessage1 (wxCommandEvent &)
{
wxMessageBox ("Message 1");
}
void MainFrame::OnFileMessage2 (wxCommandEvent &)
{
wxMessageBox ("Message 2. Notice the different style "
"and positioning relative to main window",
"wxWindows Sample",
wxOK | wxICON_INFORMATION,
this);
}
void MainFrame::OnHelpAbout (wxCommandEvent &)
{
wxMessageBox ("About wxWindows Minimal Sample",
"wxWindows Sample",
wxOK | wxICON_INFORMATION,
this);
}
void MainFrame::OnFileExit (wxCommandEvent &)
{
Close (true); // close main frame, terminating
// the application
}
End of Listing