#include "wx/wx.h"
class MyFrame : public wxFrame
{
public:
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
};
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame((wxFrame *)NULL, -1, title, pos, size)
{
wxBoxSizer *topsizer = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *vertsizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *text = new wxStaticText(this, -1, _T("Hello World!"));
topsizer->Add(vertsizer, 1, wxALIGN_CENTER | wxALL, 10);
vertsizer->Add(text, 1, wxALIGN_CENTER | wxALL, 10);
SetSizer(topsizer);
}
class MyApp : public wxApp
{
public:
virtual bool OnInit();
};
IMPLEMENT_APP(MyApp)
bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame(_T("Hello World"), wxPoint(50, 50), wxSize(600, 340));
frame->Show(TRUE);
return TRUE;
}
#include "wx/wx.h"
class MyFrame : public wxFrame
{
public:
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
void OnClose(wxCloseEvent& event);
void OnQuit(wxCommandEvent& event);
void OnClickMe(wxCommandEvent& event);
private:
wxButton *m_clickButton;
DECLARE_EVENT_TABLE();
};
enum {
ID_Quit = 1,
ID_About,
ID_CLICK_ME,
};
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_CLOSE(MyFrame::OnClose)
EVT_MENU(ID_About, MyFrame::OnAbout)
EVT_MENU(ID_Quit, MyFrame::OnQuit)
EVT_BUTTON(ID_CLICK_ME, MyFrame::OnClickMe)
END_EVENT_TABLE()
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame((wxFrame *)NULL, -1, title, pos, size)
{
wxMenu *menu = new wxMenu;
wxMenuBar *menuBar = new wxMenuBar;
menu->Append(ID_About, _T("&About..."));
menu->AppendSeparator();
menu->Append(ID_Quit, _T("&Quit"));
menuBar->Append(menu, _T("&File"));
SetMenuBar(menuBar);
m_clickButton = new wxButton(this, ID_CLICK_ME, _T("Click Me!"));
wxBoxSizer *topsizer = new wxBoxSizer(wxHORIZONTAL);
topsizer->Add(m_clickButton, 0, wxTOP | wxALL, 5);
SetSizer(topsizer);
}
void MyFrame::OnClose(wxCloseEvent& event)
{
.. event.Skip() ..
}
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
wxMessageBox(_T("Toplevel wxWidgets Sample"), _T("About Toplevel"), wxICON_INFORMATION | wxOK, this);
}
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
Close(TRUE);
}
void MyFrame::OnClickMe(wxCommandEvent& WXUNUSED(event))
{
..
}
class MyApp : public wxApp
{
public:
virtual bool OnInit();
};
IMPLEMENT_APP(MyApp)
bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame(_T("Click Me Demo"), wxPoint(50, 50), wxSize(450, 340));
frame->Show(TRUE);
SetTopWindow(frame);
return TRUE;
}