wxWidgets控件处理事件的传统方法是使用事件表,2.9.0版本后新增了动态绑定方式。
这个小程序包含两个按钮(wxButton)和一个文本框(wxStaticText)。两个按钮采用不同的方式处理点击事件,第一个按钮采用静态事件表,第二个按钮采用动态绑定,点击按钮,按钮计数值增加;文本框负责打印当前窗口的宽高,采用动态绑定,输出随着窗口大小改变。
// C++11编译
#include <wx/wx.h>
class MyApp : public wxApp {
public:
virtual bool OnInit();
};
class MyFrame : public wxFrame {
public:
MyFrame(const wxString &title, const wxPoint &pos, const wxSize &size);
private:
wxButton* button1 = nullptr;
wxButton* button2 = nullptr;
wxStaticText *text = nullptr;
void OnButton_1(wxCommandEvent&);
void OnButton_2(wxCommandEvent&);
void OnSize(wxSizeEvent &event);