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