#include <wx/app.h>
#include <wx/frame.h>
#include <wx/button.h>
#define BTN1_ID 1000
#define BTN2_ID 2000
class MyFrame : public wxFrame //自定义窗口
{
public:
MyFrame(wxWindow *parent,
wxWindowID id,
const wxString& title,
const wxPoint& pos=wxDefaultPosition,
const wxSize& size=wxDefaultSize,
long style=wxDEFAULT_FRAME_STYLE);
void OnBtn1Click(wxCommandEvent& event);
void OnBtn2Click(wxCommandEvent& event);
private:
DECLARE_EVENT_TABLE()
};
MyFrame::MyFrame(wxWindow* parent,
wxWindowID id,
const wxString& title,
const wxPoint& pos,
const wxSize& size,
long style)
:wxFrame(parent,id,title,pos,size,style)
{
wxButton *btn1=new wxButton(this,BTN1_ID,wxT("BTN1"),wxPoint(100,100),wxSize(60,60));
wxButton *btn2=new wxButton(this,BTN2_ID,wxT("BTN2"),wxPoint(200,200),wxSize(50,50));
}
void MyFrame::OnBtn1Click(wxCommandEvent& event)
{
this->SetTitle(wxT("BTN1 is clicked!"));
}
void MyFrame::OnBtn2Click(wxCommandEvent& event)
{
this->SetTitle(wxT("BTN2 is clicked!"));
}
class MyApp : public wxApp
{
public:
bool OnInit();//虚函数重载
};
DECLARE_APP(MyApp) //声明main函数
IMPLEMENT_APP(MyApp)
bool MyApp::OnInit() //main函数执行时要调用的函数
{
if(!wxApp::OnInit())
{
return false;
}
//创建顶层窗口
wxFrame *frame1=new MyFrame(NULL,wxID_ANY,wxT("my first window"),wxDefaultPosition,wxSize(600,400));
frame1->Show();
return true;
}
BEGIN_EVENT_TABLE(MyFrame,wxFrame)//事件表声明
EVT_BUTTON(BTN1_ID,MyFrame::OnBtn1Click)
EVT_BUTTON(BTN2_ID,MyFrame::OnBtn2Click)
END_EVENT_TABLE()
wxwidgets之入门示例
最新推荐文章于 2023-07-18 16:11:01 发布