1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
21 #pragma implementation "app.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
27 #if defined(__BORLANDC__)
35 #include "wx/gdicmn.h"
38 #include "wx/cursor.h"
40 #include "wx/palette.h"
42 #include "wx/dialog.h"
43 #include "wx/msgdlg.h"
45 #include "wx/dynarray.h"
48 #include "wx/msw/private.h"
50 #include "wx/module.h"
53 #include "wx/thread.h"
55 // define the array of MSG strutures
56 WX_DECLARE_OBJARRAY(MSG
, wxMsgArray
);
58 #include "wx/arrimpl.cpp"
60 WX_DEFINE_OBJARRAY(wxMsgArray
);
61 #endif // wxUSE_THREADS
63 #if wxUSE_WX_RESOURCES
64 #include "wx/resource.h"
67 // OLE is used for drag-and-drop, clipboard, OLE Automation...
68 #if defined(__GNUWIN32__) || defined(__SC__) || defined(__SALFORDC__)
72 #endif // broken compilers
81 #if (defined(__WIN95__) && !defined(__GNUWIN32__)) || defined(__TWIN32__)
85 #include "wx/msw/msvcrt.h"
87 // ---------------------------------------------------------------------------
89 // ---------------------------------------------------------------------------
91 extern char *wxBuffer
;
92 extern char *wxOsVersion
;
93 extern wxList
*wxWinHandleList
;
94 extern wxList WXDLLEXPORT wxPendingDelete
;
96 extern wxList
*wxPendingEvents
;
97 extern wxCriticalSection
*wxPendingEventsLocker
;
99 extern void wxSetKeyboardHook(bool doIt
);
100 extern wxCursor
*g_globalCursor
;
102 HINSTANCE wxhInstance
= 0;
104 wxApp
*wxTheApp
= NULL
;
106 // FIXME why not const? and not static?
107 char wxFrameClassName
[] = "wxFrameClass";
108 char wxMDIFrameClassName
[] = "wxMDIFrameClass";
109 char wxMDIChildFrameClassName
[] = "wxMDIChildFrameClass";
110 char wxPanelClassName
[] = "wxPanelClass";
111 char wxCanvasClassName
[] = "wxCanvasClass";
113 HICON wxSTD_FRAME_ICON
= (HICON
) NULL
;
114 HICON wxSTD_MDICHILDFRAME_ICON
= (HICON
) NULL
;
115 HICON wxSTD_MDIPARENTFRAME_ICON
= (HICON
) NULL
;
117 HICON wxDEFAULT_FRAME_ICON
= (HICON
) NULL
;
118 HICON wxDEFAULT_MDICHILDFRAME_ICON
= (HICON
) NULL
;
119 HICON wxDEFAULT_MDIPARENTFRAME_ICON
= (HICON
) NULL
;
121 HBRUSH wxDisableButtonBrush
= (HBRUSH
) 0;
123 LRESULT APIENTRY
wxWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
125 #if defined(__WIN95__) && !defined(__TWIN32__)
126 #define wxUSE_RICHEDIT 1
128 #define wxUSE_RICHEDIT 0
132 static HINSTANCE gs_hRichEdit
= (HINSTANCE
) NULL
;
135 // ===========================================================================
137 // ===========================================================================
139 // ---------------------------------------------------------------------------
141 // ---------------------------------------------------------------------------
143 #if !USE_SHARED_LIBRARY
144 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
146 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
147 EVT_IDLE(wxApp::OnIdle
)
148 EVT_END_SESSION(wxApp::OnEndSession
)
149 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
)
154 bool wxApp::Initialize()
156 // Some people may wish to use this, but
157 // probably it shouldn't be here by default.
159 // wxRedirectIOToConsole();
162 wxBuffer
= new char[1500]; // FIXME
164 wxClassInfo::InitializeClasses();
167 wxGetResource("wxWindows", "OsVersion", &wxOsVersion
);
170 // I'm annoyed ... I don't know where to put this and I don't want to
171 // create a module for that as it's part of the core.
173 wxPendingEvents
= new wxList();
174 wxPendingEventsLocker
= new wxCriticalSection();
177 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
178 wxTheColourDatabase
->Initialize();
180 wxInitializeStockLists();
181 wxInitializeStockObjects();
183 #if wxUSE_WX_RESOURCES
184 wxInitializeResourceSystem();
187 wxBitmap::InitStandardHandlers();
189 #if defined(__WIN95__)
190 InitCommonControls();
193 gs_hRichEdit
= LoadLibrary("RICHED32.DLL");
195 if (gs_hRichEdit
== (HINSTANCE
) NULL
)
197 wxLogError(_("Could not initialise Rich Edit DLL"));
199 #endif // wxUSE_RICHEDIT
203 // for OLE, enlarge message queue to be as large as possible
205 while (!SetMessageQueue(iMsg
) && (iMsg
-= 8));
208 // we need to initialize OLE library
209 if ( FAILED(::OleInitialize(NULL
)) )
210 wxLogError(_("Cannot initialize OLE"));
214 if (!Ctl3dRegister(wxhInstance
))
215 wxLogError("Cannot register CTL3D");
217 Ctl3dAutoSubclass(wxhInstance
);
220 g_globalCursor
= new wxCursor
;
222 wxSTD_FRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_FRAME");
223 wxSTD_MDIPARENTFRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_MDIPARENTFRAME");
224 wxSTD_MDICHILDFRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_MDICHILDFRAME");
226 wxDEFAULT_FRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_FRAME");
227 wxDEFAULT_MDIPARENTFRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_MDIPARENTFRAME");
228 wxDEFAULT_MDICHILDFRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_MDICHILDFRAME");
230 RegisterWindowClasses();
232 // Create the brush for disabling bitmap buttons
235 lb
.lbStyle
= BS_PATTERN
;
236 lb
.lbHatch
= (int)LoadBitmap( wxhInstance
, "wxDISABLE_BUTTON_BITMAP" );
237 wxDisableButtonBrush
= ::CreateBrushIndirect( & lb
);
238 ::DeleteObject( (HGDIOBJ
)lb
.lbHatch
);
244 wxWinHandleList
= new wxList(wxKEY_INTEGER
);
246 // This is to foil optimizations in Visual C++ that throw out dummy.obj.
247 // PLEASE DO NOT ALTER THIS.
248 #if defined(__VISUALC__) && !defined(WXMAKINGDLL)
249 extern char wxDummyChar
;
250 if (wxDummyChar
) wxDummyChar
++;
253 wxSetKeyboardHook(TRUE
);
255 wxModule::RegisterModules();
256 if (!wxModule::InitializeModules())
261 // ---------------------------------------------------------------------------
262 // RegisterWindowClasses
263 // ---------------------------------------------------------------------------
265 bool wxApp::RegisterWindowClasses()
269 // the fields which are common to all classes
270 wndclass
.style
= CS_HREDRAW
| CS_VREDRAW
| CS_DBLCLKS
;
271 wndclass
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
272 wndclass
.cbClsExtra
= 0;
273 wndclass
.cbWndExtra
= sizeof( DWORD
); // what is this DWORD used for?
274 wndclass
.hInstance
= wxhInstance
;
275 wndclass
.hIcon
= (HICON
) NULL
;
276 wndclass
.hCursor
= ::LoadCursor((HINSTANCE
)NULL
, IDC_ARROW
);
277 wndclass
.lpszMenuName
= NULL
;
279 // Register the frame window class.
280 wndclass
.hbrBackground
= (HBRUSH
)(COLOR_APPWORKSPACE
+ 1);
281 #ifdef _MULTIPLE_INSTANCES
282 sprintf( wxFrameClassName
,"wxFrameClass%d", wxhInstance
);
284 wndclass
.lpszClassName
= wxFrameClassName
;
286 if ( !RegisterClass(&wndclass
) )
288 wxLogLastError("RegisterClass(frame)");
293 // Register the MDI frame window class.
294 wndclass
.hbrBackground
= (HBRUSH
)NULL
; // paint MDI frame ourselves
295 wndclass
.lpszClassName
= wxMDIFrameClassName
;
297 if ( !RegisterClass(&wndclass
) )
299 wxLogLastError("RegisterClass(MDI parent)");
304 // Register the MDI child frame window class.
305 wndclass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
306 wndclass
.lpszClassName
= wxMDIChildFrameClassName
;
308 if ( !RegisterClass(&wndclass
) )
310 wxLogLastError("RegisterClass(MDI child)");
315 // Register the panel window class.
316 wndclass
.hbrBackground
= (HBRUSH
) GetStockObject( LTGRAY_BRUSH
);
317 wndclass
.lpszClassName
= wxPanelClassName
;
319 if ( !RegisterClass(&wndclass
) )
321 wxLogLastError("RegisterClass(panel)");
326 // Register the canvas and textsubwindow class name
327 wndclass
.hbrBackground
= (HBRUSH
)NULL
;
328 wndclass
.lpszClassName
= wxCanvasClassName
;
330 if ( !RegisterClass(&wndclass
) )
332 wxLogLastError("RegisterClass(canvas)");
340 // ---------------------------------------------------------------------------
341 // Convert Windows to argc, argv style
342 // ---------------------------------------------------------------------------
344 void wxApp::ConvertToStandardCommandArgs(char* lpCmdLine
)
348 wxString
cmdLine(lpCmdLine
);
351 // Get application name
352 char name
[260]; // 260 is MAX_PATH value from windef.h
353 ::GetModuleFileName(wxhInstance
, name
, WXSIZEOF(name
));
358 strcpy(name
, wxFileNameFromPath(name
));
359 wxStripExtension(name
);
360 wxTheApp
->SetAppName(name
);
363 // Treat strings enclosed in double-quotes as single arguments
365 int len
= cmdLine
.Length();
369 while ((i
< len
) && isspace(cmdLine
.GetChar(i
)))
374 if (cmdLine
.GetChar(i
) == '"') // We found the start of a string
378 while ((i
< len
) && (cmdLine
.GetChar(i
) != '"'))
381 wxString
arg(cmdLine
.Mid(first
, (i
- first
)));
387 i
++; // Skip past 2nd quote
389 else // Unquoted argument
392 while ((i
< len
) && !isspace(cmdLine
.GetChar(i
)))
395 wxString
arg(cmdLine
.Mid(first
, (i
- first
)));
403 wxTheApp
->argv
= new char*[count
+ 1];
404 for (i
= 0; i
< count
; i
++)
406 wxString
arg(args
[i
]);
407 wxTheApp
->argv
[i
] = copystring((const char*)arg
);
409 wxTheApp
->argv
[count
] = NULL
; // argv[] is a NULL-terminated list
410 wxTheApp
->argc
= count
;
413 //// Cleans up any wxWindows internal structures left lying around
415 void wxApp::CleanUp()
419 // flush the logged messages if any and install a 'safer' log target: the
420 // default one (wxLogGui) can't be used after the resources are freed just
421 // below and the user suppliedo ne might be even more unsafe (using any
422 // wxWindows GUI function is unsafe starting from now)
423 wxLog::DontCreateOnDemand();
425 // this will flush the old messages if any
426 delete wxLog::SetActiveTarget(new wxLogStderr
);
428 // One last chance for pending objects to be cleaned up
429 wxTheApp
->DeletePendingObjects();
431 wxModule::CleanUpModules();
433 #if wxUSE_WX_RESOURCES
434 wxCleanUpResourceSystem();
436 // wxDefaultResourceTable->ClearTable();
439 // Indicate that the cursor can be freed, so that cursor won't be deleted
440 // by deleting the bitmap list before g_globalCursor goes out of scope
441 // (double deletion of the cursor).
442 wxSetCursor(wxNullCursor
);
443 delete g_globalCursor
;
444 g_globalCursor
= NULL
;
446 wxDeleteStockObjects();
448 // Destroy all GDI lists, etc.
449 wxDeleteStockLists();
451 delete wxTheColourDatabase
;
452 wxTheColourDatabase
= NULL
;
454 wxBitmap::CleanUpHandlers();
459 //// WINDOWS-SPECIFIC CLEANUP
461 wxSetKeyboardHook(FALSE
);
466 if (gs_hRichEdit
!= (HINSTANCE
) NULL
)
467 FreeLibrary(gs_hRichEdit
);
476 if (wxSTD_FRAME_ICON
)
477 DestroyIcon(wxSTD_FRAME_ICON
);
478 if (wxSTD_MDICHILDFRAME_ICON
)
479 DestroyIcon(wxSTD_MDICHILDFRAME_ICON
);
480 if (wxSTD_MDIPARENTFRAME_ICON
)
481 DestroyIcon(wxSTD_MDIPARENTFRAME_ICON
);
483 if (wxDEFAULT_FRAME_ICON
)
484 DestroyIcon(wxDEFAULT_FRAME_ICON
);
485 if (wxDEFAULT_MDICHILDFRAME_ICON
)
486 DestroyIcon(wxDEFAULT_MDICHILDFRAME_ICON
);
487 if (wxDEFAULT_MDIPARENTFRAME_ICON
)
488 DestroyIcon(wxDEFAULT_MDIPARENTFRAME_ICON
);
490 if ( wxDisableButtonBrush
)
491 ::DeleteObject( wxDisableButtonBrush
);
498 Ctl3dUnregister(wxhInstance
);
502 delete wxWinHandleList
;
504 // GL: I'm annoyed ... I don't know where to put this and I don't want to
505 // create a module for that as it's part of the core.
507 delete wxPendingEvents
;
508 delete wxPendingEventsLocker
;
509 // If we don't do the following, we get an apparent memory leak.
510 ((wxEvtHandler
&) wxDefaultValidator
).ClearEventLocker();
513 wxClassInfo::CleanUpClasses();
518 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
519 // At this point we want to check if there are any memory
520 // blocks that aren't part of the wxDebugContext itself,
521 // as a special case. Then when dumping we need to ignore
522 // wxDebugContext, too.
523 if (wxDebugContext::CountObjectsLeft(TRUE
) > 0)
525 wxLogDebug("There were memory leaks.");
526 wxDebugContext::Dump();
527 wxDebugContext::PrintStatistics();
529 // wxDebugContext::SetStream(NULL, NULL);
532 // do it as the very last thing because everything else can log messages
533 delete wxLog::SetActiveTarget(NULL
);
536 #if !defined(_WINDLL) || (defined(_WINDLL) && defined(WXMAKINGDLL))
538 // temporarily disable this warning which would be generated in release builds
541 #pragma warning(disable: 4715) // not all control paths return a value
544 //// Main wxWindows entry point
545 int wxEntry(WXHINSTANCE hInstance
,
546 WXHINSTANCE
WXUNUSED(hPrevInstance
),
551 // do check for memory leaks on program exit
552 // (another useful flag is _CRTDBG_DELAY_FREE_MEM_DF which doesn't free
553 // deallocated memory which may be used to simulate low-memory condition)
554 wxCrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF
);
556 // take everything into a try-except block in release build
557 // FIXME other compilers must support Win32 SEH (structured exception
558 // handling) too, just find the appropriate keyword in their docs!
559 // Please note that it's _not_ the same as C++ exceptions!
560 #if !defined(__WXDEBUG__) && defined(__VISUALC__)
561 #define CATCH_PROGRAM_EXCEPTIONS
565 #undef CATCH_PROGRAM_EXCEPTIONS
568 wxhInstance
= (HINSTANCE
) hInstance
;
570 if (!wxApp::Initialize())
573 // create the application object or ensure that one already exists
576 // The app may have declared a global application object, but we recommend
577 // the IMPLEMENT_APP macro is used instead, which sets an initializer
578 // function for delayed, dynamic app object construction.
579 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
580 "No initializer - use IMPLEMENT_APP macro." );
582 wxTheApp
= (*wxApp::GetInitializerFunction()) ();
585 wxCHECK_MSG( wxTheApp
, 0, "You have to define an instance of wxApp!" );
587 // save the WinMain() parameters
588 wxTheApp
->ConvertToStandardCommandArgs(lpCmdLine
);
589 wxTheApp
->m_nCmdShow
= nCmdShow
;
591 // GUI-specific initialisation. In fact on Windows we don't have any,
592 // but this call is provided for compatibility across platforms.
593 wxTheApp
->OnInitGui();
597 if ( wxTheApp
->OnInit() )
601 retValue
= wxTheApp
->OnRun();
604 // We want to initialize, but not run or exit immediately.
607 //else: app initialization failed, so we skipped OnRun()
609 wxWindow
*topWindow
= wxTheApp
->GetTopWindow();
612 // Forcibly delete the window.
613 if ( topWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
614 topWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
616 topWindow
->Close(TRUE
);
617 wxTheApp
->DeletePendingObjects();
622 wxTheApp
->SetTopWindow(NULL
);
632 #ifdef CATCH_PROGRAM_EXCEPTIONS
634 __except ( EXCEPTION_EXECUTE_HANDLER
) {
637 wxTheApp->OnFatalException();
640 // using wxLog would be unsafe here
642 _("Unrecoverable program error detected: "
643 " the application will terminate."),
645 MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
647 ::ExitProcess(3); // the same exit code as abort()
651 #endif // CATCH_PROGRAM_EXCEPTIONS
654 // restore warning state
656 #pragma warning(default: 4715) // not all control paths return a value
661 //// Entry point for DLLs
663 int wxEntry(WXHINSTANCE hInstance
)
665 wxhInstance
= (HINSTANCE
) hInstance
;
668 // The app may have declared a global application object, but we recommend
669 // the IMPLEMENT_APP macro is used instead, which sets an initializer function
670 // for delayed, dynamic app object construction.
673 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
674 "No initializer - use IMPLEMENT_APP macro." );
676 wxTheApp
= (* wxApp::GetInitializerFunction()) ();
679 wxCHECK_MSG( wxTheApp
, 0, "You have to define an instance of wxApp!" );
682 wxTheApp
->argv
= NULL
;
684 wxTheApp
->OnInitGui();
688 wxWindow
*topWindow
= wxTheApp
->GetTopWindow();
689 if ( topWindow
&& topWindow
->GetHWND())
691 topWindow
->Show(TRUE
);
698 //// Static member initialization
700 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
706 m_wantDebugOutput
= TRUE
;
710 m_printMode
= wxPRINT_WINDOWS
;
711 m_exitOnFrameDelete
= TRUE
;
717 // Delete command-line args
719 for (i
= 0; i
< argc
; i
++)
726 bool wxApp::Initialized()
734 #ifdef _WINDLL // Assume initialized if DLL (no way of telling)
740 * Get and process a message, returning FALSE if WM_QUIT
741 * received (and also set the flag telling the app to exit the main loop)
744 bool wxApp::DoMessage()
746 BOOL rc
= ::GetMessage(&s_currentMsg
, (HWND
) NULL
, 0, 0);
756 // should never happen, but let's test for it nevertheless
757 wxLogLastError("GetMessage");
762 wxASSERT_MSG( wxThread::IsMain(),
763 "only the main thread can process Windows messages" );
765 static bool s_hadGuiLock
= TRUE
;
766 static wxMsgArray s_aSavedMessages
;
768 // if a secondary thread owns is doing GUI calls, save all messages for
769 // later processing - we can't process them right now because it will
770 // lead to recursive library calls (and we're not reentrant)
771 if ( !wxGuiOwnedByMainThread() )
773 s_hadGuiLock
= FALSE
;
775 // leave out WM_COMMAND messages: too dangerous, sometimes
776 // the message will be processed twice
777 if ( !wxIsWaitingForThread() ||
778 s_currentMsg
.message
!= WM_COMMAND
)
780 s_aSavedMessages
.Add(s_currentMsg
);
787 // have we just regained the GUI lock? if so, post all of the saved
790 // FIXME of course, it's not _exactly_ the same as processing the
791 // messages normally - expect some things to break...
796 size_t count
= s_aSavedMessages
.Count();
797 for ( size_t n
= 0; n
< count
; n
++ )
799 MSG
& msg
= s_aSavedMessages
[n
];
801 if ( !ProcessMessage((WXMSG
*)&msg
) )
803 ::TranslateMessage(&msg
);
804 ::DispatchMessage(&msg
);
808 s_aSavedMessages
.Empty();
811 #endif // wxUSE_THREADS
813 // Process the message
814 if ( !ProcessMessage((WXMSG
*)&s_currentMsg
) )
816 ::TranslateMessage(&s_currentMsg
);
817 ::DispatchMessage(&s_currentMsg
);
825 * Keep trying to process messages until WM_QUIT
828 * If there are messages to be processed, they will all be
829 * processed and OnIdle will not be called.
830 * When there are no more messages, OnIdle is called.
831 * If OnIdle requests more time,
832 * it will be repeatedly called so long as there are no pending messages.
833 * A 'feature' of this is that once OnIdle has decided that no more processing
834 * is required, then it won't get processing time until further messages
835 * are processed (it'll sit in DoMessage).
838 int wxApp::MainLoop()
842 while ( m_keepGoing
)
845 wxMutexGuiLeaveOrEnter();
846 #endif // wxUSE_THREADS
848 while ( !::PeekMessage(&s_currentMsg
, 0, 0, 0, PM_NOREMOVE
) &&
857 return s_currentMsg
.wParam
;
860 // Returns TRUE if more time is needed.
861 bool wxApp::ProcessIdle()
864 event
.SetEventObject(this);
867 return event
.MoreRequested();
871 void wxApp::ProcessPendingEvents()
873 wxNode
*node
= wxPendingEvents
->First();
874 wxCriticalSectionLocker
locker(*wxPendingEventsLocker
);
878 wxEvtHandler
*handler
= (wxEvtHandler
*)node
->Data();
880 handler
->ProcessPendingEvents();
883 node
= wxPendingEvents
->First();
889 void wxApp::ExitMainLoop()
894 bool wxApp::Pending()
896 return (::PeekMessage(&s_currentMsg
, 0, 0, 0, PM_NOREMOVE
) != 0);
899 void wxApp::Dispatch()
905 * Give all windows a chance to preprocess
906 * the message. Some may have accelerator tables, or have
910 bool wxApp::ProcessMessage(WXMSG
*wxmsg
)
912 MSG
*msg
= (MSG
*)wxmsg
;
913 HWND hWnd
= msg
->hwnd
;
914 wxWindow
*wndThis
= wxFindWinFromHandle((WXHWND
)hWnd
), *wnd
;
916 // Try translations first; find the youngest window with
917 // a translation table.
918 for ( wnd
= wndThis
; wnd
; wnd
= wnd
->GetParent() )
920 if ( wnd
->MSWTranslateMessage(wxmsg
) )
924 // Anyone for a non-translation message? Try youngest descendants first.
925 for ( wnd
= wndThis
; wnd
; wnd
= wnd
->GetParent() )
927 if ( wnd
->MSWProcessMessage(wxmsg
) )
934 void wxApp::OnIdle(wxIdleEvent
& event
)
936 static bool s_inOnIdle
= FALSE
;
938 // Avoid recursion (via ProcessEvent default case)
944 // 'Garbage' collection of windows deleted with Close().
945 DeletePendingObjects();
947 // flush the logged messages if any
948 wxLog
*pLog
= wxLog::GetActiveTarget();
949 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
952 // Send OnIdle events to all windows
953 if ( SendIdleEvents() )
955 // SendIdleEvents() returns TRUE if at least one window requested more
957 event
.RequestMore(TRUE
);
960 // If they are pending events, we must process them.
962 ProcessPendingEvents();
967 // Send idle event to all top-level windows
968 bool wxApp::SendIdleEvents()
970 bool needMore
= FALSE
;
972 wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
975 wxWindow
* win
= node
->GetData();
976 if (SendIdleEvents(win
))
978 node
= node
->GetNext();
984 // Send idle event to window and all subwindows
985 bool wxApp::SendIdleEvents(wxWindow
* win
)
987 bool needMore
= FALSE
;
990 event
.SetEventObject(win
);
991 win
->GetEventHandler()->ProcessEvent(event
);
993 if (event
.MoreRequested())
996 wxNode
* node
= win
->GetChildren().First();
999 wxWindow
* win
= (wxWindow
*) node
->Data();
1000 if (SendIdleEvents(win
))
1003 node
= node
->Next();
1008 void wxApp::DeletePendingObjects()
1010 wxNode
*node
= wxPendingDelete
.First();
1013 wxObject
*obj
= (wxObject
*)node
->Data();
1017 if (wxPendingDelete
.Member(obj
))
1020 // Deleting one object may have deleted other pending
1021 // objects, so start from beginning of list again.
1022 node
= wxPendingDelete
.First();
1026 void wxApp::OnEndSession(wxCloseEvent
& WXUNUSED(event
))
1029 GetTopWindow()->Close(TRUE
);
1032 // Default behaviour: close the application with prompts. The
1033 // user can veto the close, and therefore the end session.
1034 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
1038 if (!GetTopWindow()->Close(!event
.CanVeto()))
1043 wxLog
* wxApp::CreateLogTarget()
1045 return new wxLogGui
;
1048 wxWindow
* wxApp::GetTopWindow() const
1052 else if (wxTopLevelWindows
.GetCount() > 0)
1053 return wxTopLevelWindows
.GetFirst()->GetData();
1058 int wxApp::GetComCtl32Version() const
1060 // have we loaded COMCTL32 yet?
1061 HMODULE theModule
= ::GetModuleHandle("COMCTL32");
1064 // if so, then we can check for the version
1067 // InitCommonControlsEx is unique to 4.7 and later
1068 FARPROC theProc
= ::GetProcAddress(theModule
, "InitCommonControlsEx");
1071 { // not found, must be 4.00
1076 // The following symbol are unique to 4.71
1078 // FlatSB_EnableScrollBar FlatSB_GetScrollInfo FlatSB_GetScrollPos
1079 // FlatSB_GetScrollProp FlatSB_GetScrollRange FlatSB_SetScrollInfo
1080 // FlatSB_SetScrollPos FlatSB_SetScrollProp FlatSB_SetScrollRange
1081 // FlatSB_ShowScrollBar
1082 // _DrawIndirectImageList _DuplicateImageList
1084 // UninitializeFlatSB
1085 // we could check for any of these - I chose DllInstall
1086 FARPROC theProc
= ::GetProcAddress(theModule
, "DllInstall");
1089 // not found, must be 4.70
1093 { // found, must be 4.71
1103 wxLogError(_("Fatal error: exiting"));
1108 // Yield to incoming messages
1112 // We want to go back to the main message loop
1113 // if we see a WM_QUIT. (?)
1114 while (PeekMessage(&msg
, NULL
, 0, 0, PM_NOREMOVE
) && msg
.message
!= WM_QUIT
)
1116 if ( !wxTheApp
->DoMessage() )
1119 // If they are pending events, we must process them.
1121 wxTheApp
->ProcessPendingEvents();
1127 HINSTANCE
wxGetInstance()
1132 void wxSetInstance(HINSTANCE hInst
)
1134 wxhInstance
= hInst
;
1137 // For some reason, with MSVC++ 1.5, WinMain isn't linked in properly
1138 // if in a separate file. So include it here to ensure it's linked.
1139 #if (defined(__VISUALC__) && !defined(__WIN32__)) || (defined(__GNUWIN32__) && !defined(__TWIN32__))