一个基本的wxWidgets程序

转自Cross Platform Gui Programming
配置:win10+msvc2013+wxWidgets3.1.0

#include<wx/wx.h>

class MyApp : public wxApp
{
public:
    virtual bool OnInit();
};

class MyFrame : public wxFrame
{
public:
    MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
    void OnQuit(wxCommandEvent& event);
    void OnAbout(wxCommandEvent& event);
private:
    wxDECLARE_EVENT_TABLE();
};

//声明可以使用全局的指针MyApp& wxGetApp();
DECLARE_APP(MyApp);

//事件映射表;
wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(wxID_ABOUT,MyFrame::OnAbout)    //菜单项关联到事件处理函数;
EVT_MENU(wxID_EXIT,MyFrame::OnQuit)
wxEND_EVENT_TABLE()

//主程序入口;
wxIMPLEMENT_APP(MyApp);


//初始化定义;
bool MyApp::OnInit()
{
    //MyFrame *frame = new MyFrame("Hello World", wxPoint(50, 50), wxSize(450, 340)); 
    MyFrame *frame = new MyFrame("Hello World", wxDefaultPosition, wxDefaultSize);
    frame->Show(true);
    return true;
}

MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
    : wxFrame(NULL, wxID_ANY, title, pos, size)
{
    //创建菜单项;
    wxMenu *fileMenu = new wxMenu;
    fileMenu->Append(wxID_ABOUT);
    wxMenu* helpMenu = new wxMenu;
    helpMenu->Append(wxID_EXIT);

    //创建菜单条;
    wxMenuBar *menuBar = new wxMenuBar;
    menuBar->Append(fileMenu, "&File");
    menuBar->Append(helpMenu, "&Help");
    SetMenuBar(menuBar);

    //创建状态栏;
    CreateStatusBar();
    SetStatusText("Welcome to wxWidgets!");
}

void MyFrame::OnQuit(wxCommandEvent& event)
{
    Close();
}

void MyFrame::OnAbout(wxCommandEvent& event)
{
    wxString msg;   
    msg.Printf(wxT("hello and welcome to %s"), wxVERSION_STRING);
    wxMessageBox(msg, wxT("about Minimal"), wxOK | wxICON_INFORMATION, this);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值