wxwidgets实战手册-c++(2)

发布时间 2023-11-22 23:29:40作者: 水宝石

目录

oninit

  • 继承自wxApp的子类,可将它视为main和winmain,应用程序的入口
// wxWidgets "Hello World" Program

// For compilers that support precompilation, includes "wx/wx.h".
#include <wx/wxprec.h>

#ifndef WX_PRECOMP
    #include <wx/wx.h>
#endif

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

class MyFrame : public wxFrame
{
public:
    MyFrame();

private:
    void OnExit(wxCommandEvent& event);
};


wxIMPLEMENT_APP(MyApp);

bool MyApp::OnInit()
{
    MyFrame *frame = new MyFrame();
    frame->Show(true);
    return true;
}

MyFrame::MyFrame()
    : wxFrame(NULL, wxID_ANY, "Hello World")
{

    CreateStatusBar();
    SetStatusText("Welcome to wxWidgets!");
}

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



  • OnInit函数返回true时,wxwidgetsta负责处理用户输入的事件循环运行事件。如果函数返回false,wxwidget会分解它的内部结构,一个复制体会终止。

image