64,648
社区成员
发帖
与我相关
我的任务
分享
#include <wx/wx.h>
class MyApp : public wxApp
{
public:
virtual bool OnInit();
};
class MyFrame : public wxFrame
{
public:
MyFrame(const wxString & title);
void OnQuit(wxCommandEvent & event);
void OnAbout(wxCommandEvent & event);
private :
DECLARE_EVENT_TABLE()
};
DECLARE_APP(MyApp)
IMPLIMENT_APP(MyApp)
bool MyApp::OnInit()//问题就出在这儿 编译后的提示是:
//error: expected constructor, destructor, or type conversion before "bool"
{
MyFrame *frame = new MyFrame(wxT("Minimal wxWidget App"));
frame->Show(true);
return true;
}
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)
{
Close();
}
#include "mondrian.xpm"
MyFrame::MyFrame(const wxString & title)
:wxFrame(NULL, wxID_ANY, title)
IMPLIMENT_APP(MyApp)改为 IMPLEMENT_APP(MyApp)
DECLARE_APP(MyApp)
IMPLIMENT_APP(MyApp)
bool MyApp::OnInit()//问题就出在这儿 编译后的提示是:
将IMPLIMENT_APP(MyApp)改为 IMPLEMENT_APP(MyApp)就可以了
原来编译提示说的是前面的构造函数或析构函数有问题
#include <wx/wx.h>
class Simple : public wxFrame
{
public:
Simple(const wxString& title);
};
Simple::Simple(const wxString& title)
: wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(250, 150))
{
Centre();
}
class MyApp : public wxApp
{
public:
virtual bool OnInit();
};
IMPLEMENT_APP(MyApp)
bool MyApp::OnInit()
{
Simple *simple = new Simple(wxT("Simple"));
simple->Show(true);
return true;
}
{
SetIcon(wxIcon(mondrian_xpm));
wxMenu *fileMenu = new wxMenu;
wxMenu *helpMenu = new wxMenu;
helpMenu->Append(wxID_ABOUT, wxT("&About...\tF1"),
wxT("Show about dailog"));
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!"));
}