a wx application with my own main

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Javock
In need of some credit
In need of some credit
Posts: 9
Joined: Mon Oct 11, 2004 8:06 am
Location: Argentina
Contact:

a wx application with my own main

Post by Javock » Mon Oct 11, 2004 8:11 am

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

jdratlif
Knows some wx things
Knows some wx things
Posts: 25
Joined: Mon Oct 11, 2004 2:12 pm
Location: in a small padded white room.
Contact:

Re: a wx application with my own main

Post by jdratlif » Mon Oct 11, 2004 3:18 pm

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.
Find save states, game genie codes, and other misc emulation related goodies at emuWorks.

http://games.technoplaza.net

Javock
In need of some credit
In need of some credit
Posts: 9
Joined: Mon Oct 11, 2004 8:06 am
Location: Argentina
Contact:

Re: a wx application with my own main

Post by Javock » Mon Oct 11, 2004 5:31 pm

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)

ezequielv
Earned a small fee
Earned a small fee
Posts: 19
Joined: Sun Oct 10, 2004 9:20 pm
Location: Berkshire, England

Post by ezequielv » Thu Oct 14, 2004 12:56 pm

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 :)

soks
Knows some wx things
Knows some wx things
Posts: 32
Joined: Wed Oct 13, 2004 4:57 am

Post by soks » Thu Oct 14, 2004 4:12 pm

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 =)

Post Reply