]> git.saurik.com Git - wxWidgets.git/blob - src/msw/app.cpp
added constructor for compliance with wxPython
[wxWidgets.git] / src / msw / app.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ===========================================================================
13 // declarations
14 // ===========================================================================
15
16 // ---------------------------------------------------------------------------
17 // headers
18 // ---------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "app.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #if defined(__BORLANDC__)
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include "wx/frame.h"
33 #include "wx/app.h"
34 #include "wx/utils.h"
35 #include "wx/gdicmn.h"
36 #include "wx/pen.h"
37 #include "wx/brush.h"
38 #include "wx/cursor.h"
39 #include "wx/icon.h"
40 #include "wx/palette.h"
41 #include "wx/dc.h"
42 #include "wx/dialog.h"
43 #include "wx/msgdlg.h"
44 #include "wx/intl.h"
45 #include "wx/dynarray.h"
46 #include "wx/wxchar.h"
47 #include "wx/icon.h"
48 #include "wx/log.h"
49 #endif
50
51 #include "wx/cmdline.h"
52 #include "wx/filename.h"
53 #include "wx/module.h"
54
55 #include "wx/msw/private.h"
56
57 #if wxUSE_THREADS
58 #include "wx/thread.h"
59
60 // define the array of MSG strutures
61 WX_DECLARE_OBJARRAY(MSG, wxMsgArray);
62
63 #include "wx/arrimpl.cpp"
64
65 WX_DEFINE_OBJARRAY(wxMsgArray);
66 #endif // wxUSE_THREADS
67
68 #if wxUSE_WX_RESOURCES
69 #include "wx/resource.h"
70 #endif
71
72 #if wxUSE_TOOLTIPS
73 #include "wx/tooltip.h"
74 #endif // wxUSE_TOOLTIPS
75
76 // OLE is used for drag-and-drop, clipboard, OLE Automation..., but some
77 // compilers don't support it (missing headers, libs, ...)
78 #if defined(__GNUWIN32_OLD__) || defined(__SC__) || defined(__SALFORDC__)
79 #undef wxUSE_OLE
80
81 #define wxUSE_OLE 0
82 #endif // broken compilers
83
84 #if wxUSE_OLE
85 #include <ole2.h>
86 #endif
87
88 #include <string.h>
89 #include <ctype.h>
90
91 #if defined(__WIN95__) && !((defined(__GNUWIN32_OLD__) || defined(__TWIN32__) || defined(__WXMICROWIN__)) && !defined(__CYGWIN10__))
92 #include <commctrl.h>
93 #endif
94
95 #ifndef __WXMICROWIN__
96 #include "wx/msw/msvcrt.h"
97 #endif
98
99 // ----------------------------------------------------------------------------
100 // conditional compilation
101 // ----------------------------------------------------------------------------
102
103 // The macro _WIN32_IE is defined by commctrl.h (unless it had already been
104 // defined before) and shows us what common control features are available
105 // during the compile time (it doesn't mean that they will be available during
106 // the run-time, use GetComCtl32Version() to test for them!). The possible
107 // values are:
108 //
109 // 0x0200 for comctl32.dll 4.00 shipped with Win95/NT 4.0
110 // 0x0300 4.70 IE 3.x
111 // 0x0400 4.71 IE 4.0
112 // 0x0401 4.72 IE 4.01 and Win98
113 // 0x0500 5.00 IE 5.x and NT 5.0 (Win2000)
114
115 #ifndef _WIN32_IE
116 // minimal set of features by default
117 #define _WIN32_IE 0x0200
118 #endif
119
120 #if _WIN32_IE >= 0x0300 && !defined(__MINGW32__)
121 #include <shlwapi.h>
122 #endif
123
124 // ---------------------------------------------------------------------------
125 // global variables
126 // ---------------------------------------------------------------------------
127
128 extern wxChar *wxBuffer;
129 extern wxList WXDLLEXPORT wxPendingDelete;
130 #ifndef __WXMICROWIN__
131 extern void wxSetKeyboardHook(bool doIt);
132 #endif
133
134 MSG s_currentMsg;
135 wxApp *wxTheApp = NULL;
136
137 // NB: all "NoRedraw" classes must have the same names as the "normal" classes
138 // with NR suffix - wxWindow::MSWCreate() supposes this
139 const wxChar *wxFrameClassName = wxT("wxFrameClass");
140 const wxChar *wxFrameClassNameNoRedraw = wxT("wxFrameClassNR");
141 const wxChar *wxMDIFrameClassName = wxT("wxMDIFrameClass");
142 const wxChar *wxMDIFrameClassNameNoRedraw = wxT("wxMDIFrameClassNR");
143 const wxChar *wxMDIChildFrameClassName = wxT("wxMDIChildFrameClass");
144 const wxChar *wxMDIChildFrameClassNameNoRedraw = wxT("wxMDIChildFrameClassNR");
145 const wxChar *wxPanelClassName = wxT("wxPanelClass");
146 const wxChar *wxPanelClassNameNR = wxT("wxPanelClassNR");
147 const wxChar *wxCanvasClassName = wxT("wxCanvasClass");
148 const wxChar *wxCanvasClassNameNR = wxT("wxCanvasClassNR");
149
150 HICON wxSTD_FRAME_ICON = (HICON) NULL;
151 HICON wxSTD_MDICHILDFRAME_ICON = (HICON) NULL;
152 HICON wxSTD_MDIPARENTFRAME_ICON = (HICON) NULL;
153
154 HICON wxDEFAULT_FRAME_ICON = (HICON) NULL;
155 HICON wxDEFAULT_MDICHILDFRAME_ICON = (HICON) NULL;
156 HICON wxDEFAULT_MDIPARENTFRAME_ICON = (HICON) NULL;
157
158 HBRUSH wxDisableButtonBrush = (HBRUSH) 0;
159
160 LRESULT WXDLLEXPORT APIENTRY wxWndProc(HWND, UINT, WPARAM, LPARAM);
161
162 // FIXME wxUSE_ON_FATAL_EXCEPTION is only supported for VC++ now because it
163 // needs compiler support for Win32 SEH. Others (especially Borland)
164 // probably have it too, but I'm not sure about how it works
165 // JACS: get 'Cannot use __try in functions that require unwinding
166 // in Unicode mode, so disabling.
167 #if !defined(__VISUALC__) || defined(__WIN16__) || defined(UNICODE)
168 #undef wxUSE_ON_FATAL_EXCEPTION
169 #define wxUSE_ON_FATAL_EXCEPTION 0
170 #endif // VC++
171
172 #if wxUSE_ON_FATAL_EXCEPTION
173 static bool gs_handleExceptions = FALSE;
174 #endif
175
176 // ===========================================================================
177 // implementation
178 // ===========================================================================
179
180 // ---------------------------------------------------------------------------
181 // wxApp
182 // ---------------------------------------------------------------------------
183
184 IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
185
186 BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
187 EVT_IDLE(wxApp::OnIdle)
188 EVT_END_SESSION(wxApp::OnEndSession)
189 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession)
190 END_EVENT_TABLE()
191
192 //// Initialize
193 bool wxApp::Initialize()
194 {
195 // the first thing to do is to check if we're trying to run an Unicode
196 // program under Win9x w/o MSLU emulation layer - if so, abort right now
197 // as it has no chance to work
198 #if wxUSE_UNICODE && !wxUSE_UNICODE_MSLU
199 if ( wxGetOsVersion() != wxWINDOWS_NT )
200 {
201 // note that we can use MessageBoxW() as it's implemented even under
202 // Win9x - OTOH, we can't use wxGetTranslation() because the file APIs
203 // used by wxLocale are not
204 ::MessageBox
205 (
206 NULL,
207 _T("This program uses Unicode and requires Windows NT/2000/XP.\nProgram aborted."),
208 _T("wxWindows Fatal Error"),
209 MB_ICONERROR | MB_OK
210 );
211
212 return FALSE;
213 }
214 #endif // wxUSE_UNICODE && !wxUSE_UNICODE_MSLU
215
216 // Some people may wish to use this, but
217 // probably it shouldn't be here by default.
218 #ifdef __WXDEBUG__
219 // wxRedirectIOToConsole();
220 #endif
221
222 wxBuffer = new wxChar[1500]; // FIXME
223
224 wxClassInfo::InitializeClasses();
225
226 #if wxUSE_THREADS
227 wxPendingEventsLocker = new wxCriticalSection;
228 #endif
229
230 wxTheColourDatabase = new wxColourDatabase(wxKEY_STRING);
231 wxTheColourDatabase->Initialize();
232
233 wxInitializeStockLists();
234 wxInitializeStockObjects();
235
236 #if wxUSE_WX_RESOURCES
237 wxInitializeResourceSystem();
238 #endif
239
240 wxBitmap::InitStandardHandlers();
241
242 #if defined(__WIN95__) && !defined(__WXMICROWIN__)
243 InitCommonControls();
244 #endif // __WIN95__
245
246 #if wxUSE_OLE || wxUSE_DRAG_AND_DROP
247
248 #ifdef __WIN16__
249 // for OLE, enlarge message queue to be as large as possible
250 int iMsg = 96;
251 while (!SetMessageQueue(iMsg) && (iMsg -= 8))
252 ;
253 #endif // Win16
254
255 #if wxUSE_OLE
256 // we need to initialize OLE library
257 if ( FAILED(::OleInitialize(NULL)) )
258 wxLogError(_("Cannot initialize OLE"));
259 #endif
260
261 #endif // wxUSE_OLE
262
263 #if wxUSE_CTL3D
264 if (!Ctl3dRegister(wxhInstance))
265 wxLogError(wxT("Cannot register CTL3D"));
266
267 Ctl3dAutoSubclass(wxhInstance);
268 #endif // wxUSE_CTL3D
269
270 // VZ: these icons are not in wx.rc anyhow (but should they?)!
271 #if 0
272 wxSTD_FRAME_ICON = LoadIcon(wxhInstance, wxT("wxSTD_FRAME"));
273 wxSTD_MDIPARENTFRAME_ICON = LoadIcon(wxhInstance, wxT("wxSTD_MDIPARENTFRAME"));
274 wxSTD_MDICHILDFRAME_ICON = LoadIcon(wxhInstance, wxT("wxSTD_MDICHILDFRAME"));
275
276 wxDEFAULT_FRAME_ICON = LoadIcon(wxhInstance, wxT("wxDEFAULT_FRAME"));
277 wxDEFAULT_MDIPARENTFRAME_ICON = LoadIcon(wxhInstance, wxT("wxDEFAULT_MDIPARENTFRAME"));
278 wxDEFAULT_MDICHILDFRAME_ICON = LoadIcon(wxhInstance, wxT("wxDEFAULT_MDICHILDFRAME"));
279 #endif // 0
280
281 RegisterWindowClasses();
282
283 #ifndef __WXMICROWIN__
284 // Create the brush for disabling bitmap buttons
285
286 LOGBRUSH lb;
287 lb.lbStyle = BS_PATTERN;
288 lb.lbColor = 0;
289 lb.lbHatch = (int)LoadBitmap( wxhInstance, wxT("wxDISABLE_BUTTON_BITMAP") );
290 if ( lb.lbHatch )
291 {
292 wxDisableButtonBrush = ::CreateBrushIndirect( & lb );
293 ::DeleteObject( (HGDIOBJ)lb.lbHatch );
294 }
295 //else: wxWindows resources are probably not linked in
296 #endif
297
298 #if wxUSE_PENWINDOWS
299 wxRegisterPenWin();
300 #endif
301
302 wxWinHandleHash = new wxWinHashTable(wxKEY_INTEGER, 100);
303
304 // This is to foil optimizations in Visual C++ that throw out dummy.obj.
305 // PLEASE DO NOT ALTER THIS.
306 #if defined(__VISUALC__) && defined(__WIN16__) && !defined(WXMAKINGDLL)
307 extern char wxDummyChar;
308 if (wxDummyChar) wxDummyChar++;
309 #endif
310
311 #ifndef __WXMICROWIN__
312 wxSetKeyboardHook(TRUE);
313 #endif
314
315 wxModule::RegisterModules();
316 if (!wxModule::InitializeModules())
317 return FALSE;
318 return TRUE;
319 }
320
321 // ---------------------------------------------------------------------------
322 // RegisterWindowClasses
323 // ---------------------------------------------------------------------------
324
325 // TODO we should only register classes really used by the app. For this it
326 // would be enough to just delay the class registration until an attempt
327 // to create a window of this class is made.
328 bool wxApp::RegisterWindowClasses()
329 {
330 WNDCLASS wndclass;
331
332 // for each class we register one with CS_(V|H)REDRAW style and one
333 // without for windows created with wxNO_FULL_REDRAW_ON_REPAINT flag
334 static const long styleNormal = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
335 static const long styleNoRedraw = CS_DBLCLKS;
336
337 // the fields which are common to all classes
338 wndclass.lpfnWndProc = (WNDPROC)wxWndProc;
339 wndclass.cbClsExtra = 0;
340 wndclass.cbWndExtra = sizeof( DWORD ); // VZ: what is this DWORD used for?
341 wndclass.hInstance = wxhInstance;
342 wndclass.hIcon = (HICON) NULL;
343 wndclass.hCursor = ::LoadCursor((HINSTANCE)NULL, IDC_ARROW);
344 wndclass.lpszMenuName = NULL;
345
346 // Register the frame window class.
347 wndclass.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE + 1);
348 wndclass.lpszClassName = wxFrameClassName;
349 wndclass.style = styleNormal;
350
351 if ( !RegisterClass(&wndclass) )
352 {
353 wxLogLastError(wxT("RegisterClass(frame)"));
354
355 return FALSE;
356 }
357
358 // "no redraw" frame
359 wndclass.lpszClassName = wxFrameClassNameNoRedraw;
360 wndclass.style = styleNoRedraw;
361
362 if ( !RegisterClass(&wndclass) )
363 {
364 wxLogLastError(wxT("RegisterClass(no redraw frame)"));
365
366 return FALSE;
367 }
368
369 // Register the MDI frame window class.
370 wndclass.hbrBackground = (HBRUSH)NULL; // paint MDI frame ourselves
371 wndclass.lpszClassName = wxMDIFrameClassName;
372 wndclass.style = styleNormal;
373
374 if ( !RegisterClass(&wndclass) )
375 {
376 wxLogLastError(wxT("RegisterClass(MDI parent)"));
377
378 return FALSE;
379 }
380
381 // "no redraw" MDI frame
382 wndclass.lpszClassName = wxMDIFrameClassNameNoRedraw;
383 wndclass.style = styleNoRedraw;
384
385 if ( !RegisterClass(&wndclass) )
386 {
387 wxLogLastError(wxT("RegisterClass(no redraw MDI parent frame)"));
388
389 return FALSE;
390 }
391
392 // Register the MDI child frame window class.
393 wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
394 wndclass.lpszClassName = wxMDIChildFrameClassName;
395 wndclass.style = styleNormal;
396
397 if ( !RegisterClass(&wndclass) )
398 {
399 wxLogLastError(wxT("RegisterClass(MDI child)"));
400
401 return FALSE;
402 }
403
404 // "no redraw" MDI child frame
405 wndclass.lpszClassName = wxMDIChildFrameClassNameNoRedraw;
406 wndclass.style = styleNoRedraw;
407
408 if ( !RegisterClass(&wndclass) )
409 {
410 wxLogLastError(wxT("RegisterClass(no redraw MDI child)"));
411
412 return FALSE;
413 }
414
415 // Register the panel window class.
416 wndclass.hbrBackground = (HBRUSH) GetStockObject( LTGRAY_BRUSH );
417 wndclass.lpszClassName = wxPanelClassName;
418 wndclass.style = styleNormal;
419
420 if ( !RegisterClass(&wndclass) )
421 {
422 wxLogLastError(wxT("RegisterClass(panel)"));
423
424 return FALSE;
425 }
426
427 // Register the no redraw panel window class.
428 wndclass.lpszClassName = wxPanelClassNameNR;
429 wndclass.style = styleNoRedraw;
430
431 if ( !RegisterClass(&wndclass) )
432 {
433 wxLogLastError(wxT("RegisterClass(no redraw panel)"));
434
435 return FALSE;
436 }
437
438 // Register the canvas and textsubwindow class name
439 wndclass.hbrBackground = (HBRUSH)NULL;
440 wndclass.lpszClassName = wxCanvasClassName;
441
442 if ( !RegisterClass(&wndclass) )
443 {
444 wxLogLastError(wxT("RegisterClass(canvas)"));
445
446 return FALSE;
447 }
448
449 wndclass.lpszClassName = wxCanvasClassNameNR;
450 wndclass.style = styleNoRedraw;
451 if ( !RegisterClass(&wndclass) )
452 {
453 wxLogLastError(wxT("RegisterClass(no redraw canvas)"));
454
455 return FALSE;
456 }
457
458 return TRUE;
459 }
460
461 // ---------------------------------------------------------------------------
462 // UnregisterWindowClasses
463 // ---------------------------------------------------------------------------
464
465 bool wxApp::UnregisterWindowClasses()
466 {
467 bool retval = TRUE;
468
469 #ifndef __WXMICROWIN__
470 // frame window class.
471 if ( !UnregisterClass(wxFrameClassName, wxhInstance) )
472 {
473 wxLogLastError(wxT("UnregisterClass(frame)"));
474
475 retval = FALSE;
476 }
477
478 // "no redraw" frame
479 if ( !UnregisterClass(wxFrameClassNameNoRedraw, wxhInstance) )
480 {
481 wxLogLastError(wxT("UnregisterClass(no redraw frame)"));
482
483 return FALSE;
484 }
485
486 // MDI frame window class.
487 if ( !UnregisterClass(wxMDIFrameClassName, wxhInstance) )
488 {
489 wxLogLastError(wxT("UnregisterClass(MDI parent)"));
490
491 retval = FALSE;
492 }
493
494 // "no redraw" MDI frame
495 if ( !UnregisterClass(wxMDIFrameClassNameNoRedraw, wxhInstance) )
496 {
497 wxLogLastError(wxT("UnregisterClass(no redraw MDI parent frame)"));
498
499 retval = FALSE;
500 }
501
502 // MDI child frame window class.
503 if ( !UnregisterClass(wxMDIChildFrameClassName, wxhInstance) )
504 {
505 wxLogLastError(wxT("UnregisterClass(MDI child)"));
506
507 retval = FALSE;
508 }
509
510 // "no redraw" MDI child frame
511 if ( !UnregisterClass(wxMDIChildFrameClassNameNoRedraw, wxhInstance) )
512 {
513 wxLogLastError(wxT("UnregisterClass(no redraw MDI child)"));
514
515 retval = FALSE;
516 }
517
518 // panel window class.
519 if ( !UnregisterClass(wxPanelClassName, wxhInstance) )
520 {
521 wxLogLastError(wxT("UnregisterClass(panel)"));
522
523 retval = FALSE;
524 }
525
526 // no redraw panel window class.
527 if ( !UnregisterClass(wxPanelClassNameNR, wxhInstance) )
528 {
529 wxLogLastError(wxT("UnregisterClass(no redraw panel)"));
530
531 retval = FALSE;
532 }
533
534 // canvas and textsubwindow class name
535 if ( !UnregisterClass(wxCanvasClassName, wxhInstance) )
536 {
537 wxLogLastError(wxT("UnregisterClass(canvas)"));
538
539 retval = FALSE;
540 }
541
542 if ( !UnregisterClass(wxCanvasClassNameNR, wxhInstance) )
543 {
544 wxLogLastError(wxT("UnregisterClass(no redraw canvas)"));
545
546 retval = FALSE;
547 }
548 #endif
549 // __WXMICROWIN__
550 return retval;
551 }
552
553 // ---------------------------------------------------------------------------
554 // Convert Windows to argc, argv style
555 // ---------------------------------------------------------------------------
556
557 void wxApp::ConvertToStandardCommandArgs(const char* lpCmdLine)
558 {
559 // break the command line in words
560 wxArrayString args =
561 wxCmdLineParser::ConvertStringToArgs(wxConvertMB2WX(lpCmdLine));
562
563 // +1 here for the program name
564 argc = args.GetCount() + 1;
565
566 // and +1 here for the terminating NULL
567 argv = new wxChar *[argc + 1];
568
569 argv[0] = new wxChar[260]; // 260 is MAX_PATH value from windef.h
570 ::GetModuleFileName(wxhInstance, argv[0], 260);
571
572 // also set the app name from argv[0]
573 wxString name;
574 wxFileName::SplitPath(argv[0], NULL, &name, NULL);
575
576 SetAppName(name);
577
578 // copy all the other arguments to wxApp::argv[]
579 for ( int i = 1; i < argc; i++ )
580 {
581 argv[i] = copystring(args[i - 1]);
582 }
583
584 // argv[] must be NULL-terminated
585 argv[argc] = NULL;
586 }
587
588 //// Cleans up any wxWindows internal structures left lying around
589
590 void wxApp::CleanUp()
591 {
592 //// COMMON CLEANUP
593
594 #if wxUSE_LOG
595 // flush the logged messages if any and install a 'safer' log target: the
596 // default one (wxLogGui) can't be used after the resources are freed just
597 // below and the user suppliedo ne might be even more unsafe (using any
598 // wxWindows GUI function is unsafe starting from now)
599 wxLog::DontCreateOnDemand();
600
601 // this will flush the old messages if any
602 delete wxLog::SetActiveTarget(new wxLogStderr);
603 #endif // wxUSE_LOG
604
605 // One last chance for pending objects to be cleaned up
606 wxTheApp->DeletePendingObjects();
607
608 wxModule::CleanUpModules();
609
610 #if wxUSE_WX_RESOURCES
611 wxCleanUpResourceSystem();
612
613 // wxDefaultResourceTable->ClearTable();
614 #endif
615
616 wxDeleteStockObjects();
617
618 // Destroy all GDI lists, etc.
619 wxDeleteStockLists();
620
621 delete wxTheColourDatabase;
622 wxTheColourDatabase = NULL;
623
624 wxBitmap::CleanUpHandlers();
625
626 delete[] wxBuffer;
627 wxBuffer = NULL;
628
629 //// WINDOWS-SPECIFIC CLEANUP
630
631 #ifndef __WXMICROWIN__
632 wxSetKeyboardHook(FALSE);
633 #endif
634
635 #if wxUSE_PENWINDOWS
636 wxCleanUpPenWin();
637 #endif
638
639 if (wxSTD_FRAME_ICON)
640 DestroyIcon(wxSTD_FRAME_ICON);
641 if (wxSTD_MDICHILDFRAME_ICON)
642 DestroyIcon(wxSTD_MDICHILDFRAME_ICON);
643 if (wxSTD_MDIPARENTFRAME_ICON)
644 DestroyIcon(wxSTD_MDIPARENTFRAME_ICON);
645
646 if (wxDEFAULT_FRAME_ICON)
647 DestroyIcon(wxDEFAULT_FRAME_ICON);
648 if (wxDEFAULT_MDICHILDFRAME_ICON)
649 DestroyIcon(wxDEFAULT_MDICHILDFRAME_ICON);
650 if (wxDEFAULT_MDIPARENTFRAME_ICON)
651 DestroyIcon(wxDEFAULT_MDIPARENTFRAME_ICON);
652
653 if ( wxDisableButtonBrush )
654 ::DeleteObject( wxDisableButtonBrush );
655
656 #if wxUSE_OLE
657 ::OleUninitialize();
658 #endif
659
660 #ifdef WXMAKINGDLL
661 // for an EXE the classes are unregistered when it terminates but DLL may
662 // be loaded several times (load/unload/load) into the same process in
663 // which case the registration will fail after the first time if we don't
664 // unregister the classes now
665 UnregisterWindowClasses();
666 #endif // WXMAKINGDLL
667
668 #if wxUSE_CTL3D
669 Ctl3dUnregister(wxhInstance);
670 #endif
671
672 delete wxWinHandleHash;
673
674 // GL: I'm annoyed ... I don't know where to put this and I don't want to
675 // create a module for that as it's part of the core.
676 delete wxPendingEvents;
677
678 #if wxUSE_THREADS
679 delete wxPendingEventsLocker;
680 // If we don't do the following, we get an apparent memory leak
681 #if wxUSE_VALIDATORS
682 ((wxEvtHandler&) wxDefaultValidator).ClearEventLocker();
683 #endif // wxUSE_VALIDATORS
684 #endif // wxUSE_THREADS
685
686 wxClassInfo::CleanUpClasses();
687
688 delete wxTheApp;
689 wxTheApp = NULL;
690
691 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
692 // At this point we want to check if there are any memory
693 // blocks that aren't part of the wxDebugContext itself,
694 // as a special case. Then when dumping we need to ignore
695 // wxDebugContext, too.
696 if (wxDebugContext::CountObjectsLeft(TRUE) > 0)
697 {
698 wxLogMessage(wxT("There were memory leaks."));
699 wxDebugContext::Dump();
700 wxDebugContext::PrintStatistics();
701 }
702 // wxDebugContext::SetStream(NULL, NULL);
703 #endif
704
705 #if wxUSE_LOG
706 // do it as the very last thing because everything else can log messages
707 delete wxLog::SetActiveTarget(NULL);
708 #endif // wxUSE_LOG
709 }
710
711 //----------------------------------------------------------------------
712 // Entry point helpers, used by wxPython
713 //----------------------------------------------------------------------
714
715 int WXDLLEXPORT wxEntryStart( int WXUNUSED(argc), char** WXUNUSED(argv) )
716 {
717 return wxApp::Initialize();
718 }
719
720 int WXDLLEXPORT wxEntryInitGui()
721 {
722 return wxTheApp->OnInitGui();
723 }
724
725 void WXDLLEXPORT wxEntryCleanup()
726 {
727 wxApp::CleanUp();
728 }
729
730
731 #if !defined(_WINDLL) || (defined(_WINDLL) && defined(WXMAKINGDLL))
732
733 // temporarily disable this warning which would be generated in release builds
734 // because of __try
735 #ifdef __VISUALC__
736 #pragma warning(disable: 4715) // not all control paths return a value
737 #endif // Visual C++
738
739 //----------------------------------------------------------------------
740 // Main wxWindows entry point
741 //----------------------------------------------------------------------
742 int wxEntry(WXHINSTANCE hInstance,
743 WXHINSTANCE WXUNUSED(hPrevInstance),
744 char *lpCmdLine,
745 int nCmdShow,
746 bool enterLoop)
747 {
748 // do check for memory leaks on program exit
749 // (another useful flag is _CRTDBG_DELAY_FREE_MEM_DF which doesn't free
750 // deallocated memory which may be used to simulate low-memory condition)
751 #ifndef __WXMICROWIN__
752 wxCrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);
753 #endif
754
755 #ifdef __MWERKS__
756 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
757 // This seems to be necessary since there are 'rogue'
758 // objects present at this point (perhaps global objects?)
759 // Setting a checkpoint will ignore them as far as the
760 // memory checking facility is concerned.
761 // Of course you may argue that memory allocated in globals should be
762 // checked, but this is a reasonable compromise.
763 wxDebugContext::SetCheckpoint();
764 #endif
765 #endif
766
767 // take everything into a try-except block to be able to call
768 // OnFatalException() if necessary
769 #if wxUSE_ON_FATAL_EXCEPTION
770 __try {
771 #endif
772 wxhInstance = (HINSTANCE) hInstance;
773
774 if (!wxEntryStart(0,0))
775 return 0;
776
777 // create the application object or ensure that one already exists
778 if (!wxTheApp)
779 {
780 // The app may have declared a global application object, but we recommend
781 // the IMPLEMENT_APP macro is used instead, which sets an initializer
782 // function for delayed, dynamic app object construction.
783 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
784 wxT("No initializer - use IMPLEMENT_APP macro.") );
785
786 wxTheApp = (wxApp*) (*wxApp::GetInitializerFunction()) ();
787 }
788
789 wxCHECK_MSG( wxTheApp, 0, wxT("You have to define an instance of wxApp!") );
790
791 // save the WinMain() parameters
792 if (lpCmdLine) // MicroWindows passes NULL
793 wxTheApp->ConvertToStandardCommandArgs(lpCmdLine);
794 wxTheApp->m_nCmdShow = nCmdShow;
795
796 // We really don't want timestamps by default, because it means
797 // we can't simply double-click on the error message and get to that
798 // line in the source. So VC++ at least, let's have a sensible default.
799 #ifdef __VISUALC__
800 wxLog::SetTimestamp(NULL);
801 #endif
802
803 int retValue = 0;
804
805 // it is common to create a modal dialog in OnInit() (to ask/notify the
806 // user about something) but it wouldn't work if we don't change the
807 // "exit on delete last frame" flag here as when this dialog is
808 // deleted, the app would terminate (it was the last top level window
809 // as the main frame wasn't created yet!), so disable this behaviour
810 // temproarily
811 bool exitOnLastFrameDelete = wxTheApp->GetExitOnFrameDelete();
812 wxTheApp->SetExitOnFrameDelete(FALSE);
813
814 // init the app
815 retValue = wxEntryInitGui() && wxTheApp->OnInit() ? 0 : -1;
816
817 // restore the old flag value
818 wxTheApp->SetExitOnFrameDelete(exitOnLastFrameDelete);
819
820 if ( retValue == 0 )
821 {
822 if ( enterLoop )
823 {
824 // run the main loop
825 retValue = wxTheApp->OnRun();
826 }
827 else
828 {
829 // we want to initialize, but not run or exit immediately.
830 return 1;
831 }
832 }
833 //else: app initialization failed, so we skipped OnRun()
834
835 wxWindow *topWindow = wxTheApp->GetTopWindow();
836 if ( topWindow )
837 {
838 // Forcibly delete the window.
839 if ( topWindow->IsKindOf(CLASSINFO(wxFrame)) ||
840 topWindow->IsKindOf(CLASSINFO(wxDialog)) )
841 {
842 topWindow->Close(TRUE);
843 wxTheApp->DeletePendingObjects();
844 }
845 else
846 {
847 delete topWindow;
848 wxTheApp->SetTopWindow(NULL);
849 }
850 }
851
852 wxTheApp->OnExit();
853
854 wxEntryCleanup();
855
856 return retValue;
857
858 #if wxUSE_ON_FATAL_EXCEPTION
859 }
860 __except ( gs_handleExceptions ? EXCEPTION_EXECUTE_HANDLER
861 : EXCEPTION_CONTINUE_SEARCH ) {
862 if ( wxTheApp )
863 {
864 // give the user a chance to do something special about this
865 wxTheApp->OnFatalException();
866 }
867
868 ::ExitProcess(3); // the same exit code as abort()
869
870 // NOTREACHED
871 }
872 #endif // wxUSE_ON_FATAL_EXCEPTION
873 }
874
875 // restore warning state
876 #ifdef __VISUALC__
877 #pragma warning(default: 4715) // not all control paths return a value
878 #endif // Visual C++
879
880 #else /* _WINDLL */
881
882 //----------------------------------------------------------------------
883 // Entry point for wxWindows + the App in a DLL
884 //----------------------------------------------------------------------
885
886 int wxEntry(WXHINSTANCE hInstance)
887 {
888 wxhInstance = (HINSTANCE) hInstance;
889 wxEntryStart(0, 0);
890
891 // The app may have declared a global application object, but we recommend
892 // the IMPLEMENT_APP macro is used instead, which sets an initializer function
893 // for delayed, dynamic app object construction.
894 if (!wxTheApp)
895 {
896 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
897 "No initializer - use IMPLEMENT_APP macro." );
898
899 wxTheApp = (* wxApp::GetInitializerFunction()) ();
900 }
901
902 wxCHECK_MSG( wxTheApp, 0, "You have to define an instance of wxApp!" );
903
904 wxTheApp->argc = 0;
905 wxTheApp->argv = NULL;
906
907 wxEntryInitGui();
908
909 wxTheApp->OnInit();
910
911 wxWindow *topWindow = wxTheApp->GetTopWindow();
912 if ( topWindow && topWindow->GetHWND())
913 {
914 topWindow->Show(TRUE);
915 }
916
917 return 1;
918 }
919 #endif // _WINDLL
920
921 //// Static member initialization
922
923 wxAppInitializerFunction wxAppBase::m_appInitFn = (wxAppInitializerFunction) NULL;
924
925 wxApp::wxApp()
926 {
927 argc = 0;
928 argv = NULL;
929 m_printMode = wxPRINT_WINDOWS;
930 m_auto3D = TRUE;
931 }
932
933 wxApp::~wxApp()
934 {
935 // Delete command-line args
936 int i;
937 for (i = 0; i < argc; i++)
938 {
939 delete[] argv[i];
940 }
941 delete[] argv;
942 }
943
944 bool wxApp::Initialized()
945 {
946 #ifndef _WINDLL
947 if (GetTopWindow())
948 return TRUE;
949 else
950 return FALSE;
951 #else // Assume initialized if DLL (no way of telling)
952 return TRUE;
953 #endif
954 }
955
956 /*
957 * Get and process a message, returning FALSE if WM_QUIT
958 * received (and also set the flag telling the app to exit the main loop)
959 *
960 */
961 bool wxApp::DoMessage()
962 {
963 BOOL rc = ::GetMessage(&s_currentMsg, (HWND) NULL, 0, 0);
964 if ( rc == 0 )
965 {
966 // got WM_QUIT
967 m_keepGoing = FALSE;
968
969 return FALSE;
970 }
971 else if ( rc == -1 )
972 {
973 // should never happen, but let's test for it nevertheless
974 wxLogLastError(wxT("GetMessage"));
975 }
976 else
977 {
978 #if wxUSE_THREADS
979 wxASSERT_MSG( wxThread::IsMain(),
980 wxT("only the main thread can process Windows messages") );
981
982 static bool s_hadGuiLock = TRUE;
983 static wxMsgArray s_aSavedMessages;
984
985 // if a secondary thread owns is doing GUI calls, save all messages for
986 // later processing - we can't process them right now because it will
987 // lead to recursive library calls (and we're not reentrant)
988 if ( !wxGuiOwnedByMainThread() )
989 {
990 s_hadGuiLock = FALSE;
991
992 // leave out WM_COMMAND messages: too dangerous, sometimes
993 // the message will be processed twice
994 if ( !wxIsWaitingForThread() ||
995 s_currentMsg.message != WM_COMMAND )
996 {
997 s_aSavedMessages.Add(s_currentMsg);
998 }
999
1000 return TRUE;
1001 }
1002 else
1003 {
1004 // have we just regained the GUI lock? if so, post all of the saved
1005 // messages
1006 //
1007 // FIXME of course, it's not _exactly_ the same as processing the
1008 // messages normally - expect some things to break...
1009 if ( !s_hadGuiLock )
1010 {
1011 s_hadGuiLock = TRUE;
1012
1013 size_t count = s_aSavedMessages.Count();
1014 for ( size_t n = 0; n < count; n++ )
1015 {
1016 MSG& msg = s_aSavedMessages[n];
1017
1018 if ( !ProcessMessage((WXMSG *)&msg) )
1019 {
1020 ::TranslateMessage(&msg);
1021 ::DispatchMessage(&msg);
1022 }
1023 }
1024
1025 s_aSavedMessages.Empty();
1026 }
1027 }
1028 #endif // wxUSE_THREADS
1029
1030 // Process the message
1031 DoMessage((WXMSG *)&s_currentMsg);
1032 }
1033
1034 return TRUE;
1035 }
1036
1037 void wxApp::DoMessage(WXMSG *pMsg)
1038 {
1039 if ( !ProcessMessage(pMsg) )
1040 {
1041 ::TranslateMessage((MSG *)pMsg);
1042 ::DispatchMessage((MSG *)pMsg);
1043 }
1044 }
1045
1046 /*
1047 * Keep trying to process messages until WM_QUIT
1048 * received.
1049 *
1050 * If there are messages to be processed, they will all be
1051 * processed and OnIdle will not be called.
1052 * When there are no more messages, OnIdle is called.
1053 * If OnIdle requests more time,
1054 * it will be repeatedly called so long as there are no pending messages.
1055 * A 'feature' of this is that once OnIdle has decided that no more processing
1056 * is required, then it won't get processing time until further messages
1057 * are processed (it'll sit in DoMessage).
1058 */
1059
1060 int wxApp::MainLoop()
1061 {
1062 m_keepGoing = TRUE;
1063
1064 while ( m_keepGoing )
1065 {
1066 #if wxUSE_THREADS
1067 wxMutexGuiLeaveOrEnter();
1068 #endif // wxUSE_THREADS
1069
1070 while ( !Pending() && ProcessIdle() )
1071 ;
1072
1073 // a message came or no more idle processing to do
1074 DoMessage();
1075 }
1076
1077 return s_currentMsg.wParam;
1078 }
1079
1080 // Returns TRUE if more time is needed.
1081 bool wxApp::ProcessIdle()
1082 {
1083 wxIdleEvent event;
1084 event.SetEventObject(this);
1085 ProcessEvent(event);
1086
1087 return event.MoreRequested();
1088 }
1089
1090 void wxApp::ExitMainLoop()
1091 {
1092 // VZ: why not ::PostQuitMessage()?
1093 m_keepGoing = FALSE;
1094 }
1095
1096 bool wxApp::Pending()
1097 {
1098 return ::PeekMessage(&s_currentMsg, 0, 0, 0, PM_NOREMOVE) != 0;
1099 }
1100
1101 void wxApp::Dispatch()
1102 {
1103 DoMessage();
1104 }
1105
1106 /*
1107 * Give all windows a chance to preprocess
1108 * the message. Some may have accelerator tables, or have
1109 * MDI complications.
1110 */
1111
1112 bool wxApp::ProcessMessage(WXMSG *wxmsg)
1113 {
1114 MSG *msg = (MSG *)wxmsg;
1115 HWND hwnd = msg->hwnd;
1116 wxWindow *wndThis = wxGetWindowFromHWND((WXHWND)hwnd);
1117
1118 // this may happen if the event occured in a standard modeless dialog (the
1119 // only example of which I know of is the find/replace dialog) - then call
1120 // IsDialogMessage() to make TAB navigation in it work
1121 if ( !wndThis )
1122 {
1123 // we need to find the dialog containing this control as
1124 // IsDialogMessage() just eats all the messages (i.e. returns TRUE for
1125 // them) if we call it for the control itself
1126 while ( hwnd && ::GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD )
1127 {
1128 hwnd = ::GetParent(hwnd);
1129 }
1130
1131 return hwnd && ::IsDialogMessage(hwnd, msg) != 0;
1132 }
1133
1134 #if wxUSE_TOOLTIPS
1135 // we must relay WM_MOUSEMOVE events to the tooltip ctrl if we want it to
1136 // popup the tooltip bubbles
1137 if ( (msg->message == WM_MOUSEMOVE) )
1138 {
1139 wxToolTip *tt = wndThis->GetToolTip();
1140 if ( tt )
1141 {
1142 tt->RelayEvent(wxmsg);
1143 }
1144 }
1145 #endif // wxUSE_TOOLTIPS
1146
1147 // allow the window to prevent certain messages from being
1148 // translated/processed (this is currently used by wxTextCtrl to always
1149 // grab Ctrl-C/V/X, even if they are also accelerators in some parent)
1150 if ( !wndThis->MSWShouldPreProcessMessage(wxmsg) )
1151 {
1152 return FALSE;
1153 }
1154
1155 // try translations first: the accelerators override everything
1156 wxWindow *wnd;
1157
1158 for ( wnd = wndThis; wnd; wnd = wnd->GetParent() )
1159 {
1160 if ( wnd->MSWTranslateMessage(wxmsg))
1161 return TRUE;
1162
1163 // stop at first top level window, i.e. don't try to process the key
1164 // strokes originating in a dialog using the accelerators of the parent
1165 // frame - this doesn't make much sense
1166 if ( wnd->IsTopLevel() )
1167 break;
1168 }
1169
1170 // now try the other hooks (kbd navigation is handled here): we start from
1171 // wndThis->GetParent() because wndThis->MSWProcessMessage() was already
1172 // called above
1173 for ( wnd = wndThis->GetParent(); wnd; wnd = wnd->GetParent() )
1174 {
1175 if ( wnd->MSWProcessMessage(wxmsg) )
1176 return TRUE;
1177 }
1178
1179 // no special preprocessing for this message, dispatch it normally
1180 return FALSE;
1181 }
1182
1183 void wxApp::OnIdle(wxIdleEvent& event)
1184 {
1185 static bool s_inOnIdle = FALSE;
1186
1187 // Avoid recursion (via ProcessEvent default case)
1188 if ( s_inOnIdle )
1189 return;
1190
1191 s_inOnIdle = TRUE;
1192
1193 // If there are pending events, we must process them: pending events
1194 // are either events to the threads other than main or events posted
1195 // with wxPostEvent() functions
1196 // GRG: I have moved this here so that all pending events are processed
1197 // before starting to delete any objects. This behaves better (in
1198 // particular, wrt wxPostEvent) and is coherent with wxGTK's current
1199 // behaviour. Changed Feb/2000 before 2.1.14
1200 ProcessPendingEvents();
1201
1202 // 'Garbage' collection of windows deleted with Close().
1203 DeletePendingObjects();
1204
1205 #if wxUSE_LOG
1206 // flush the logged messages if any
1207 wxLog::FlushActive();
1208 #endif // wxUSE_LOG
1209
1210 #if wxUSE_DC_CACHEING
1211 // automated DC cache management: clear the cached DCs and bitmap
1212 // if it's likely that the app has finished with them, that is, we
1213 // get an idle event and we're not dragging anything.
1214 if (!::GetKeyState(MK_LBUTTON) && !::GetKeyState(MK_MBUTTON) && !::GetKeyState(MK_RBUTTON))
1215 wxDC::ClearCache();
1216 #endif // wxUSE_DC_CACHEING
1217
1218 // Send OnIdle events to all windows
1219 if ( SendIdleEvents() )
1220 {
1221 // SendIdleEvents() returns TRUE if at least one window requested more
1222 // idle events
1223 event.RequestMore(TRUE);
1224 }
1225
1226 s_inOnIdle = FALSE;
1227 }
1228
1229 // Send idle event to all top-level windows
1230 bool wxApp::SendIdleEvents()
1231 {
1232 bool needMore = FALSE;
1233
1234 wxWindowList::Node* node = wxTopLevelWindows.GetFirst();
1235 while (node)
1236 {
1237 wxWindow* win = node->GetData();
1238 if (SendIdleEvents(win))
1239 needMore = TRUE;
1240 node = node->GetNext();
1241 }
1242
1243 return needMore;
1244 }
1245
1246 // Send idle event to window and all subwindows
1247 bool wxApp::SendIdleEvents(wxWindow* win)
1248 {
1249 bool needMore = FALSE;
1250
1251 wxIdleEvent event;
1252 event.SetEventObject(win);
1253 win->GetEventHandler()->ProcessEvent(event);
1254
1255 if (event.MoreRequested())
1256 needMore = TRUE;
1257
1258 wxNode* node = win->GetChildren().First();
1259 while (node)
1260 {
1261 wxWindow* win = (wxWindow*) node->Data();
1262 if (SendIdleEvents(win))
1263 needMore = TRUE;
1264
1265 node = node->Next();
1266 }
1267 return needMore;
1268 }
1269
1270 void wxApp::DeletePendingObjects()
1271 {
1272 wxNode *node = wxPendingDelete.First();
1273 while (node)
1274 {
1275 wxObject *obj = (wxObject *)node->Data();
1276
1277 delete obj;
1278
1279 if (wxPendingDelete.Member(obj))
1280 delete node;
1281
1282 // Deleting one object may have deleted other pending
1283 // objects, so start from beginning of list again.
1284 node = wxPendingDelete.First();
1285 }
1286 }
1287
1288 void wxApp::OnEndSession(wxCloseEvent& WXUNUSED(event))
1289 {
1290 if (GetTopWindow())
1291 GetTopWindow()->Close(TRUE);
1292 }
1293
1294 // Default behaviour: close the application with prompts. The
1295 // user can veto the close, and therefore the end session.
1296 void wxApp::OnQueryEndSession(wxCloseEvent& event)
1297 {
1298 if (GetTopWindow())
1299 {
1300 if (!GetTopWindow()->Close(!event.CanVeto()))
1301 event.Veto(TRUE);
1302 }
1303 }
1304
1305 /* static */
1306 int wxApp::GetComCtl32Version()
1307 {
1308 #ifdef __WXMICROWIN__
1309 return 0;
1310 #else
1311 // cache the result
1312 static int s_verComCtl32 = -1;
1313
1314 wxCRIT_SECT_DECLARE(csComCtl32);
1315 wxCRIT_SECT_LOCKER(lock, csComCtl32);
1316
1317 if ( s_verComCtl32 == -1 )
1318 {
1319 // initally assume no comctl32.dll at all
1320 s_verComCtl32 = 0;
1321
1322 // do we have it?
1323 HMODULE hModuleComCtl32 = ::GetModuleHandle(wxT("COMCTL32"));
1324
1325 // if so, then we can check for the version
1326 if ( hModuleComCtl32 )
1327 {
1328 // try to use DllGetVersion() if available in _headers_
1329 #ifdef DLLVER_PLATFORM_WINDOWS // defined in shlwapi.h
1330 DLLGETVERSIONPROC pfnDllGetVersion = (DLLGETVERSIONPROC)
1331 ::GetProcAddress(hModuleComCtl32, "DllGetVersion");
1332 if ( pfnDllGetVersion )
1333 {
1334 DLLVERSIONINFO dvi;
1335 dvi.cbSize = sizeof(dvi);
1336
1337 HRESULT hr = (*pfnDllGetVersion)(&dvi);
1338 if ( FAILED(hr) )
1339 {
1340 wxLogApiError(_T("DllGetVersion"), hr);
1341 }
1342 else
1343 {
1344 // this is incompatible with _WIN32_IE values, but
1345 // compatible with the other values returned by
1346 // GetComCtl32Version()
1347 s_verComCtl32 = 100*dvi.dwMajorVersion +
1348 dvi.dwMinorVersion;
1349 }
1350 }
1351 #endif
1352 // DllGetVersion() unavailable either during compile or
1353 // run-time, try to guess the version otherwise
1354 if ( !s_verComCtl32 )
1355 {
1356 // InitCommonControlsEx is unique to 4.70 and later
1357 FARPROC theProc = ::GetProcAddress
1358 (
1359 hModuleComCtl32,
1360 "InitCommonControlsEx"
1361 );
1362
1363 if ( !theProc )
1364 {
1365 // not found, must be 4.00
1366 s_verComCtl32 = 400;
1367 }
1368 else
1369 {
1370 // many symbols appeared in comctl32 4.71, could use
1371 // any of them except may be DllInstall
1372 theProc = ::GetProcAddress
1373 (
1374 hModuleComCtl32,
1375 "InitializeFlatSB"
1376 );
1377 if ( !theProc )
1378 {
1379 // not found, must be 4.70
1380 s_verComCtl32 = 470;
1381 }
1382 else
1383 {
1384 // found, must be 4.71
1385 s_verComCtl32 = 471;
1386 }
1387 }
1388 }
1389 }
1390 }
1391
1392 return s_verComCtl32;
1393 #endif
1394 }
1395
1396 void wxExit()
1397 {
1398 wxLogError(_("Fatal error: exiting"));
1399
1400 wxApp::CleanUp();
1401 exit(0);
1402 }
1403
1404 // Yield to incoming messages
1405
1406 bool wxApp::Yield(bool onlyIfNeeded)
1407 {
1408 // MT-FIXME
1409 static bool s_inYield = FALSE;
1410
1411 // disable log flushing from here because a call to wxYield() shouldn't
1412 // normally result in message boxes popping up &c
1413 wxLog::Suspend();
1414
1415 if ( s_inYield )
1416 {
1417 if ( !onlyIfNeeded )
1418 {
1419 wxFAIL_MSG( wxT("wxYield called recursively" ) );
1420 }
1421
1422 return FALSE;
1423 }
1424
1425 s_inYield = TRUE;
1426
1427 // we don't want to process WM_QUIT from here - it should be processed in
1428 // the main event loop in order to stop it
1429 MSG msg;
1430 while ( PeekMessage(&msg, (HWND)0, 0, 0, PM_NOREMOVE) &&
1431 msg.message != WM_QUIT )
1432 {
1433 #if wxUSE_THREADS
1434 wxMutexGuiLeaveOrEnter();
1435 #endif // wxUSE_THREADS
1436
1437 if ( !wxTheApp->DoMessage() )
1438 break;
1439 }
1440
1441 // if there are pending events, we must process them.
1442 ProcessPendingEvents();
1443
1444 // let the logs be flashed again
1445 wxLog::Resume();
1446
1447 s_inYield = FALSE;
1448
1449 return TRUE;
1450 }
1451
1452 bool wxHandleFatalExceptions(bool doit)
1453 {
1454 #if wxUSE_ON_FATAL_EXCEPTION
1455 // assume this can only be called from the main thread
1456 gs_handleExceptions = doit;
1457
1458 return TRUE;
1459 #else
1460 wxFAIL_MSG(_T("set wxUSE_ON_FATAL_EXCEPTION to 1 to use this function"));
1461
1462 (void)doit;
1463 return FALSE;
1464 #endif
1465 }
1466
1467 //-----------------------------------------------------------------------------
1468 // wxWakeUpIdle
1469 //-----------------------------------------------------------------------------
1470
1471 void wxWakeUpIdle()
1472 {
1473 // Send the top window a dummy message so idle handler processing will
1474 // start up again. Doing it this way ensures that the idle handler
1475 // wakes up in the right thread (see also wxWakeUpMainThread() which does
1476 // the same for the main app thread only)
1477 wxWindow *topWindow = wxTheApp->GetTopWindow();
1478 if ( topWindow )
1479 {
1480 if ( !::PostMessage(GetHwndOf(topWindow), WM_NULL, 0, 0) )
1481 {
1482 // should never happen
1483 wxLogLastError(wxT("PostMessage(WM_NULL)"));
1484 }
1485 }
1486 }
1487
1488 //-----------------------------------------------------------------------------
1489
1490 wxIcon
1491 wxApp::GetStdIcon(int which) const
1492 {
1493 switch(which)
1494 {
1495 case wxICON_INFORMATION:
1496 return wxIcon("wxICON_INFO");
1497
1498 case wxICON_QUESTION:
1499 return wxIcon("wxICON_QUESTION");
1500
1501 case wxICON_EXCLAMATION:
1502 return wxIcon("wxICON_WARNING");
1503
1504 default:
1505 wxFAIL_MSG(wxT("requested non existent standard icon"));
1506 // still fall through
1507
1508 case wxICON_HAND:
1509 return wxIcon("wxICON_ERROR");
1510 }
1511 }
1512
1513 // For some reason, with MSVC++ 1.5, WinMain isn't linked in properly
1514 // if in a separate file. So include it here to ensure it's linked.
1515 #if (defined(__VISUALC__) && !defined(__WIN32__)) || (defined(__GNUWIN32__) && !defined(__TWIN32__) && !defined(WXMAKINGDLL))
1516 #include "main.cpp"
1517 #endif