#include<wx/wx.h>
#include<wx/menu.h>
class MyMenu:public wxFrame//菜单类
{
public:
MyMenu(const wxString& title);
void OnQuit(wxCommandEvent &event);
wxMenuBar *menubar;//菜单栏
wxMenu *file;//菜单栏下拉选项
};
MyMenu::MyMenu(const wxString& title)
:wxFrame(NULL,wxID_ANY,title,wxDefaultPosition,wxSize(280,180))
{
menubar = new wxMenuBar;//创建对象
file = new wxMenu;//创建对象
file->Append(wxID_EXIT,wxT("&Quit"));//添加对象
menubar->Append(file,wxT("&File"));
SetMenuBar(menubar);
//将退出函数与wxEVT_COMMAND_MENU_SELECTED绑定
Connect(wxID_EXIT,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(MyMenu::OnQuit));
Centre();
}
void MyMenu::OnQuit(wxCommandEvent &event)
{
Close(true);
}
class MyApp:public wxApp
{
public:
virtual bool OnInit();
};
IMPLEMENT_APP(MyApp)
bool MyApp::OnInit()
{
MyMenu *menu = new MyMenu(wxT("My Menu"));
menu->Show(true);
return true;
}
运行结果: