What is *App.cpp for? Topic is solved

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
User avatar
WXWdan
In need of some credit
In need of some credit
Posts: 5
Joined: Fri Dec 15, 2017 5:56 pm

What is *App.cpp for?

Post by WXWdan » Fri Feb 01, 2019 6:57 pm

Hello everybody and excuse my rather nonsensical subject title.

I'm new to wxwidgets + wxsmith + C::B and I'm already getting adapted the this environment. From my very first test and searches it seems like a solid development pack.

I've created a testing project having a single frame and I get, among others, these files:

testApp.cpp
testFrame.cpp
test.wxs

It compiles and runs nicely but I have some doubts about testApp.cpp. I see testApp.cpp initializes my frame like this:

Code: Select all

bool testApp::OnInit()
{
    //(*AppInitialize
    bool wxsOK = true;
    wxInitAllImageHandlers();
    if ( wxsOK )
    {
    	testFrame* Frame = new testFrame(0);
    	Frame->Show();
    	SetTopWindow(Frame);
    }
    //*)

    return wxsOK;

}
I also see testFrame.cpp is comprised of frame events functions, basically where the actions happens. But when I see testApp.cpp, I look at it is as somehow isolated from testFrame.cpp. Yes, it creates and initializes the frame but testFrame.cpp is not even referenced by a header definition. No way to create code that 'communicate' testApp.cpp with testFrame.cpp.

I'm pretty sure I'm missing something essential. I've tried to find some info on the wikis and tutorials but I'm miserably failing at get the right information. There's a lot of documentation and examples but most of these are based of coding from scratch, not using wxsmith.

A secondary questions is about wxsmith 'commented' code in the source. This way to insert code is new to me. When is it interpreted, at compile or pre-processing time?.

I'm sorry for the long post and I'm thankful you for your help in advance.

Thank you.

Manolo
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 664
Joined: Mon Apr 30, 2012 11:07 pm

Re: What is *App.cpp for?

Post by Manolo » Fri Feb 01, 2019 9:07 pm

If you want to learn wxWidgets I strongly advice studying the samples/minimal at your wx dir.

The first thing wx needs is to start the library. It includes not only basic classes, but also the "main" function required to start any app, and the events-loop. This is why you need to derive your own "MyApp" (or any name you like) from wxApp, and override wxApp::OnInit(). In this member you usually create the main window (a wxFrame derived type).

If the definition of the "MyFrame" class is in another .cpp file, likely its declaration is in another .h file, which you must #include before OnInit() uses it.
All of it should be done "automagically" by C::B's wxSmith. Look for it at testApp.
[h]

wxSmith not only "writes" some code for you, but also adds special code so as you are able to modify your controls (with the IDE) and the changes get reflected into the code. Take a look at the .wxs file.
The "special code" includes strange comments. Read about them at wxSmith docs, where it says "This is a block of code that is automatically generated by wxSmith"...

User avatar
WXWdan
In need of some credit
In need of some credit
Posts: 5
Joined: Fri Dec 15, 2017 5:56 pm

Re: What is *App.cpp for?

Post by WXWdan » Fri Feb 01, 2019 9:59 pm

Manolo, thank you for taking your time exposing these concept to me. And thank you for pointing at that wx Smith document, if didn't know about it, it seems really knowledgeable.

Gracias :wink:

Post Reply