C++ 没有wx主程序的wxWidgets——如何编码?
我正在尝试编写一个应用程序的wxWidgets组件,该组件由应用程序的另一部分调用,因此没有wxWidgets主程序。我在查找正确的调用顺序时遇到一些问题 据我所知,首先我需要子类化C++ 没有wx主程序的wxWidgets——如何编码?,c++,wxwidgets,C++,Wxwidgets,我正在尝试编写一个应用程序的wxWidgets组件,该组件由应用程序的另一部分调用,因此没有wxWidgets主程序。我在查找正确的调用顺序时遇到一些问题 据我所知,首先我需要子类化wxApp: class TestApp : public wxApp { public: virtual bool OnInit() override; }; bool TestApp::OnInit() { cerr << "app init\n"<<flush; }
wxApp
:
class TestApp : public wxApp {
public:
virtual bool OnInit() override;
};
bool TestApp::OnInit() {
cerr << "app init\n"<<flush;
}
类TestApp:public wxApp{
公众:
虚拟bool OnInit()覆盖;
};
bool TestApp::OnInit(){
cerrwxEntryStart()
确实不调用OnInit()
,只有wxEntry()
调用
因此,您可以使用wxEntry()
(它也调用OnRun()
)或手动调用wxTheApp->CallOnInit()
有关详细信息,请参见此处:可能重复的Yes,`wxEntry`调用OnInit()
。谢谢。
TestApp* app = new TestApp();
cerr << "a\n";
wxApp::SetInstance(app);
cerr << "b\n";
int argCount = 0;
char* argv[0];
if(! wxEntryStart(argCount, argv)) {
cerr << "wx failed to start\n";
wxExit();
}
cerr << "d\n";
int res = wxGetApp().OnRun();