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