简体   繁体   中英

Where is the main function in a wxWidgets application?

I try to use wxWidgets in my C++ project.
As far as I know, for wxWidgets I need to use wxIMPLEMENT_APP(MyAPP ); instead of the main() function.
I don't understand how to write other functions to do other work before my wxWidgets graphics object is created.
In other words, I would like to understand how to get a result like this:

int main(int argc, char* argv[]) {
    configure_application_1();
    app_config app_cfg;
    app_configuration(app_cfg); 
    
    other_functions();

    ___create_wxWidgets________

}

According to the official doc :

A wxWidgets application does not have a main procedure; the equivalent is the wxApp::OnInit member defined for a class derived from wxApp.

So put your code in wxApp::OnInit function.

The main() , or WinMain() (or other entry points that used to exist, but don't any more because the corresponding platforms have gone extinct), is part of wxIMPLEMENT_APP() macro expansion. If you don't want it to define your entry point, you can use wxIMPLEMENT_APP_NO_MAIN() , but then you're responsible for initializing the library yourself.

However typically you would just leave it be and put your initialization code in your overridden MyApp::OnInit() , where MyApp is your class inheriting from wxApp .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM