From: Vadim Zeitlin Date: Tue, 15 Apr 2008 23:30:15 +0000 (+0000) Subject: execute the usual cleanup code from EVT_END_SESSION handler under MSW, otherwise... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/9fb99466b5b43589f477783ca65bf17714ff8615 execute the usual cleanup code from EVT_END_SESSION handler under MSW, otherwise it's not run at all because we're simply killed by the system (bug 1428691) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53186 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/interface/event.h b/interface/event.h index 08a2849d66..945be51cea 100644 --- a/interface/event.h +++ b/interface/event.h @@ -2934,16 +2934,28 @@ public: This allows the wxWindow::Close function to return @true or @false depending on whether the close instruction was honoured or not. + The EVT_END_SESSION event is slightly different as it is sent by the system + when the user session is ending (e.g. because of log out or shutdown) and + so all windows are being forcefully closed. At least under MSW, after the + handler for this event is executed the program is simply killed by the + system. Because of this, the default handler for this event provided by + wxWidgets calls all the usual cleanup code (including wxApp::OnExit()) so + that it could still be executed and exit()s the process itself, without + waiting for being killed. If this behaviour is for some reason undesirable, + make sure that you define a handler for this event in your wxApp-derived + class and do not call @c event.Skip() in it (but be aware that the system + will still kill your application). + @beginEventTable{wxCloseEvent} @event{EVT_CLOSE(func)} Process a close event, supplying the member function. This event applies to wxFrame and wxDialog classes. @event{EVT_QUERY_END_SESSION(func)} Process a query end session event, supplying the member function. - This event applies to wxApp only. + This event can be handled in wxApp-derived class only. @event{EVT_END_SESSION(func)} Process an end session event, supplying the member function. - This event applies to wxApp only. + This event can be handled in wxApp-derived class only. @endEventTable @library{wxcore} diff --git a/src/msw/app.cpp b/src/msw/app.cpp index 04916f784b..95d953241c 100644 --- a/src/msw/app.cpp +++ b/src/msw/app.cpp @@ -598,8 +598,17 @@ void wxApp::WakeUpIdle() void wxApp::OnEndSession(wxCloseEvent& WXUNUSED(event)) { - if (GetTopWindow()) - GetTopWindow()->Close(true); + // Windows will terminate the process soon after we return from + // WM_ENDSESSION handler anyhow, so make sure we at least execute our + // cleanup code before + const int rc = OnExit(); + + wxEntryCleanup(); + + // calling exit() instead of ExitProcess() or not doing anything at all and + // being killed by Windows has the advantage of executing the dtors of + // global objects + exit(rc); } // Default behaviour: close the application with prompts. The