wxwidgets之入门示例

#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()


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值