1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "app.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
19 #if defined(__BORLANDC__)
27 #include "wx/gdicmn.h"
30 #include "wx/cursor.h"
32 #include "wx/palette.h"
34 #include "wx/dialog.h"
35 #include "wx/msgdlg.h"
38 #include "wx/msw/private.h"
40 #include "wx/module.h"
42 #if wxUSE_WX_RESOURCES
43 #include "wx/resource.h"
50 #if defined(__WIN95__) && !defined(__GNUWIN32__)
54 // use debug CRT functions for memory leak detections in VC++ if we're not
55 // using wxWindows own methods
56 #if defined(__WXDEBUG__) && defined(_MSC_VER) && !wxUSE_GLOBAL_MEMORY_OPERATORS && !defined(__NO_VC_CRTDBG__)
57 #define wxUSE_VC_CRTDBG
59 #undef wxUSE_VC_CRTDBG
62 #ifdef wxUSE_VC_CRTDBG
63 // VC++ uses this macro as debug/release mode indicator
68 /* Need to undef new if including crtdbg.h */
75 #if defined(__WXDEBUG__) && wxUSE_GLOBAL_MEMORY_OPERATORS && wxUSE_DEBUG_NEW_ALWAYS
76 #define new new(__FILE__,__LINE__)
81 extern char *wxBuffer
;
82 extern char *wxOsVersion
;
83 extern wxList
*wxWinHandleList
;
84 extern wxList wxPendingDelete
;
85 extern void wxSetKeyboardHook(bool doIt
);
86 extern wxCursor
*g_globalCursor
;
88 HINSTANCE wxhInstance
= 0;
89 static MSG s_currentMsg
;
90 wxApp
*wxTheApp
= NULL
;
92 // @@ why not const? and not static?
93 char wxFrameClassName
[] = "wxFrameClass";
94 char wxMDIFrameClassName
[] = "wxMDIFrameClass";
95 char wxMDIChildFrameClassName
[] = "wxMDIChildFrameClass";
96 char wxPanelClassName
[] = "wxPanelClass";
97 char wxCanvasClassName
[] = "wxCanvasClass";
99 HICON wxSTD_FRAME_ICON
= NULL
;
100 HICON wxSTD_MDICHILDFRAME_ICON
= NULL
;
101 HICON wxSTD_MDIPARENTFRAME_ICON
= NULL
;
103 HICON wxDEFAULT_FRAME_ICON
= NULL
;
104 HICON wxDEFAULT_MDICHILDFRAME_ICON
= NULL
;
105 HICON wxDEFAULT_MDIPARENTFRAME_ICON
= NULL
;
107 HBRUSH wxDisableButtonBrush
= 0;
109 LRESULT APIENTRY
wxWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
111 #if !USE_SHARED_LIBRARY
112 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
114 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
115 EVT_IDLE(wxApp::OnIdle
)
116 EVT_END_SESSION(wxApp::OnEndSession
)
117 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
)
121 long wxApp::sm_lastMessageTime
= 0;
124 static HINSTANCE gs_hRichEdit
= NULL
;
129 bool wxApp::Initialize()
131 // Some people may wish to use this, but
132 // probably it shouldn't be here by default.
134 // wxRedirectIOToConsole();
137 wxBuffer
= new char[1500];
139 #ifdef wxUSE_VC_CRTDBG
140 // do check for memory leaks on program exit
141 // (another useful flag is _CRTDBG_DELAY_FREE_MEM_DF which doesn't free
142 // deallocated memory which may be used to simulate low-memory condition)
143 _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG
) | _CRTDBG_LEAK_CHECK_DF
);
144 #endif // debug build under MS VC++
146 wxClassInfo::InitializeClasses();
149 wxGetResource("wxWindows", "OsVersion", &wxOsVersion
);
152 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
153 wxTheColourDatabase
->Initialize();
155 wxInitializeStockLists();
156 wxInitializeStockObjects();
158 #if wxUSE_WX_RESOURCES
159 wxInitializeResourceSystem();
162 wxBitmap::InitStandardHandlers();
164 #if defined(__WIN95__)
165 InitCommonControls();
166 gs_hRichEdit
= LoadLibrary("RICHED32.DLL");
168 if (gs_hRichEdit
== NULL
)
170 wxMessageBox("Could not initialise Rich Edit DLL");
176 // for OLE, enlarge message queue to be as large as possible
177 while (!SetMessageQueue(iMsg
) && (iMsg
-= 8));
181 dwOleVer = CoBuildVersion();
183 // check the OLE library version
184 if (rmm != HIWORD(dwOleVer))
186 wxMessageBox("Incorrect version of OLE libraries.");
192 // we need to initialize OLE library
193 if ( FAILED(::OleInitialize(NULL
)) )
194 wxFatalError(_("Cannot initialize OLE"));
198 if (!Ctl3dRegister(wxhInstance
))
199 wxFatalError("Cannot register CTL3D");
201 Ctl3dAutoSubclass(wxhInstance
);
204 g_globalCursor
= new wxCursor
;
206 wxSTD_FRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_FRAME");
207 wxSTD_MDIPARENTFRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_MDIPARENTFRAME");
208 wxSTD_MDICHILDFRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_MDICHILDFRAME");
210 wxDEFAULT_FRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_FRAME");
211 wxDEFAULT_MDIPARENTFRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_MDIPARENTFRAME");
212 wxDEFAULT_MDICHILDFRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_MDICHILDFRAME");
214 RegisterWindowClasses();
216 // Create the brush for disabling bitmap buttons
219 lb
.lbStyle
= BS_PATTERN
;
220 lb
.lbHatch
= (int)LoadBitmap( wxhInstance
, "wxDISABLE_BUTTON_BITMAP" ) ;
221 wxDisableButtonBrush
= ::CreateBrushIndirect( & lb
) ;
222 ::DeleteObject( (HGDIOBJ
)lb
.lbHatch
) ;
228 wxWinHandleList
= new wxList(wxKEY_INTEGER
);
230 // This is to foil optimizations in Visual C++ that
231 // throw out dummy.obj.
232 #if (_MSC_VER >= 800) && !defined(WXMAKINGDLL)
233 extern char wxDummyChar
;
234 if (wxDummyChar
) wxDummyChar
++;
237 wxSetKeyboardHook(TRUE
);
239 wxModule::RegisterModules();
240 if (!wxModule::InitializeModules())
245 //// RegisterWindowClasses
247 bool wxApp::RegisterWindowClasses()
249 ///////////////////////////////////////////////////////////////////////
250 // Register the frame window class.
251 WNDCLASS wndclass
; // Structure used to register Windows class.
253 wndclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
254 wndclass
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
255 wndclass
.cbClsExtra
= 0;
256 wndclass
.cbWndExtra
= sizeof( DWORD
); // was 4
257 wndclass
.hInstance
= wxhInstance
;
258 wndclass
.hIcon
= NULL
; // wxSTD_FRAME_ICON;
259 wndclass
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
260 wndclass
.hbrBackground
= (HBRUSH
)(COLOR_APPWORKSPACE
+1) ;
261 // wndclass.hbrBackground = GetStockObject( WHITE_BRUSH );
262 wndclass
.lpszMenuName
= NULL
;
263 #ifdef _MULTIPLE_INSTANCES
264 sprintf( wxFrameClassName
,"wxFrameClass%d", wxhInstance
);
266 wndclass
.lpszClassName
= wxFrameClassName
;
268 if (!RegisterClass( &wndclass
))
270 // wxFatalError("Can't register Frame Window class");
273 ///////////////////////////////////////////////////////////////////////
274 // Register the MDI frame window class.
275 WNDCLASS wndclass1
; // Structure used to register Windows class.
277 wndclass1
.style
= CS_HREDRAW
| CS_VREDRAW
;
278 wndclass1
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
279 wndclass1
.cbClsExtra
= 0;
280 wndclass1
.cbWndExtra
= sizeof( DWORD
); // was 4
281 wndclass1
.hInstance
= wxhInstance
;
282 wndclass1
.hIcon
= NULL
; // wxSTD_MDIPARENTFRAME_ICON;
283 wndclass1
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
284 // wndclass1.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1) ;
285 wndclass1
.hbrBackground
= NULL
;
286 wndclass1
.lpszMenuName
= NULL
;
288 wndclass1
.lpszClassName
= wxMDIFrameClassName
;
289 if (!RegisterClass( &wndclass1
))
291 // wxFatalError("Can't register MDI Frame window class");
295 ///////////////////////////////////////////////////////////////////////
296 // Register the MDI child frame window class.
297 WNDCLASS wndclass4
; // Structure used to register Windows class.
299 wndclass4
.style
= CS_HREDRAW
| CS_VREDRAW
;
300 wndclass4
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
301 wndclass4
.cbClsExtra
= 0;
302 wndclass4
.cbWndExtra
= sizeof( DWORD
); // was 4
303 wndclass4
.hInstance
= wxhInstance
;
304 wndclass4
.hIcon
= NULL
; // wxSTD_MDICHILDFRAME_ICON;
305 wndclass4
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
306 // TODO: perhaps this should be NULL so that Windows doesn't
307 // paint the background itself (would OnEraseBackground duplicate
309 wndclass4
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1) ;
310 // wndclass4.hbrBackground = NULL;
311 wndclass4
.lpszMenuName
= NULL
;
312 wndclass4
.lpszClassName
= wxMDIChildFrameClassName
;
314 if (!RegisterClass( &wndclass4
))
316 // wxFatalError("Can't register MDI child frame window class");
320 ///////////////////////////////////////////////////////////////////////
321 // Register the panel window class.
322 WNDCLASS wndclass2
; // Structure used to register Windows class.
323 memset(&wndclass2
, 0, sizeof(WNDCLASS
)); // start with NULL defaults
324 // Use CS_OWNDC to avoid messing about restoring the context
325 // for every graphic operation.
326 wndclass2
.style
= CS_HREDRAW
| CS_VREDRAW
;
327 wndclass2
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
328 wndclass2
.cbClsExtra
= 0;
329 wndclass2
.cbWndExtra
= sizeof( DWORD
); // was 4
330 wndclass2
.hInstance
= wxhInstance
;
331 wndclass2
.hIcon
= NULL
;
332 wndclass2
.hCursor
= NULL
;
333 // wndclass2.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1) ;
334 wndclass2
.hbrBackground
= (HBRUSH
) GetStockObject( LTGRAY_BRUSH
);
335 wndclass2
.lpszMenuName
= NULL
;
336 wndclass2
.lpszClassName
= wxPanelClassName
;
337 if (!RegisterClass( &wndclass2
))
339 // wxFatalError("Can't register Panel Window class");
343 ///////////////////////////////////////////////////////////////////////
344 // Register the canvas and textsubwindow class name
345 WNDCLASS wndclass3
; // Structure used to register Windows class.
346 memset(&wndclass3
, 0, sizeof(WNDCLASS
)); // start with NULL defaults
347 // Use CS_OWNDC to avoid messing about restoring the context
348 // for every graphic operation.
349 // wndclass3.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS ;
351 wndclass3
.style
= CS_HREDRAW
| CS_VREDRAW
| CS_DBLCLKS
;
352 wndclass3
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
353 wndclass3
.cbClsExtra
= 0;
354 wndclass3
.cbWndExtra
= sizeof( DWORD
); // was 4
355 wndclass3
.hInstance
= wxhInstance
;
356 wndclass3
.hIcon
= NULL
;
357 wndclass3
.hCursor
= NULL
;
358 // wndclass3.hbrBackground = (HBRUSH)(COLOR_WINDOW+1) ;
359 wndclass3
.hbrBackground
= NULL
;
360 wndclass3
.lpszMenuName
= NULL
;
361 wndclass3
.lpszClassName
= wxCanvasClassName
;
362 if (!RegisterClass( &wndclass3
))
364 // wxFatalError("Can't register Canvas class");
371 //// Convert Windows to argc, argv style
373 void wxApp::ConvertToStandardCommandArgs(char* lpCmdLine
)
377 wxString
cmdLine(lpCmdLine
);
380 // Get application name
381 char name
[260]; // 260 is MAX_PATH value from windef.h
382 ::GetModuleFileName(wxhInstance
, name
, WXSIZEOF(name
));
384 // GNUWIN32 already fills in the first arg with the application name.
385 #if !defined(__GNUWIN32__)
390 strcpy(name
, wxFileNameFromPath(name
));
391 wxStripExtension(name
);
392 wxTheApp
->SetAppName(name
);
395 // Treat strings enclosed in double-quotes as single arguments
397 int len
= cmdLine
.Length();
401 while ((i
< len
) && isspace(cmdLine
.GetChar(i
)))
406 if (cmdLine
.GetChar(i
) == '"') // We found the start of a string
410 while ((i
< len
) && (cmdLine
.GetChar(i
) != '"'))
413 wxString
arg(cmdLine
.Mid(first
, (i
- first
)));
419 i
++; // Skip past 2nd quote
421 else // Unquoted argument
424 while ((i
< len
) && !isspace(cmdLine
.GetChar(i
)))
427 wxString
arg(cmdLine
.Mid(first
, (i
- first
)));
435 wxTheApp
->argv
= new char*[count
+ 1];
436 for (i
= 0; i
< count
; i
++)
438 wxString
arg(args
[i
]);
439 wxTheApp
->argv
[i
] = copystring((const char*)arg
);
441 wxTheApp
->argv
[count
] = NULL
; // argv[] is a NULL-terminated list
442 wxTheApp
->argc
= count
;
445 //// Cleans up any wxWindows internal structures left lying around
447 void wxApp::CleanUp()
450 wxModule::CleanUpModules();
452 #if wxUSE_WX_RESOURCES
453 wxCleanUpResourceSystem();
455 // wxDefaultResourceTable->ClearTable();
458 // Indicate that the cursor can be freed,
459 // so that cursor won't be deleted by deleting
460 // the bitmap list before g_globalCursor goes out
461 // of scope (double deletion of the cursor).
462 wxSetCursor(wxNullCursor
);
463 delete g_globalCursor
;
465 wxDeleteStockObjects() ;
467 // Destroy all GDI lists, etc.
468 wxDeleteStockLists();
470 delete wxTheColourDatabase
;
471 wxTheColourDatabase
= NULL
;
473 wxBitmap::CleanUpHandlers();
478 //// WINDOWS-SPECIFIC CLEANUP
480 wxSetKeyboardHook(FALSE
);
483 if (gs_hRichEdit
!= NULL
)
484 FreeLibrary(gs_hRichEdit
);
491 if (wxSTD_FRAME_ICON
)
492 DestroyIcon(wxSTD_FRAME_ICON
);
493 if (wxSTD_MDICHILDFRAME_ICON
)
494 DestroyIcon(wxSTD_MDICHILDFRAME_ICON
);
495 if (wxSTD_MDIPARENTFRAME_ICON
)
496 DestroyIcon(wxSTD_MDIPARENTFRAME_ICON
);
498 if (wxDEFAULT_FRAME_ICON
)
499 DestroyIcon(wxDEFAULT_FRAME_ICON
);
500 if (wxDEFAULT_MDICHILDFRAME_ICON
)
501 DestroyIcon(wxDEFAULT_MDICHILDFRAME_ICON
);
502 if (wxDEFAULT_MDIPARENTFRAME_ICON
)
503 DestroyIcon(wxDEFAULT_MDIPARENTFRAME_ICON
);
505 if ( wxDisableButtonBrush
)
506 ::DeleteObject( wxDisableButtonBrush
) ;
513 Ctl3dUnregister(wxhInstance
);
517 delete wxWinHandleList
;
519 wxClassInfo::CleanUpClasses();
524 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
525 // At this point we want to check if there are any memory
526 // blocks that aren't part of the wxDebugContext itself,
527 // as a special case. Then when dumping we need to ignore
528 // wxDebugContext, too.
529 if (wxDebugContext::CountObjectsLeft() > 0)
531 wxLogDebug("There were memory leaks.");
532 wxDebugContext::Dump();
533 wxDebugContext::PrintStatistics();
535 // wxDebugContext::SetStream(NULL, NULL);
538 // do it as the very last thing because everything else can log messages
539 wxLog::DontCreateOnDemand();
540 delete wxLog::SetActiveTarget(NULL
);
543 #if !defined(_WINDLL) || (defined(_WINDLL) && defined(WXMAKINGDLL))
545 //// Main wxWindows entry point
546 int wxEntry(WXHINSTANCE hInstance
,
547 WXHINSTANCE
WXUNUSED(hPrevInstance
),
552 #ifndef __WXDEBUG__ // take everything into a try-except block in release build
556 wxhInstance
= (HINSTANCE
) hInstance
;
558 if (!wxApp::Initialize())
561 // create the application object or ensure that one already exists
564 // The app may have declared a global application object, but we recommend
565 // the IMPLEMENT_APP macro is used instead, which sets an initializer
566 // function for delayed, dynamic app object construction.
567 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
568 "No initializer - use IMPLEMENT_APP macro." );
570 wxTheApp
= (*wxApp::GetInitializerFunction()) ();
573 wxCHECK_MSG( wxTheApp
, 0, "You have to define an instance of wxApp!" );
575 // save the WinMain() parameters
576 wxTheApp
->ConvertToStandardCommandArgs(lpCmdLine
);
577 wxTheApp
->m_nCmdShow
= nCmdShow
;
579 // GUI-specific initialisation. In fact on Windows we don't have any,
580 // but this call is provided for compatibility across platforms.
581 wxTheApp
->OnInitGui() ;
585 if ( wxTheApp
->OnInit() )
589 retValue
= wxTheApp
->OnRun();
592 //else: app initialization failed, so we skipped OnRun()
594 wxWindow
*topWindow
= wxTheApp
->GetTopWindow();
597 // Forcibly delete the window.
598 if ( topWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
599 topWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
601 topWindow
->Close(TRUE
);
602 wxTheApp
->DeletePendingObjects();
607 wxTheApp
->SetTopWindow(NULL
);
613 // flush the logged messages if any
614 wxLog
*pLog
= wxLog::GetActiveTarget();
615 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
622 #ifndef __WXDEBUG__ // catch exceptions only in release build
624 except ( EXCEPTION_EXECUTE_HANDLER
) {
627 wxTheApp->OnFatalException();
630 ::ExitProcess(3); // the same exit code as abort()
637 //// Entry point for DLLs
639 int wxEntry(WXHINSTANCE hInstance
)
641 wxhInstance
= (HINSTANCE
) hInstance
;
644 // The app may have declared a global application object, but we recommend
645 // the IMPLEMENT_APP macro is used instead, which sets an initializer function
646 // for delayed, dynamic app object construction.
650 if (!wxApp::GetInitializerFunction())
652 MessageBox(NULL
, "No initializer - use IMPLEMENT_APP macro.", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
656 wxTheApp
= (* wxApp::GetInitializerFunction()) ();
660 MessageBox(NULL
, "You have to define an instance of wxApp!", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
665 wxTheApp
->argv
= NULL
;
667 wxTheApp
->OnInitGui();
671 if (wxTheApp
->GetTopWindow() && wxTheApp
->GetTopWindow()->GetHWND()) {
672 wxTheApp
->GetTopWindow()->Show(TRUE
);
679 //// Static member initialization
681 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
688 m_wantDebugOutput
= TRUE
;
693 m_printMode
= wxPRINT_WINDOWS
;
695 m_printMode
= wxPRINT_POSTSCRIPT
;
697 m_exitOnFrameDelete
= TRUE
;
703 // Delete command-line args
705 for (i
= 0; i
< argc
; i
++)
712 bool wxApp::Initialized()
720 #ifdef _WINDLL // Assume initialized if DLL (no way of telling)
726 * Get and process a message, returning FALSE if WM_QUIT
730 bool wxApp::DoMessage()
732 if (!::GetMessage(&s_currentMsg
, (HWND
) NULL
, 0, 0))
737 // Process the message
738 if (!ProcessMessage((WXMSG
*)&s_currentMsg
))
740 ::TranslateMessage(&s_currentMsg
);
741 wxApp::sm_lastMessageTime
= s_currentMsg
.time
; /* MATTHEW: timeStamp impl. */
742 ::DispatchMessage(&s_currentMsg
);
748 * Keep trying to process messages until WM_QUIT
751 * If there are messages to be processed, they will all be
752 * processed and OnIdle will not be called.
753 * When there are no more messages, OnIdle is called.
754 * If OnIdle requests more time,
755 * it will be repeatedly called so long as there are no pending messages.
756 * A 'feature' of this is that once OnIdle has decided that no more processing
757 * is required, then it won't get processing time until further messages
758 * are processed (it'll sit in DoMessage).
761 int wxApp::MainLoop()
766 while (!::PeekMessage(&s_currentMsg
, 0, 0, 0, PM_NOREMOVE
) &&
772 return s_currentMsg
.wParam
;
775 // Returns TRUE if more time is needed.
776 bool wxApp::ProcessIdle()
779 event
.SetEventObject(this);
782 return event
.MoreRequested();
785 void wxApp::ExitMainLoop()
790 bool wxApp::Pending()
792 return (::PeekMessage(&s_currentMsg
, 0, 0, 0, PM_NOREMOVE
) != 0) ;
795 void wxApp::Dispatch()
802 * Give all windows a chance to preprocess
803 * the message. Some may have accelerator tables, or have
806 bool wxApp::ProcessMessage(WXMSG
*Msg
)
808 MSG
*msg
= (MSG
*)Msg
;
812 // Try translations first; find the youngest window with
813 // a translation table.
814 for (hWnd
= msg
->hwnd
; hWnd
!= NULL
; hWnd
= ::GetParent(hWnd
))
816 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
819 if (wnd
->MSWTranslateMessage(Msg
))
824 // Anyone for a non-translation message? Try youngest descendants first.
825 for (hWnd
= msg
->hwnd
; hWnd
!= NULL
; hWnd
= ::GetParent(hWnd
))
827 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
830 if (wnd
->MSWProcessMessage(Msg
))
837 void wxApp::OnIdle(wxIdleEvent
& event
)
839 static bool inOnIdle
= FALSE
;
841 // Avoid recursion (via ProcessEvent default case)
847 // 'Garbage' collection of windows deleted with Close().
848 DeletePendingObjects();
850 // flush the logged messages if any
851 wxLog
*pLog
= wxLog::GetActiveTarget();
852 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
855 // Send OnIdle events to all windows
856 bool needMore
= SendIdleEvents();
857 // bool needMore = FALSE;
860 event
.RequestMore(TRUE
);
865 // Send idle event to all top-level windows
866 bool wxApp::SendIdleEvents()
868 bool needMore
= FALSE
;
869 wxNode
* node
= wxTopLevelWindows
.First();
872 wxWindow
* win
= (wxWindow
*) node
->Data();
873 if (SendIdleEvents(win
))
881 // Send idle event to window and all subwindows
882 bool wxApp::SendIdleEvents(wxWindow
* win
)
884 bool needMore
= FALSE
;
887 event
.SetEventObject(win
);
888 win
->GetEventHandler()->ProcessEvent(event
);
890 if (event
.MoreRequested())
893 wxNode
* node
= win
->GetChildren().First();
896 wxWindow
* win
= (wxWindow
*) node
->Data();
897 if (SendIdleEvents(win
))
905 void wxApp::DeletePendingObjects()
907 wxNode
*node
= wxPendingDelete
.First();
910 wxObject
*obj
= (wxObject
*)node
->Data();
914 if (wxPendingDelete
.Member(obj
))
917 // Deleting one object may have deleted other pending
918 // objects, so start from beginning of list again.
919 node
= wxPendingDelete
.First();
923 void wxApp::OnEndSession(wxCloseEvent
& event
)
926 GetTopWindow()->Close(TRUE
);
929 // Default behaviour: close the application with prompts. The
930 // user can veto the close, and therefore the end session.
931 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
935 if (!GetTopWindow()->Close(!event
.CanVeto()))
940 wxLog
* wxApp::CreateLogTarget()
945 wxWindow
* wxApp::GetTopWindow() const
949 else if (wxTopLevelWindows
.Number() > 0)
950 return (wxWindow
*) wxTopLevelWindows
.First()->Data();
955 int wxApp::GetComCtl32Version() const
957 // have we loaded COMCTL32 yet?
958 HMODULE theModule
= ::GetModuleHandle("COMCTL32");
961 // if so, then we can check for the version
964 // InitCommonControlsEx is unique to 4.7 and later
965 FARPROC theProc
= ::GetProcAddress(theModule
, "InitCommonControlsEx");
968 { // not found, must be 4.00
973 // The following symbol are unique to 4.71
975 // FlatSB_EnableScrollBar FlatSB_GetScrollInfo FlatSB_GetScrollPos
976 // FlatSB_GetScrollProp FlatSB_GetScrollRange FlatSB_SetScrollInfo
977 // FlatSB_SetScrollPos FlatSB_SetScrollProp FlatSB_SetScrollRange
978 // FlatSB_ShowScrollBar
979 // _DrawIndirectImageList _DuplicateImageList
981 // UninitializeFlatSB
982 // we could check for any of these - I chose DllInstall
983 FARPROC theProc
= ::GetProcAddress(theModule
, "DllInstall");
986 // not found, must be 4.70
990 { // found, must be 4.71
1001 FatalAppExit(0, "Fatal error: exiting");
1004 // Yield to incoming messages
1008 // We want to go back to the main message loop
1009 // if we see a WM_QUIT. (?)
1010 while (PeekMessage(&msg
, NULL
, 0, 0, PM_NOREMOVE
) && msg
.message
!= WM_QUIT
)
1012 if (!wxTheApp
->DoMessage())
1019 HINSTANCE
wxGetInstance()
1024 // For some reason, with MSVC++ 1.5, WinMain isn't linked in properly
1025 // if in a separate file. So include it here to ensure it's linked.
1026 #if (defined(_MSC_VER) && !defined(__WIN32__)) || defined(__GNUWIN32__)