]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/msw/app.cpp
Rework the wxCusor ctor taking wx stock number to provide as many cursors as
[wxWidgets.git] / src / msw / app.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/msw/app.cpp
3// Purpose: wxApp
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// ===========================================================================
13// declarations
14// ===========================================================================
15
16// ---------------------------------------------------------------------------
17// headers
18// ---------------------------------------------------------------------------
19
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#if defined(__BORLANDC__)
24 #pragma hdrstop
25#endif
26
27#ifndef WX_PRECOMP
28 #include "wx/msw/wrapcctl.h"
29 #include "wx/dynarray.h"
30 #include "wx/frame.h"
31 #include "wx/app.h"
32 #include "wx/utils.h"
33 #include "wx/gdicmn.h"
34 #include "wx/pen.h"
35 #include "wx/brush.h"
36 #include "wx/cursor.h"
37 #include "wx/icon.h"
38 #include "wx/palette.h"
39 #include "wx/dc.h"
40 #include "wx/dialog.h"
41 #include "wx/msgdlg.h"
42 #include "wx/intl.h"
43 #include "wx/crt.h"
44 #include "wx/log.h"
45 #include "wx/module.h"
46#endif
47
48#include "wx/apptrait.h"
49#include "wx/filename.h"
50#include "wx/dynlib.h"
51#include "wx/evtloop.h"
52
53#include "wx/msw/private.h"
54#include "wx/msw/ole/oleutils.h"
55#include "wx/msw/private/timer.h"
56
57#if wxUSE_TOOLTIPS
58 #include "wx/tooltip.h"
59#endif // wxUSE_TOOLTIPS
60
61// OLE is used for drag-and-drop, clipboard, OLE Automation..., but some
62// compilers don't support it (missing headers, libs, ...)
63#if defined(__GNUWIN32_OLD__) || defined(__SYMANTEC__) || defined(__SALFORDC__)
64 #undef wxUSE_OLE
65
66 #define wxUSE_OLE 0
67#endif // broken compilers
68
69#if defined(__POCKETPC__) || defined(__SMARTPHONE__)
70 #include <ole2.h>
71 #include <aygshell.h>
72#endif
73
74#if wxUSE_OLE
75 #include <ole2.h>
76#endif
77
78#include <string.h>
79#include <ctype.h>
80
81#include "wx/msw/missing.h"
82
83// instead of including <shlwapi.h> which is not part of the core SDK and not
84// shipped at all with other compilers, we always define the parts of it we
85// need here ourselves
86//
87// NB: DLLVER_PLATFORM_WINDOWS will be defined if shlwapi.h had been somehow
88// included already
89#ifndef DLLVER_PLATFORM_WINDOWS
90 // hopefully we don't need to change packing as DWORDs should be already
91 // correctly aligned
92 struct DLLVERSIONINFO
93 {
94 DWORD cbSize;
95 DWORD dwMajorVersion; // Major version
96 DWORD dwMinorVersion; // Minor version
97 DWORD dwBuildNumber; // Build number
98 DWORD dwPlatformID; // DLLVER_PLATFORM_*
99 };
100
101 typedef HRESULT (CALLBACK* DLLGETVERSIONPROC)(DLLVERSIONINFO *);
102#endif // defined(DLLVERSIONINFO)
103
104
105// ---------------------------------------------------------------------------
106// global variables
107// ---------------------------------------------------------------------------
108
109#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
110extern void wxSetKeyboardHook(bool doIt);
111#endif
112
113// NB: all "NoRedraw" classes must have the same names as the "normal" classes
114// with NR suffix - wxWindow::MSWCreate() supposes this
115#ifdef __WXWINCE__
116WXDLLIMPEXP_CORE wxChar *wxCanvasClassName;
117WXDLLIMPEXP_CORE wxChar *wxCanvasClassNameNR;
118#else
119WXDLLIMPEXP_CORE const wxChar *wxCanvasClassName = wxT("wxWindowClass");
120WXDLLIMPEXP_CORE const wxChar *wxCanvasClassNameNR = wxT("wxWindowClassNR");
121#endif
122WXDLLIMPEXP_CORE const wxChar *wxMDIFrameClassName = wxT("wxMDIFrameClass");
123WXDLLIMPEXP_CORE const wxChar *wxMDIFrameClassNameNoRedraw = wxT("wxMDIFrameClassNR");
124WXDLLIMPEXP_CORE const wxChar *wxMDIChildFrameClassName = wxT("wxMDIChildFrameClass");
125WXDLLIMPEXP_CORE const wxChar *wxMDIChildFrameClassNameNoRedraw = wxT("wxMDIChildFrameClassNR");
126
127// ----------------------------------------------------------------------------
128// private functions
129// ----------------------------------------------------------------------------
130
131LRESULT WXDLLEXPORT APIENTRY wxWndProc(HWND, UINT, WPARAM, LPARAM);
132
133// ===========================================================================
134// wxGUIAppTraits implementation
135// ===========================================================================
136
137// private class which we use to pass parameters from BeforeChildWaitLoop() to
138// AfterChildWaitLoop()
139struct ChildWaitLoopData
140{
141 ChildWaitLoopData(wxWindowDisabler *wd_, wxWindow *winActive_)
142 {
143 wd = wd_;
144 winActive = winActive_;
145 }
146
147 wxWindowDisabler *wd;
148 wxWindow *winActive;
149};
150
151void *wxGUIAppTraits::BeforeChildWaitLoop()
152{
153 /*
154 We use a dirty hack here to disable all application windows (which we
155 must do because otherwise the calls to wxYield() could lead to some very
156 unexpected reentrancies in the users code) but to avoid losing
157 focus/activation entirely when the child process terminates which would
158 happen if we simply disabled everything using wxWindowDisabler. Indeed,
159 remember that Windows will never activate a disabled window and when the
160 last childs window is closed and Windows looks for a window to activate
161 all our windows are still disabled. There is no way to enable them in
162 time because we don't know when the childs windows are going to be
163 closed, so the solution we use here is to keep one special tiny frame
164 enabled all the time. Then when the child terminates it will get
165 activated and when we close it below -- after reenabling all the other
166 windows! -- the previously active window becomes activated again and
167 everything is ok.
168 */
169 wxBeginBusyCursor();
170
171 // first disable all existing windows
172 wxWindowDisabler *wd = new wxWindowDisabler;
173
174 // then create an "invisible" frame: it has minimal size, is positioned
175 // (hopefully) outside the screen and doesn't appear on the taskbar
176 wxWindow *winActive = new wxFrame
177 (
178 wxTheApp->GetTopWindow(),
179 wxID_ANY,
180 wxEmptyString,
181 wxPoint(32600, 32600),
182 wxSize(1, 1),
183 wxDEFAULT_FRAME_STYLE | wxFRAME_NO_TASKBAR
184 );
185 winActive->Show();
186
187 return new ChildWaitLoopData(wd, winActive);
188}
189
190void wxGUIAppTraits::AlwaysYield()
191{
192 wxYield();
193}
194
195void wxGUIAppTraits::AfterChildWaitLoop(void *dataOrig)
196{
197 wxEndBusyCursor();
198
199 ChildWaitLoopData * const data = (ChildWaitLoopData *)dataOrig;
200
201 delete data->wd;
202
203 // finally delete the dummy frame and, as wd has been already destroyed and
204 // the other windows reenabled, the activation is going to return to the
205 // window which had had it before
206 data->winActive->Destroy();
207
208 // also delete the temporary data object itself
209 delete data;
210}
211
212bool wxGUIAppTraits::DoMessageFromThreadWait()
213{
214 // we should return false only if the app should exit, i.e. only if
215 // Dispatch() determines that the main event loop should terminate
216 wxEventLoopBase * const evtLoop = wxEventLoop::GetActive();
217 if ( !evtLoop || !evtLoop->Pending() )
218 {
219 // no events means no quit event
220 return true;
221 }
222
223 return evtLoop->Dispatch();
224}
225
226DWORD wxGUIAppTraits::WaitForThread(WXHANDLE hThread)
227{
228 // if we don't have a running event loop, we shouldn't wait for the
229 // messages as we never remove them from the message queue and so we enter
230 // an infinite loop as MsgWaitForMultipleObjects() keeps returning
231 // WAIT_OBJECT_0 + 1
232 if ( !wxEventLoop::GetActive() )
233 return DoSimpleWaitForThread(hThread);
234
235 return ::MsgWaitForMultipleObjects
236 (
237 1, // number of objects to wait for
238 (HANDLE *)&hThread, // the objects
239 false, // wait for any objects, not all
240 INFINITE, // no timeout
241 QS_ALLINPUT | // return as soon as there are any events
242 QS_ALLPOSTMESSAGE
243 );
244}
245
246wxPortId wxGUIAppTraits::GetToolkitVersion(int *majVer, int *minVer) const
247{
248 OSVERSIONINFO info;
249 wxZeroMemory(info);
250
251 // on Windows, the toolkit version is the same of the OS version
252 // as Windows integrates the OS kernel with the GUI toolkit.
253 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
254 if ( ::GetVersionEx(&info) )
255 {
256 if ( majVer )
257 *majVer = info.dwMajorVersion;
258 if ( minVer )
259 *minVer = info.dwMinorVersion;
260 }
261
262#if defined(__WXHANDHELD__) || defined(__WXWINCE__)
263 return wxPORT_WINCE;
264#else
265 return wxPORT_MSW;
266#endif
267}
268
269wxTimerImpl *wxGUIAppTraits::CreateTimerImpl(wxTimer *timer)
270{
271 return new wxMSWTimerImpl(timer);
272}
273
274wxEventLoopBase* wxGUIAppTraits::CreateEventLoop()
275{
276 return new wxEventLoop;
277}
278
279// ===========================================================================
280// wxApp implementation
281// ===========================================================================
282
283int wxApp::m_nCmdShow = SW_SHOWNORMAL;
284
285// ---------------------------------------------------------------------------
286// wxWin macros
287// ---------------------------------------------------------------------------
288
289IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
290
291BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
292 EVT_IDLE(wxApp::OnIdle)
293 EVT_END_SESSION(wxApp::OnEndSession)
294 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession)
295END_EVENT_TABLE()
296
297// class to ensure that wxAppBase::CleanUp() is called if our Initialize()
298// fails
299class wxCallBaseCleanup
300{
301public:
302 wxCallBaseCleanup(wxApp *app) : m_app(app) { }
303 ~wxCallBaseCleanup() { if ( m_app ) m_app->wxAppBase::CleanUp(); }
304
305 void Dismiss() { m_app = NULL; }
306
307private:
308 wxApp *m_app;
309};
310
311//// Initialize
312bool wxApp::Initialize(int& argc, wxChar **argv)
313{
314 if ( !wxAppBase::Initialize(argc, argv) )
315 return false;
316
317 // ensure that base cleanup is done if we return too early
318 wxCallBaseCleanup callBaseCleanup(this);
319
320#ifdef __WXWINCE__
321 wxString tmp = GetAppName();
322 tmp += wxT("ClassName");
323 wxCanvasClassName = wxStrdup( tmp.c_str() );
324 tmp += wxT("NR");
325 wxCanvasClassNameNR = wxStrdup( tmp.c_str() );
326 HWND hWnd = FindWindow( wxCanvasClassNameNR, NULL );
327 if (hWnd)
328 {
329 SetForegroundWindow( (HWND)(((DWORD)hWnd)|0x01) );
330 return false;
331 }
332#endif
333
334#if !defined(__WXMICROWIN__)
335 InitCommonControls();
336#endif // !defined(__WXMICROWIN__)
337
338#if defined(__SMARTPHONE__) || defined(__POCKETPC__)
339 SHInitExtraControls();
340#endif
341
342#ifndef __WXWINCE__
343 // Don't show a message box if a function such as SHGetFileInfo
344 // fails to find a device.
345 SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX);
346#endif
347
348 wxOleInitialize();
349
350 RegisterWindowClasses();
351
352 wxWinHandleHash = new wxWinHashTable(wxKEY_INTEGER, 100);
353
354#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
355 wxSetKeyboardHook(true);
356#endif
357
358 callBaseCleanup.Dismiss();
359
360 return true;
361}
362
363// ---------------------------------------------------------------------------
364// RegisterWindowClasses
365// ---------------------------------------------------------------------------
366
367// TODO we should only register classes really used by the app. For this it
368// would be enough to just delay the class registration until an attempt
369// to create a window of this class is made.
370bool wxApp::RegisterWindowClasses()
371{
372 WNDCLASS wndclass;
373 wxZeroMemory(wndclass);
374
375 // for each class we register one with CS_(V|H)REDRAW style and one
376 // without for windows created with wxNO_FULL_REDRAW_ON_REPAINT flag
377 static const long styleNormal = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
378 static const long styleNoRedraw = CS_DBLCLKS;
379
380 // the fields which are common to all classes
381 wndclass.lpfnWndProc = (WNDPROC)wxWndProc;
382 wndclass.hInstance = wxhInstance;
383 wndclass.hCursor = ::LoadCursor((HINSTANCE)NULL, IDC_ARROW);
384
385 // register the class for all normal windows
386 wndclass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
387 wndclass.lpszClassName = wxCanvasClassName;
388 wndclass.style = styleNormal;
389
390 if ( !RegisterClass(&wndclass) )
391 {
392 wxLogLastError(wxT("RegisterClass(frame)"));
393 }
394
395 // "no redraw" frame
396 wndclass.lpszClassName = wxCanvasClassNameNR;
397 wndclass.style = styleNoRedraw;
398
399 if ( !RegisterClass(&wndclass) )
400 {
401 wxLogLastError(wxT("RegisterClass(no redraw frame)"));
402 }
403
404 // Register the MDI frame window class.
405 wndclass.hbrBackground = (HBRUSH)NULL; // paint MDI frame ourselves
406 wndclass.lpszClassName = wxMDIFrameClassName;
407 wndclass.style = styleNormal;
408
409 if ( !RegisterClass(&wndclass) )
410 {
411 wxLogLastError(wxT("RegisterClass(MDI parent)"));
412 }
413
414 // "no redraw" MDI frame
415 wndclass.lpszClassName = wxMDIFrameClassNameNoRedraw;
416 wndclass.style = styleNoRedraw;
417
418 if ( !RegisterClass(&wndclass) )
419 {
420 wxLogLastError(wxT("RegisterClass(no redraw MDI parent frame)"));
421 }
422
423 // Register the MDI child frame window class.
424 wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
425 wndclass.lpszClassName = wxMDIChildFrameClassName;
426 wndclass.style = styleNormal;
427
428 if ( !RegisterClass(&wndclass) )
429 {
430 wxLogLastError(wxT("RegisterClass(MDI child)"));
431 }
432
433 // "no redraw" MDI child frame
434 wndclass.lpszClassName = wxMDIChildFrameClassNameNoRedraw;
435 wndclass.style = styleNoRedraw;
436
437 if ( !RegisterClass(&wndclass) )
438 {
439 wxLogLastError(wxT("RegisterClass(no redraw MDI child)"));
440 }
441
442 return true;
443}
444
445// ---------------------------------------------------------------------------
446// UnregisterWindowClasses
447// ---------------------------------------------------------------------------
448
449bool wxApp::UnregisterWindowClasses()
450{
451 bool retval = true;
452
453#ifndef __WXMICROWIN__
454 // MDI frame window class.
455 if ( !::UnregisterClass(wxMDIFrameClassName, wxhInstance) )
456 {
457 wxLogLastError(wxT("UnregisterClass(MDI parent)"));
458
459 retval = false;
460 }
461
462 // "no redraw" MDI frame
463 if ( !::UnregisterClass(wxMDIFrameClassNameNoRedraw, wxhInstance) )
464 {
465 wxLogLastError(wxT("UnregisterClass(no redraw MDI parent frame)"));
466
467 retval = false;
468 }
469
470 // MDI child frame window class.
471 if ( !::UnregisterClass(wxMDIChildFrameClassName, wxhInstance) )
472 {
473 wxLogLastError(wxT("UnregisterClass(MDI child)"));
474
475 retval = false;
476 }
477
478 // "no redraw" MDI child frame
479 if ( !::UnregisterClass(wxMDIChildFrameClassNameNoRedraw, wxhInstance) )
480 {
481 wxLogLastError(wxT("UnregisterClass(no redraw MDI child)"));
482
483 retval = false;
484 }
485
486 // canvas class name
487 if ( !::UnregisterClass(wxCanvasClassName, wxhInstance) )
488 {
489 wxLogLastError(wxT("UnregisterClass(canvas)"));
490
491 retval = false;
492 }
493
494 if ( !::UnregisterClass(wxCanvasClassNameNR, wxhInstance) )
495 {
496 wxLogLastError(wxT("UnregisterClass(no redraw canvas)"));
497
498 retval = false;
499 }
500#endif // __WXMICROWIN__
501
502 return retval;
503}
504
505void wxApp::CleanUp()
506{
507 // all objects pending for deletion must be deleted first, otherwise we
508 // would crash when they use wxWinHandleHash (and UnregisterWindowClasses()
509 // call wouldn't succeed as long as any windows still exist), so call the
510 // base class method first and only then do our clean up
511 wxAppBase::CleanUp();
512
513#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
514 wxSetKeyboardHook(false);
515#endif
516
517 wxOleUninitialize();
518
519 // for an EXE the classes are unregistered when it terminates but DLL may
520 // be loaded several times (load/unload/load) into the same process in
521 // which case the registration will fail after the first time if we don't
522 // unregister the classes now
523 UnregisterWindowClasses();
524
525 delete wxWinHandleHash;
526 wxWinHandleHash = NULL;
527
528#ifdef __WXWINCE__
529 free( wxCanvasClassName );
530 free( wxCanvasClassNameNR );
531#endif
532}
533
534// ----------------------------------------------------------------------------
535// wxApp ctor/dtor
536// ----------------------------------------------------------------------------
537
538wxApp::wxApp()
539{
540 m_printMode = wxPRINT_WINDOWS;
541}
542
543wxApp::~wxApp()
544{
545}
546
547// ----------------------------------------------------------------------------
548// wxApp idle handling
549// ----------------------------------------------------------------------------
550
551void wxApp::OnIdle(wxIdleEvent& WXUNUSED(event))
552{
553#if wxUSE_DC_CACHEING
554 // automated DC cache management: clear the cached DCs and bitmap
555 // if it's likely that the app has finished with them, that is, we
556 // get an idle event and we're not dragging anything.
557 if (!::GetKeyState(MK_LBUTTON) && !::GetKeyState(MK_MBUTTON) && !::GetKeyState(MK_RBUTTON))
558 wxDC::ClearCache();
559#endif // wxUSE_DC_CACHEING
560}
561
562void wxApp::WakeUpIdle()
563{
564 // Send the top window a dummy message so idle handler processing will
565 // start up again. Doing it this way ensures that the idle handler
566 // wakes up in the right thread (see also wxWakeUpMainThread() which does
567 // the same for the main app thread only)
568 wxWindow *topWindow = wxTheApp->GetTopWindow();
569 if ( topWindow )
570 {
571 if ( !::PostMessage(GetHwndOf(topWindow), WM_NULL, 0, 0) )
572 {
573 // should never happen
574 wxLogLastError(wxT("PostMessage(WM_NULL)"));
575 }
576 }
577}
578
579// ----------------------------------------------------------------------------
580// other wxApp event hanlders
581// ----------------------------------------------------------------------------
582
583void wxApp::OnEndSession(wxCloseEvent& WXUNUSED(event))
584{
585 if (GetTopWindow())
586 GetTopWindow()->Close(true);
587}
588
589// Default behaviour: close the application with prompts. The
590// user can veto the close, and therefore the end session.
591void wxApp::OnQueryEndSession(wxCloseEvent& event)
592{
593 if (GetTopWindow())
594 {
595 if (!GetTopWindow()->Close(!event.CanVeto()))
596 event.Veto(true);
597 }
598}
599
600// ----------------------------------------------------------------------------
601// miscellaneous
602// ----------------------------------------------------------------------------
603
604/* static */
605int wxApp::GetComCtl32Version()
606{
607#if defined(__WXMICROWIN__) || defined(__WXWINCE__)
608 return 0;
609#else
610 // cache the result
611 //
612 // NB: this is MT-ok as in the worst case we'd compute s_verComCtl32 twice,
613 // but as its value should be the same both times it doesn't matter
614 static int s_verComCtl32 = -1;
615
616 if ( s_verComCtl32 == -1 )
617 {
618 // initally assume no comctl32.dll at all
619 s_verComCtl32 = 0;
620
621 // we're prepared to handle the errors
622 wxLogNull noLog;
623
624#if wxUSE_DYNLIB_CLASS
625 // do we have it?
626 wxDynamicLibrary dllComCtl32(_T("comctl32.dll"), wxDL_VERBATIM);
627
628 // if so, then we can check for the version
629 if ( dllComCtl32.IsLoaded() )
630 {
631 // now check if the function is available during run-time
632 wxDYNLIB_FUNCTION( DLLGETVERSIONPROC, DllGetVersion, dllComCtl32 );
633 if ( pfnDllGetVersion )
634 {
635 DLLVERSIONINFO dvi;
636 dvi.cbSize = sizeof(dvi);
637
638 HRESULT hr = (*pfnDllGetVersion)(&dvi);
639 if ( FAILED(hr) )
640 {
641 wxLogApiError(_T("DllGetVersion"), hr);
642 }
643 else
644 {
645 // this is incompatible with _WIN32_IE values, but
646 // compatible with the other values returned by
647 // GetComCtl32Version()
648 s_verComCtl32 = 100*dvi.dwMajorVersion +
649 dvi.dwMinorVersion;
650 }
651 }
652
653 // if DllGetVersion() is unavailable either during compile or
654 // run-time, try to guess the version otherwise
655 if ( !s_verComCtl32 )
656 {
657 // InitCommonControlsEx is unique to 4.70 and later
658 void *pfn = dllComCtl32.GetSymbol(_T("InitCommonControlsEx"));
659 if ( !pfn )
660 {
661 // not found, must be 4.00
662 s_verComCtl32 = 400;
663 }
664 else // 4.70+
665 {
666 // many symbols appeared in comctl32 4.71, could use any of
667 // them except may be DllInstall()
668 pfn = dllComCtl32.GetSymbol(_T("InitializeFlatSB"));
669 if ( !pfn )
670 {
671 // not found, must be 4.70
672 s_verComCtl32 = 470;
673 }
674 else
675 {
676 // found, must be 4.71 or later
677 s_verComCtl32 = 471;
678 }
679 }
680 }
681 }
682#endif
683 }
684
685 return s_verComCtl32;
686#endif // Microwin/!Microwin
687}
688
689// Yield to incoming messages
690
691bool wxApp::Yield(bool onlyIfNeeded)
692{
693 // MT-FIXME
694 static bool s_inYield = false;
695
696#if wxUSE_LOG
697 // disable log flushing from here because a call to wxYield() shouldn't
698 // normally result in message boxes popping up &c
699 wxLog::Suspend();
700#endif // wxUSE_LOG
701
702 if ( s_inYield )
703 {
704 if ( !onlyIfNeeded )
705 {
706 wxFAIL_MSG( wxT("wxYield called recursively" ) );
707 }
708
709 return false;
710 }
711
712 s_inYield = true;
713
714 // we don't want to process WM_QUIT from here - it should be processed in
715 // the main event loop in order to stop it
716 MSG msg;
717 while ( PeekMessage(&msg, (HWND)0, 0, 0, PM_NOREMOVE) &&
718 msg.message != WM_QUIT )
719 {
720#if wxUSE_THREADS
721 wxMutexGuiLeaveOrEnter();
722#endif // wxUSE_THREADS
723
724 if ( !wxTheApp->Dispatch() )
725 break;
726 }
727
728 // if there are pending events, we must process them.
729 ProcessPendingEvents();
730
731#if wxUSE_LOG
732 // let the logs be flashed again
733 wxLog::Resume();
734#endif // wxUSE_LOG
735
736 s_inYield = false;
737
738 return true;
739}
740
741#if wxUSE_EXCEPTIONS
742
743// ----------------------------------------------------------------------------
744// exception handling
745// ----------------------------------------------------------------------------
746
747bool wxApp::OnExceptionInMainLoop()
748{
749 // ask the user about what to do: use the Win32 API function here as it
750 // could be dangerous to use any wxWidgets code in this state
751 switch (
752 ::MessageBox
753 (
754 NULL,
755 _T("An unhandled exception occurred. Press \"Abort\" to \
756terminate the program,\r\n\
757\"Retry\" to exit the program normally and \"Ignore\" to try to continue."),
758 _T("Unhandled exception"),
759 MB_ABORTRETRYIGNORE |
760 MB_ICONERROR|
761 MB_TASKMODAL
762 )
763 )
764 {
765 case IDABORT:
766 throw;
767
768 default:
769 wxFAIL_MSG( _T("unexpected MessageBox() return code") );
770 // fall through
771
772 case IDRETRY:
773 return false;
774
775 case IDIGNORE:
776 return true;
777 }
778}
779
780#endif // wxUSE_EXCEPTIONS