AS> Instead of looking at that old test with wxAppConsole in it, I wrote
AS> up a class which demonstrates what I mean:
AS> http://pastebin.com/download.php?i=rcR0pzPQ
AS> Use comment out the #defines near the top to cause different
AS> behavior.
What version of wx do you use to test this and how do you build your
application, as a console or as a GUI program?
AS> I write out events to "events.txt". Notice if an event
AS> loop is used, and the application
AS> is closed by the user,
I don't understand how can it be closed by user if it's a console
application and I don't understand how can you use wxAppConsole if it
isn't. IOW I'm quite confused, could you please explain how does this work?
Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
I assume your user is exiting the application by pressing Ctrl-C, or
something similar... in that case it's the same thing I was testing
right now, and works by installing a simple signal handler which
terminates the main loop, ie:
Add this function somewere:
static void my_signal_handler (int sig)
{
// Caught signal 'sig'
wxGetApp ().ExitMainLoop ();
}
And add this to your MyAppConsole's constructor:
signal (SIGINT, my_signal_handler);
This worked for me at least on linux (SIGINT catches Ctrl-C), don't know
if it will work on Windows (you may need to call 'SetConsoleCtrlHandler'
instead of 'signal'; see
http://www.cplusplus.com/forum/beginner/1501/#msg5410 )
Regards,
--
========================
Carlos Rodriguez Llodrá
carlos....@gmail.com
AS> So the plan was to have this wxAppConsole executable running 24/7,
AS> with an event loop that handled events (specifically
AS> wxFileSystemWatcherEvent events). It won't do anything else but sit
AS> there. I wrongly assumed that OnExit was supposed to be called or an
AS> event was supposed to be generated when:
AS> The user pressed Ctrl-C or,
AS> When the user pressed the X on the window with their mouse.
No, both result in an abnormal termination. You do need to use Win32
SetConsoleCtrlHandler() function to handle both of the above events but
wxWidgets doesn't wrap it currently (maybe it should).
AS> I don't see anything involving I/O as possible using wxAppConsole,
AS> even with signal handlers; and I don't want to use MS specific stuff
AS> ('SetConsoleCtrlHandler').
Why not? It's the right function to use here and you can isolate the
platform-specific part from the rest of your code quite easily (under Unix
you have a completely functionally equivalent signal(SIGINT)). Or, with
some more effort, you could isolate it even more thoroughly by submitting a
patch to wx adding a virtual OnConsoleInterrupt() method to wxAppConsole.