wxWidgets框架的一个例子

#ifndef MY_TEST_H_
#define MY_TEST_H_

#include "wx/wx.h"

//定义应用程序类
class MyApp:public wxApp
{
public:
	virtual bool OnInit();//启动时被调用
};


class MyDlg:public wxDialog
{
	DECLARE_CLASS(MyDlg)
	DECLARE_EVENT_TABLE()
public:
	MyDlg();
	virtual ~MyDlg();

	//初始化
	void init();

	//创建窗体
	bool CreateDlg(wxWindow * parent,
		wxWindowID id,
		const wxString& DlgTitle,
		const wxPoint& DlgPos,
		const wxSize& DlgSize,
		long DlgStyle=wxCAPTION | wxRESIZE_BORDER | wxSYSTEM_MENU);

	//创建控件
	void CreateControls();
};


//定义主窗口类
class MyFrame:public wxFrame
{
public:
	//构造函数 参数:框架窗口标题栏文本
	MyFrame(const wxString& title);

	//事件处理函数 参数:事件类对象
	void OnAbout(wxCommandEvent& event);
	
	//按钮点击
	void OnButtonOK(wxCommandEvent& event);

	wxDialog * pDlg;

private:
	DECLARE_EVENT_TABLE()//事件声明表
};

DECLARE_APP(MyApp)//为了使用wxGetApp()函数

IMPLEMENT_APP(MyApp)//实现应用程序的类(类似注册MFC theApp)



#endif //MY_TEST_H_

 

#include "MyTest.h"

//类的事件表MyFrame
BEGIN_EVENT_TABLE(MyFrame,wxFrame)
	EVT_MENU(wxID_ABOUT,MyFrame::OnAbout)
	EVT_BUTTON(wxID_OK,MyFrame::OnButtonOK)
END_EVENT_TABLE()




/实现部分///

bool MyApp::OnInit()//实现初始化函数
{
	MyFrame * frame=new MyFrame(_T("框架窗口标题栏"));//创建主窗口

	frame->Show(true);//显示主窗口

	return true;
}


//框架窗口实现部分
MyFrame::MyFrame(const wxString& title):wxFrame(NULL,wxID_ANY,title)
{
	wxMenuBar * menuBar = new wxMenuBar();//创建菜单栏对象
	
	wxMenu * helpMenu = new wxMenu();//创建菜单项对象
	
//	wxButton * button = new wxButton(this,wxID_OK,wxT("按钮文字"),wxPoint(0,0),wxSize(200,200));

	//添加子菜单项
	helpMenu->Append(wxID_ABOUT,_T("&About...\tF1"),_T("鼠标经过消息响应"));
	
	//将子菜单添加到菜单项中
	menuBar->Append(helpMenu, _T("帮助"));

	//设置菜单栏
	SetMenuBar(menuBar);

	//创建状态栏
	CreateStatusBar(1);
	
	//设置状态栏文本
	SetStatusText(_T("状态栏文本"));
}

void MyFrame::OnAbout(wxCommandEvent& event)
{
	wxString msg;
	
	msg.Printf(_T("当前类库版本: %s"),wxVERSION_STRING);//wx字符串格式化(类似CString::Format)

	/*消息框 类似AfxMessageBox
	参数1 显示文字
	参数2 标题栏文字
	参数3 风格类型
	参数4 父窗口指针
	*/
	wxMessageBox(msg,_("消息框标题栏文字"),wxOK | wxICON_INFORMATION,this);
}


void MyFrame::OnButtonOK(wxCommandEvent& event)
{
	wxMessageBox(_T("按钮单机事件响应"),_("标题栏文字"),wxOK | wxICON_INFORMATION,this);
}




MyDlg::MyDlg()
{}


//初始化
void MyDlg::init()
{

}

//创建窗体
bool MyDlg::CreateDlg(wxWindow * parent,
		wxWindowID id,
		const wxString& DlgTitle,
		const wxPoint& DlgPos,
		const wxSize& DlgSize,
		long DlgStyle)
{
	return true;
}

//创建控件
void MyDlg::CreateControls()
{

}

 

转载于:https://my.oschina.net/mlgb/blog/272158

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值