removed extraneous semicolons
[wxWidgets.git] / src / msw / app.cpp
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/wxchar.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__)
110 extern 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__
116 WXDLLIMPEXP_CORE wxChar *wxCanvasClassName;
117 WXDLLIMPEXP_CORE wxChar *wxCanvasClassNameNR;
118 #else
119 WXDLLIMPEXP_CORE const wxChar *wxCanvasClassName = wxT("wxWindowClass");
120 WXDLLIMPEXP_CORE const wxChar *wxCanvasClassNameNR = wxT("wxWindowClassNR");
121 #endif
122 WXDLLIMPEXP_CORE const wxChar *wxMDIFrameClassName = wxT("wxMDIFrameClass");
123 WXDLLIMPEXP_CORE const wxChar *wxMDIFrameClassNameNoRedraw = wxT("wxMDIFrameClassNR");
124 WXDLLIMPEXP_CORE const wxChar *wxMDIChildFrameClassName = wxT("wxMDIChildFrameClass");
125 WXDLLIMPEXP_CORE const wxChar *wxMDIChildFrameClassNameNoRedraw = wxT("wxMDIChildFrameClassNR");
126
127 // ----------------------------------------------------------------------------
128 // private functions
129 // ----------------------------------------------------------------------------
130
131 LRESULT 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()
139 struct 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
151 void *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
190 void wxGUIAppTraits::AlwaysYield()
191 {
192 wxYield();
193 }
194
195 void 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
212 bool 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 wxEventLoop *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
226 DWORD 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
246 wxPortId 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
269 wxTimerImpl *
270 wxGUIAppTraits::CreateTimerImpl(wxTimer *timer)
271 {
272 return new wxMSWTimerImpl(timer);
273 }
274
275 // ===========================================================================
276 // wxApp implementation
277 // ===========================================================================
278
279 int wxApp::m_nCmdShow = SW_SHOWNORMAL;
280
281 // ---------------------------------------------------------------------------
282 // wxWin macros
283 // ---------------------------------------------------------------------------
284
285 IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
286
287 BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
288 EVT_IDLE(wxApp::OnIdle)
289 EVT_END_SESSION(wxApp::OnEndSession)
290 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession)
291 END_EVENT_TABLE()
292
293 // class to ensure that wxAppBase::CleanUp() is called if our Initialize()
294 // fails
295 class wxCallBaseCleanup
296 {
297 public:
298 wxCallBaseCleanup(wxApp *app) : m_app(app) { }
299 ~wxCallBaseCleanup() { if ( m_app ) m_app->wxAppBase::CleanUp(); }
300
301 void Dismiss() { m_app = NULL; }
302
303 private:
304 wxApp *m_app;
305 };
306
307 //// Initialize
308 bool wxApp::Initialize(int& argc, wxChar **argv)
309 {
310 if ( !wxAppBase::Initialize(argc, argv) )
311 return false;
312
313 // ensure that base cleanup is done if we return too early
314 wxCallBaseCleanup callBaseCleanup(this);
315
316 #ifdef __WXWINCE__
317 wxString tmp = GetAppName();
318 tmp += wxT("ClassName");
319 wxCanvasClassName = wxStrdup( tmp.c_str() );
320 tmp += wxT("NR");
321 wxCanvasClassNameNR = wxStrdup( tmp.c_str() );
322 HWND hWnd = FindWindow( wxCanvasClassNameNR, NULL );
323 if (hWnd)
324 {
325 SetForegroundWindow( (HWND)(((DWORD)hWnd)|0x01) );
326 return false;
327 }
328 #endif
329
330 #if !defined(__WXMICROWIN__)
331 InitCommonControls();
332 #endif // !defined(__WXMICROWIN__)
333
334 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
335 SHInitExtraControls();
336 #endif
337
338 #ifndef __WXWINCE__
339 // Don't show a message box if a function such as SHGetFileInfo
340 // fails to find a device.
341 SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX);
342 #endif
343
344 wxOleInitialize();
345
346 RegisterWindowClasses();
347
348 wxWinHandleHash = new wxWinHashTable(wxKEY_INTEGER, 100);
349
350 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
351 wxSetKeyboardHook(true);
352 #endif
353
354 callBaseCleanup.Dismiss();
355
356 return true;
357 }
358
359 // ---------------------------------------------------------------------------
360 // RegisterWindowClasses
361 // ---------------------------------------------------------------------------
362
363 // TODO we should only register classes really used by the app. For this it
364 // would be enough to just delay the class registration until an attempt
365 // to create a window of this class is made.
366 bool wxApp::RegisterWindowClasses()
367 {
368 WNDCLASS wndclass;
369 wxZeroMemory(wndclass);
370
371 // for each class we register one with CS_(V|H)REDRAW style and one
372 // without for windows created with wxNO_FULL_REDRAW_ON_REPAINT flag
373 static const long styleNormal = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
374 static const long styleNoRedraw = CS_DBLCLKS;
375
376 // the fields which are common to all classes
377 wndclass.lpfnWndProc = (WNDPROC)wxWndProc;
378 wndclass.hInstance = wxhInstance;
379 wndclass.hCursor = ::LoadCursor((HINSTANCE)NULL, IDC_ARROW);
380
381 // register the class for all normal windows
382 wndclass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
383 wndclass.lpszClassName = wxCanvasClassName;
384 wndclass.style = styleNormal;
385
386 if ( !RegisterClass(&wndclass) )
387 {
388 wxLogLastError(wxT("RegisterClass(frame)"));
389 }
390
391 // "no redraw" frame
392 wndclass.lpszClassName = wxCanvasClassNameNR;
393 wndclass.style = styleNoRedraw;
394
395 if ( !RegisterClass(&wndclass) )
396 {
397 wxLogLastError(wxT("RegisterClass(no redraw frame)"));
398 }
399
400 // Register the MDI frame window class.
401 wndclass.hbrBackground = (HBRUSH)NULL; // paint MDI frame ourselves
402 wndclass.lpszClassName = wxMDIFrameClassName;
403 wndclass.style = styleNormal;
404
405 if ( !RegisterClass(&wndclass) )
406 {
407 wxLogLastError(wxT("RegisterClass(MDI parent)"));
408 }
409
410 // "no redraw" MDI frame
411 wndclass.lpszClassName = wxMDIFrameClassNameNoRedraw;
412 wndclass.style = styleNoRedraw;
413
414 if ( !RegisterClass(&wndclass) )
415 {
416 wxLogLastError(wxT("RegisterClass(no redraw MDI parent frame)"));
417 }
418
419 // Register the MDI child frame window class.
420 wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
421 wndclass.lpszClassName = wxMDIChildFrameClassName;
422 wndclass.style = styleNormal;
423
424 if ( !RegisterClass(&wndclass) )
425 {
426 wxLogLastError(wxT("RegisterClass(MDI child)"));
427 }
428
429 // "no redraw" MDI child frame
430 wndclass.lpszClassName = wxMDIChildFrameClassNameNoRedraw;
431 wndclass.style = styleNoRedraw;
432
433 if ( !RegisterClass(&wndclass) )
434 {
435 wxLogLastError(wxT("RegisterClass(no redraw MDI child)"));
436 }
437
438 return true;
439 }
440
441 // ---------------------------------------------------------------------------
442 // UnregisterWindowClasses
443 // ---------------------------------------------------------------------------
444
445 bool wxApp::UnregisterWindowClasses()
446 {
447 bool retval = true;
448
449 #ifndef __WXMICROWIN__
450 // MDI frame window class.
451 if ( !::UnregisterClass(wxMDIFrameClassName, wxhInstance) )
452 {
453 wxLogLastError(wxT("UnregisterClass(MDI parent)"));
454
455 retval = false;
456 }
457
458 // "no redraw" MDI frame
459 if ( !::UnregisterClass(wxMDIFrameClassNameNoRedraw, wxhInstance) )
460 {
461 wxLogLastError(wxT("UnregisterClass(no redraw MDI parent frame)"));
462
463 retval = false;
464 }
465
466 // MDI child frame window class.
467 if ( !::UnregisterClass(wxMDIChildFrameClassName, wxhInstance) )
468 {
469 wxLogLastError(wxT("UnregisterClass(MDI child)"));
470
471 retval = false;
472 }
473
474 // "no redraw" MDI child frame
475 if ( !::UnregisterClass(wxMDIChildFrameClassNameNoRedraw, wxhInstance) )
476 {
477 wxLogLastError(wxT("UnregisterClass(no redraw MDI child)"));
478
479 retval = false;
480 }
481
482 // canvas class name
483 if ( !::UnregisterClass(wxCanvasClassName, wxhInstance) )
484 {
485 wxLogLastError(wxT("UnregisterClass(canvas)"));
486
487 retval = false;
488 }
489
490 if ( !::UnregisterClass(wxCanvasClassNameNR, wxhInstance) )
491 {
492 wxLogLastError(wxT("UnregisterClass(no redraw canvas)"));
493
494 retval = false;
495 }
496 #endif // __WXMICROWIN__
497
498 return retval;
499 }
500
501 void wxApp::CleanUp()
502 {
503 // all objects pending for deletion must be deleted first, otherwise we
504 // would crash when they use wxWinHandleHash (and UnregisterWindowClasses()
505 // call wouldn't succeed as long as any windows still exist), so call the
506 // base class method first and only then do our clean up
507 wxAppBase::CleanUp();
508
509 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
510 wxSetKeyboardHook(false);
511 #endif
512
513 wxOleUninitialize();
514
515 // for an EXE the classes are unregistered when it terminates but DLL may
516 // be loaded several times (load/unload/load) into the same process in
517 // which case the registration will fail after the first time if we don't
518 // unregister the classes now
519 UnregisterWindowClasses();
520
521 delete wxWinHandleHash;
522 wxWinHandleHash = NULL;
523
524 #ifdef __WXWINCE__
525 free( wxCanvasClassName );
526 free( wxCanvasClassNameNR );
527 #endif
528 }
529
530 // ----------------------------------------------------------------------------
531 // wxApp ctor/dtor
532 // ----------------------------------------------------------------------------
533
534 wxApp::wxApp()
535 {
536 m_printMode = wxPRINT_WINDOWS;
537 }
538
539 wxApp::~wxApp()
540 {
541 }
542
543 // ----------------------------------------------------------------------------
544 // wxApp idle handling
545 // ----------------------------------------------------------------------------
546
547 void wxApp::OnIdle(wxIdleEvent& event)
548 {
549 wxAppBase::OnIdle(event);
550
551 #if wxUSE_DC_CACHEING
552 // automated DC cache management: clear the cached DCs and bitmap
553 // if it's likely that the app has finished with them, that is, we
554 // get an idle event and we're not dragging anything.
555 if (!::GetKeyState(MK_LBUTTON) && !::GetKeyState(MK_MBUTTON) && !::GetKeyState(MK_RBUTTON))
556 wxDC::ClearCache();
557 #endif // wxUSE_DC_CACHEING
558 }
559
560 void wxApp::WakeUpIdle()
561 {
562 // Send the top window a dummy message so idle handler processing will
563 // start up again. Doing it this way ensures that the idle handler
564 // wakes up in the right thread (see also wxWakeUpMainThread() which does
565 // the same for the main app thread only)
566 wxWindow *topWindow = wxTheApp->GetTopWindow();
567 if ( topWindow )
568 {
569 if ( !::PostMessage(GetHwndOf(topWindow), WM_NULL, 0, 0) )
570 {
571 // should never happen
572 wxLogLastError(wxT("PostMessage(WM_NULL)"));
573 }
574 }
575 }
576
577 // ----------------------------------------------------------------------------
578 // other wxApp event hanlders
579 // ----------------------------------------------------------------------------
580
581 void wxApp::OnEndSession(wxCloseEvent& WXUNUSED(event))
582 {
583 if (GetTopWindow())
584 GetTopWindow()->Close(true);
585 }
586
587 // Default behaviour: close the application with prompts. The
588 // user can veto the close, and therefore the end session.
589 void wxApp::OnQueryEndSession(wxCloseEvent& event)
590 {
591 if (GetTopWindow())
592 {
593 if (!GetTopWindow()->Close(!event.CanVeto()))
594 event.Veto(true);
595 }
596 }
597
598 // ----------------------------------------------------------------------------
599 // miscellaneous
600 // ----------------------------------------------------------------------------
601
602 /* static */
603 int wxApp::GetComCtl32Version()
604 {
605 #if defined(__WXMICROWIN__) || defined(__WXWINCE__)
606 return 0;
607 #else
608 // cache the result
609 //
610 // NB: this is MT-ok as in the worst case we'd compute s_verComCtl32 twice,
611 // but as its value should be the same both times it doesn't matter
612 static int s_verComCtl32 = -1;
613
614 if ( s_verComCtl32 == -1 )
615 {
616 // initally assume no comctl32.dll at all
617 s_verComCtl32 = 0;
618
619 // we're prepared to handle the errors
620 wxLogNull noLog;
621
622 #if wxUSE_DYNLIB_CLASS
623 // do we have it?
624 wxDynamicLibrary dllComCtl32(_T("comctl32.dll"), wxDL_VERBATIM);
625
626 // if so, then we can check for the version
627 if ( dllComCtl32.IsLoaded() )
628 {
629 // now check if the function is available during run-time
630 wxDYNLIB_FUNCTION( DLLGETVERSIONPROC, DllGetVersion, dllComCtl32 );
631 if ( pfnDllGetVersion )
632 {
633 DLLVERSIONINFO dvi;
634 dvi.cbSize = sizeof(dvi);
635
636 HRESULT hr = (*pfnDllGetVersion)(&dvi);
637 if ( FAILED(hr) )
638 {
639 wxLogApiError(_T("DllGetVersion"), hr);
640 }
641 else
642 {
643 // this is incompatible with _WIN32_IE values, but
644 // compatible with the other values returned by
645 // GetComCtl32Version()
646 s_verComCtl32 = 100*dvi.dwMajorVersion +
647 dvi.dwMinorVersion;
648 }
649 }
650
651 // if DllGetVersion() is unavailable either during compile or
652 // run-time, try to guess the version otherwise
653 if ( !s_verComCtl32 )
654 {
655 // InitCommonControlsEx is unique to 4.70 and later
656 void *pfn = dllComCtl32.GetSymbol(_T("InitCommonControlsEx"));
657 if ( !pfn )
658 {
659 // not found, must be 4.00
660 s_verComCtl32 = 400;
661 }
662 else // 4.70+
663 {
664 // many symbols appeared in comctl32 4.71, could use any of
665 // them except may be DllInstall()
666 pfn = dllComCtl32.GetSymbol(_T("InitializeFlatSB"));
667 if ( !pfn )
668 {
669 // not found, must be 4.70
670 s_verComCtl32 = 470;
671 }
672 else
673 {
674 // found, must be 4.71 or later
675 s_verComCtl32 = 471;
676 }
677 }
678 }
679 }
680 #endif
681 }
682
683 return s_verComCtl32;
684 #endif // Microwin/!Microwin
685 }
686
687 // Yield to incoming messages
688
689 bool wxApp::Yield(bool onlyIfNeeded)
690 {
691 // MT-FIXME
692 static bool s_inYield = false;
693
694 #if wxUSE_LOG
695 // disable log flushing from here because a call to wxYield() shouldn't
696 // normally result in message boxes popping up &c
697 wxLog::Suspend();
698 #endif // wxUSE_LOG
699
700 if ( s_inYield )
701 {
702 if ( !onlyIfNeeded )
703 {
704 wxFAIL_MSG( wxT("wxYield called recursively" ) );
705 }
706
707 return false;
708 }
709
710 s_inYield = true;
711
712 // we don't want to process WM_QUIT from here - it should be processed in
713 // the main event loop in order to stop it
714 MSG msg;
715 while ( PeekMessage(&msg, (HWND)0, 0, 0, PM_NOREMOVE) &&
716 msg.message != WM_QUIT )
717 {
718 #if wxUSE_THREADS
719 wxMutexGuiLeaveOrEnter();
720 #endif // wxUSE_THREADS
721
722 if ( !wxTheApp->Dispatch() )
723 break;
724 }
725
726 // if there are pending events, we must process them.
727 ProcessPendingEvents();
728
729 #if wxUSE_LOG
730 // let the logs be flashed again
731 wxLog::Resume();
732 #endif // wxUSE_LOG
733
734 s_inYield = false;
735
736 return true;
737 }
738
739 #if wxUSE_EXCEPTIONS
740
741 // ----------------------------------------------------------------------------
742 // exception handling
743 // ----------------------------------------------------------------------------
744
745 bool wxApp::OnExceptionInMainLoop()
746 {
747 // ask the user about what to do: use the Win32 API function here as it
748 // could be dangerous to use any wxWidgets code in this state
749 switch (
750 ::MessageBox
751 (
752 NULL,
753 _T("An unhandled exception occurred. Press \"Abort\" to \
754 terminate the program,\r\n\
755 \"Retry\" to exit the program normally and \"Ignore\" to try to continue."),
756 _T("Unhandled exception"),
757 MB_ABORTRETRYIGNORE |
758 MB_ICONERROR|
759 MB_TASKMODAL
760 )
761 )
762 {
763 case IDABORT:
764 throw;
765
766 default:
767 wxFAIL_MSG( _T("unexpected MessageBox() return code") );
768 // fall through
769
770 case IDRETRY:
771 return false;
772
773 case IDIGNORE:
774 return true;
775 }
776 }
777
778 #endif // wxUSE_EXCEPTIONS