一、main.h
#include <wx/wx.h>
class MyApp:public wxApp
{
public:
virtual bool OnInit();
};
二、main.cpp
#include "main.h"
#include "MyFrame.h"
wxIMPLEMENT_APP(MyApp);
bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame("my frame");
frame->Show(true);
return true;
}
三、myframe.h
class MyFrame:public wxFrame
{
public:
MyFrame(const wxString &title);
protected:
void OnExit(wxCommandEvent &event);//1 用作静态绑定示例
private:
wxDECLARE_EVENT_TABLE();//2 声明静态事件表的
};
四、myframe.cpp
#include <wx/wx.h>
#include "myframe.h"
// 3 静态事件表的声明
wxBEGIN_EVENT_TABLE(MyFrame,wxFrame)
EVT_BUTTON(wxID_EXIT,MyFrame::OnExit)
wxEND_EVENT_TABLE()
MyFrame::MyFrame(const wxString &title)
:wxFrame(NULL,wxID_ANY,title,wxDefaultPosition,wxSize(200,150))
{
wxPanel *panel = new wxPanel(this,wxID_ANY,wxDefaultPosition,wxSize(100,100));
//*** 4事件静态绑定按钮 ***
wxButton *btnExit = new wxButton;
btnExit->Create(panel,wxID_EXIT,"Exit"
,wxPoint(0,button->GetPosition().y + button->GetSize().GetHeight())
);
Centre();
}
void MyFrame::OnExit(wxCommandEvent &event)
{
Close(true);
}