First wxWidgets Demo, wxWidgets简单示例

windows下,注意文件格式设为UTF-8。

Code::Blocks 10.05设置: Setting -> Editor

Main.cpp:

#include "wx/wx.h"
//Declare the application class
class MyApp:public wxApp{
public:
    //Called on application startup
    virtual bool OnInit();
};
// Declare our main frameclass
class MyFrame:public wxFrame{
public:
    // Constructor
    MyFrame(const wxString& title);
    // Event handlers
    void OnQuit(wxCommandEvent& event);
    void OnAbout(wxCommandEvent& event);
private:
    // This class handles events
    DECLARE_EVENT_TABLE();
};
// Implements MyApp& GetApp()
DECLARE_APP(MyApp)
// Give wxWidgets the means to create a MyApp object
IMPLEMENT_APP(MyApp)

// Initialize the application
bool MyApp::OnInit(){
    // Create the main application window
    MyFrame *frame=new MyFrame(wxT("Minimal wxwidgets App"));
    // Show it
    frame->Show(true);
    // Start the event loop
    return true;
}
// Event table for MyFrame
BEGIN_EVENT_TABLE(MyFrame,wxFrame)
    EVT_MENU(wxID_ABOUT,MyFrame::OnAbout)
    EVT_MENU(wxID_EXIT,MyFrame::OnQuit)
END_EVENT_TABLE()

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);
}

void MyFrame::OnQuit(wxCommandEvent& event){
    // Destroy the frame
    Close();
}

//#include "mondrian.xpm"

MyFrame::MyFrame(const wxString& title):
    wxFrame(NULL,wxID_ANY,title){
    //SetIcon(wxIcon(mondrian_xpm));
    wxMenu *fileMenu=new wxMenu;
    wxMenu *helpMenu=new wxMenu;
    helpMenu->Append(wxID_ABOUT,wxT("&About...\tF1"),
                     wxT("Show About dialog"));
    fileMenu->Append(wxID_EXIT,wxT("E&xit\tAlt-X"),
                     wxT("Quit this program退出程序"));
    wxMenuBar *menuBar=new wxMenuBar();
    menuBar->Append(fileMenu,wxT("&File"));
    menuBar->Append(helpMenu,wxT("&Help"));
    SetMenuBar(menuBar);
    CreateStatusBar(2);
    SetStatusText(wxT("中国人Welcome to wxwidgets!"));
}

  

posted @ 2011-10-05 00:26  庚武  Views(1060)  Comments(0Edit  收藏  举报