Page 1 of 1

a wx application with my own main

Posted: Mon Oct 11, 2004 8:11 am
by Javock
Hello,
I'm writing an application and I would like to use wxwindows objects to create windows and such. But I would like to retain my own main() and not use the IMPLEMENT_APP macro...
That's it, I would like to have my program running and only then plug a class that has GUI support. But as the program should run without this class, the main() must be the same...

Any ideas :shock:

Thanks

Re: a wx application with my own main

Posted: Mon Oct 11, 2004 3:18 pm
by jdratlif
Javock wrote:Hello,
I'm writing an application and I would like to use wxwindows objects to create windows and such. But I would like to retain my own main() and not use the IMPLEMENT_APP macro...
That's it, I would like to have my program running and only then plug a class that has GUI support. But as the program should run without this class, the main() must be the same...

Any ideas :shock:

Thanks
Have you looked the IMPLEMENT_APP_NO_MAIN macro? I read about it on this message board somewhere for integrating wxWidget apps with SDL or other toolkits. Don't know how to use it, but there's probably some docs on in out there.

Re: a wx application with my own main

Posted: Mon Oct 11, 2004 5:31 pm
by Javock
jdratlif wrote:
Have you looked the IMPLEMENT_APP_NO_MAIN macro? I read about it on this message board somewhere for integrating wxWidget apps with SDL or other toolkits. Don't know how to use it, but there's probably some docs on in out there.
Great, I will check that out...

Thanks 8)

Posted: Thu Oct 14, 2004 12:56 pm
by ezequielv
Don't forget to check: ::wxEntry() documentation. I'm maintaining an MFC application and I will try to convert it to wxWidgets-only in the future.

So far, what I've had to do is:

non-MFC specific:

1. Create my app class and put the DECLARE_APP() macro in the header file for that class.
2. Put the IMPLEMENT_APP_NOMAIN() macro in my app class' source file (.cpp file).
3. Override wxApp::OnInit(), etc.

MFC app class:

1. Override CWinApp::InitInstance() and CWinApp::ExitInstance() to initialize/uninitialize wxWidgets:
a. Add the call to ::wxEntry() in this CMyApp::InitInstance() (as in the wx/app.h comment just before the IMPLEMENT_APP_NOMAIN() macro). I'm using CWinApp data members m_hInstance, m_hPrevInstance, m_lpCmdLine and m_nCmdShow to call ::wxEntry().
b. Call wxGetApp().OnExit() and wxApp::CleanUp() in CMyApp::ExitInstance() (as in ::wxEntry() documentation).
2. Override CWinApp::PreTranslateMessage() to call wxGetApp().ProcessMessage() (as in wxApp::ProcessMessage() documentation).

I'll probably update the Wiki with this, as it's all spread in the official documentation.

Please note that this is *not* final. However, my application seems to be working allright so far :)

Posted: Thu Oct 14, 2004 4:12 pm
by soks
AH! PLEASE post that on the wiki! I was looking for that kind of information for some time, not at the moment, but that is very useful considering all the knowlege you got requires thinly spread documentation and looking at the source (at least I coudln't find IMPLEMENT_APP_NO_MAIN anywhere but in the headers).

So goodluck and please share that process with everyone =)