X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/42bcb12b405f19915ed009f6aa323d0e48cd89f6..27a97d02eb2f3dcf031c5cbcd3c1321c6d35fce8:/src/msw/app.cpp diff --git a/src/msw/app.cpp b/src/msw/app.cpp index 97db714527..3424745eaf 100644 --- a/src/msw/app.cpp +++ b/src/msw/app.cpp @@ -724,15 +724,33 @@ int wxEntry(WXHINSTANCE hInstance, int retValue = 0; - if ( wxTheApp->OnInit() ) + // it is common to create a modal dialog in OnInit() (to ask/notify the + // user about something) but it wouldn't work if we don't change the + // "exit on delete last frame" flag here as when this dialog is + // deleted, the app would terminate (it was the last top level window + // as the main frame wasn't created yet!), so disable this behaviour + // temproarily + bool exitOnLastFrameDelete = wxTheApp->GetExitOnFrameDelete(); + wxTheApp->SetExitOnFrameDelete(FALSE); + + // init the app + retValue = wxTheApp->OnInit() ? 0 : -1; + + // restore the old flag value + wxTheApp->SetExitOnFrameDelete(exitOnLastFrameDelete); + + if ( retValue == 0 ) { if ( enterLoop ) { + // run the main loop retValue = wxTheApp->OnRun(); } else - // We want to initialize, but not run or exit immediately. + { + // we want to initialize, but not run or exit immediately. return 1; + } } //else: app initialization failed, so we skipped OnRun() @@ -1262,12 +1280,22 @@ void wxExit() } // Yield to incoming messages + +static bool gs_inYield = FALSE; + bool wxYield() { // disable log flushing from here because a call to wxYield() shouldn't // normally result in message boxes popping up &c wxLog::Suspend(); +#ifdef __WXDEBUG__ + if (gs_inYield) + wxFAIL_MSG( wxT("wxYield called recursively" ) ); +#endif + + gs_inYield = TRUE; + // we don't want to process WM_QUIT from here - it should be processed in // the main event loop in order to stop it MSG msg; @@ -1289,9 +1317,20 @@ bool wxYield() // let the logs be flashed again wxLog::Resume(); + gs_inYield = FALSE; + return TRUE; } +// Yield to incoming messages; but fail silently if recursion is detected. +bool wxYieldIfNeeded() +{ + if (gs_inYield) + return FALSE; + + return wxYield(); +} + bool wxHandleFatalExceptions(bool doit) { #if wxUSE_ON_FATAL_EXCEPTION @@ -1301,7 +1340,8 @@ bool wxHandleFatalExceptions(bool doit) return TRUE; #else wxFAIL_MSG(_T("set wxUSE_ON_FATAL_EXCEPTION to 1 to sue this function")); - + + (void)doit; return FALSE; #endif }