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"
49 #if defined(__WIN95__) && !defined(__GNUWIN32__)
53 // use debug CRT functions for memory leak detections in VC++ if we're not
54 // using wxWindows own methods
55 #if defined(__WXDEBUG__) && defined(_MSC_VER) && !wxUSE_GLOBAL_MEMORY_OPERATORS && !defined(__NO_VC_CRTDBG__)
56 #define wxUSE_VC_CRTDBG
58 #undef wxUSE_VC_CRTDBG
61 #ifdef wxUSE_VC_CRTDBG
62 // VC++ uses this macro as debug/release mode indicator
67 /* Need to undef new if including crtdbg.h */
74 #if defined(__WXDEBUG__) && wxUSE_GLOBAL_MEMORY_OPERATORS && wxUSE_DEBUG_NEW_ALWAYS
75 #define new new(__FILE__,__LINE__)
80 extern char *wxBuffer
;
81 extern char *wxOsVersion
;
82 extern wxList
*wxWinHandleList
;
83 extern wxList wxPendingDelete
;
84 extern void wxSetKeyboardHook(bool doIt
);
85 extern wxCursor
*g_globalCursor
;
87 HINSTANCE wxhInstance
= 0;
88 static MSG s_currentMsg
;
89 wxApp
*wxTheApp
= NULL
;
91 // @@ why not const? and not static?
92 char wxFrameClassName
[] = "wxFrameClass";
93 char wxMDIFrameClassName
[] = "wxMDIFrameClass";
94 char wxMDIChildFrameClassName
[] = "wxMDIChildFrameClass";
95 char wxPanelClassName
[] = "wxPanelClass";
96 char wxCanvasClassName
[] = "wxCanvasClass";
98 HICON wxSTD_FRAME_ICON
= NULL
;
99 HICON wxSTD_MDICHILDFRAME_ICON
= NULL
;
100 HICON wxSTD_MDIPARENTFRAME_ICON
= NULL
;
102 HICON wxDEFAULT_FRAME_ICON
= NULL
;
103 HICON wxDEFAULT_MDICHILDFRAME_ICON
= NULL
;
104 HICON wxDEFAULT_MDIPARENTFRAME_ICON
= NULL
;
106 HBRUSH wxDisableButtonBrush
= 0;
108 LRESULT APIENTRY
wxWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
110 #if !USE_SHARED_LIBRARY
111 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
113 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
114 EVT_IDLE(wxApp::OnIdle
)
115 EVT_END_SESSION(wxApp::OnEndSession
)
116 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
)
120 long wxApp::sm_lastMessageTime
= 0;
123 static HINSTANCE gs_hRichEdit
= NULL
;
128 bool wxApp::Initialize()
130 // Some people may wish to use this, but
131 // probably it shouldn't be here by default.
133 // wxRedirectIOToConsole();
136 wxBuffer
= new char[1500];
138 #ifdef wxUSE_VC_CRTDBG
139 // do check for memory leaks on program exit
140 // (another useful flag is _CRTDBG_DELAY_FREE_MEM_DF which doesn't free
141 // deallocated memory which may be used to simulate low-memory condition)
142 _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG
) | _CRTDBG_LEAK_CHECK_DF
);
143 #endif // debug build under MS VC++
145 wxClassInfo::InitializeClasses();
148 wxGetResource("wxWindows", "OsVersion", &wxOsVersion
);
151 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
152 wxTheColourDatabase
->Initialize();
154 wxInitializeStockLists();
155 wxInitializeStockObjects();
157 #if wxUSE_WX_RESOURCES
158 wxInitializeResourceSystem();
161 wxBitmap::InitStandardHandlers();
163 #if defined(__WIN95__)
164 InitCommonControls();
165 gs_hRichEdit
= LoadLibrary("RICHED32.DLL");
167 if (gs_hRichEdit
== NULL
)
169 wxMessageBox("Could not initialise Rich Edit DLL");
175 // for OLE, enlarge message queue to be as large as possible
176 while (!SetMessageQueue(iMsg
) && (iMsg
-= 8));
180 dwOleVer = CoBuildVersion();
182 // check the OLE library version
183 if (rmm != HIWORD(dwOleVer))
185 wxMessageBox("Incorrect version of OLE libraries.");
191 // we need to initialize OLE library
192 if ( FAILED(::OleInitialize(NULL
)) )
193 wxFatalError(_("Cannot initialize OLE"));
197 if (!Ctl3dRegister(wxhInstance
))
198 wxFatalError("Cannot register CTL3D");
200 Ctl3dAutoSubclass(wxhInstance
);
203 g_globalCursor
= new wxCursor
;
205 wxSTD_FRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_FRAME");
206 wxSTD_MDIPARENTFRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_MDIPARENTFRAME");
207 wxSTD_MDICHILDFRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_MDICHILDFRAME");
209 wxDEFAULT_FRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_FRAME");
210 wxDEFAULT_MDIPARENTFRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_MDIPARENTFRAME");
211 wxDEFAULT_MDICHILDFRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_MDICHILDFRAME");
213 RegisterWindowClasses();
215 // Create the brush for disabling bitmap buttons
218 lb
.lbStyle
= BS_PATTERN
;
219 lb
.lbHatch
= (int)LoadBitmap( wxhInstance
, "wxDISABLE_BUTTON_BITMAP" ) ;
220 wxDisableButtonBrush
= ::CreateBrushIndirect( & lb
) ;
221 ::DeleteObject( (HGDIOBJ
)lb
.lbHatch
) ;
227 wxWinHandleList
= new wxList(wxKEY_INTEGER
);
229 // This is to foil optimizations in Visual C++ that
230 // throw out dummy.obj.
231 #if (_MSC_VER >= 800) && !defined(WXMAKINGDLL)
232 extern char wxDummyChar
;
233 if (wxDummyChar
) wxDummyChar
++;
236 wxSetKeyboardHook(TRUE
);
238 wxModule::RegisterModules();
239 if (!wxModule::InitializeModules())
244 //// RegisterWindowClasses
246 bool wxApp::RegisterWindowClasses()
248 ///////////////////////////////////////////////////////////////////////
249 // Register the frame window class.
250 WNDCLASS wndclass
; // Structure used to register Windows class.
252 wndclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
253 wndclass
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
254 wndclass
.cbClsExtra
= 0;
255 wndclass
.cbWndExtra
= sizeof( DWORD
); // was 4
256 wndclass
.hInstance
= wxhInstance
;
257 wndclass
.hIcon
= NULL
; // wxSTD_FRAME_ICON;
258 wndclass
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
259 wndclass
.hbrBackground
= (HBRUSH
)(COLOR_APPWORKSPACE
+1) ;
260 // wndclass.hbrBackground = GetStockObject( WHITE_BRUSH );
261 wndclass
.lpszMenuName
= NULL
;
262 #ifdef _MULTIPLE_INSTANCES
263 sprintf( wxFrameClassName
,"wxFrameClass%d", wxhInstance
);
265 wndclass
.lpszClassName
= wxFrameClassName
;
267 if (!RegisterClass( &wndclass
))
269 // wxFatalError("Can't register Frame Window class");
272 ///////////////////////////////////////////////////////////////////////
273 // Register the MDI frame window class.
274 WNDCLASS wndclass1
; // Structure used to register Windows class.
276 wndclass1
.style
= CS_HREDRAW
| CS_VREDRAW
;
277 wndclass1
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
278 wndclass1
.cbClsExtra
= 0;
279 wndclass1
.cbWndExtra
= sizeof( DWORD
); // was 4
280 wndclass1
.hInstance
= wxhInstance
;
281 wndclass1
.hIcon
= NULL
; // wxSTD_MDIPARENTFRAME_ICON;
282 wndclass1
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
283 // wndclass1.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1) ;
284 wndclass1
.hbrBackground
= NULL
;
285 wndclass1
.lpszMenuName
= NULL
;
287 wndclass1
.lpszClassName
= wxMDIFrameClassName
;
288 if (!RegisterClass( &wndclass1
))
290 // wxFatalError("Can't register MDI Frame window class");
294 ///////////////////////////////////////////////////////////////////////
295 // Register the MDI child frame window class.
296 WNDCLASS wndclass4
; // Structure used to register Windows class.
298 wndclass4
.style
= CS_HREDRAW
| CS_VREDRAW
;
299 wndclass4
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
300 wndclass4
.cbClsExtra
= 0;
301 wndclass4
.cbWndExtra
= sizeof( DWORD
); // was 4
302 wndclass4
.hInstance
= wxhInstance
;
303 wndclass4
.hIcon
= NULL
; // wxSTD_MDICHILDFRAME_ICON;
304 wndclass4
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
305 // TODO: perhaps this should be NULL so that Windows doesn't
306 // paint the background itself (would OnEraseBackground duplicate
308 wndclass4
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1) ;
309 // wndclass4.hbrBackground = NULL;
310 wndclass4
.lpszMenuName
= NULL
;
311 wndclass4
.lpszClassName
= wxMDIChildFrameClassName
;
313 if (!RegisterClass( &wndclass4
))
315 // wxFatalError("Can't register MDI child frame window class");
319 ///////////////////////////////////////////////////////////////////////
320 // Register the panel window class.
321 WNDCLASS wndclass2
; // Structure used to register Windows class.
322 memset(&wndclass2
, 0, sizeof(WNDCLASS
)); // start with NULL defaults
323 // Use CS_OWNDC to avoid messing about restoring the context
324 // for every graphic operation.
325 wndclass2
.style
= CS_HREDRAW
| CS_VREDRAW
;
326 wndclass2
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
327 wndclass2
.cbClsExtra
= 0;
328 wndclass2
.cbWndExtra
= sizeof( DWORD
); // was 4
329 wndclass2
.hInstance
= wxhInstance
;
330 wndclass2
.hIcon
= NULL
;
331 wndclass2
.hCursor
= NULL
;
332 // wndclass2.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1) ;
333 wndclass2
.hbrBackground
= (HBRUSH
) GetStockObject( LTGRAY_BRUSH
);
334 wndclass2
.lpszMenuName
= NULL
;
335 wndclass2
.lpszClassName
= wxPanelClassName
;
336 if (!RegisterClass( &wndclass2
))
338 // wxFatalError("Can't register Panel Window class");
342 ///////////////////////////////////////////////////////////////////////
343 // Register the canvas and textsubwindow class name
344 WNDCLASS wndclass3
; // Structure used to register Windows class.
345 memset(&wndclass3
, 0, sizeof(WNDCLASS
)); // start with NULL defaults
346 // Use CS_OWNDC to avoid messing about restoring the context
347 // for every graphic operation.
348 // wndclass3.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS ;
350 wndclass3
.style
= CS_HREDRAW
| CS_VREDRAW
| CS_DBLCLKS
;
351 wndclass3
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
352 wndclass3
.cbClsExtra
= 0;
353 wndclass3
.cbWndExtra
= sizeof( DWORD
); // was 4
354 wndclass3
.hInstance
= wxhInstance
;
355 wndclass3
.hIcon
= NULL
;
356 wndclass3
.hCursor
= NULL
;
357 // wndclass3.hbrBackground = (HBRUSH)(COLOR_WINDOW+1) ;
358 wndclass3
.hbrBackground
= NULL
;
359 wndclass3
.lpszMenuName
= NULL
;
360 wndclass3
.lpszClassName
= wxCanvasClassName
;
361 if (!RegisterClass( &wndclass3
))
363 // wxFatalError("Can't register Canvas class");
370 //// Convert Windows to argc, argv style
372 void wxApp::ConvertToStandardCommandArgs(char* lpCmdLine
)
376 wxString
cmdLine(lpCmdLine
);
379 // Get application name
380 char name
[260]; // 260 is MAX_PATH value from windef.h
381 ::GetModuleFileName(wxhInstance
, name
, WXSIZEOF(name
));
383 // GNUWIN32 already fills in the first arg with the application name.
384 #if !defined(__GNUWIN32__)
389 strcpy(name
, wxFileNameFromPath(name
));
390 wxStripExtension(name
);
391 wxTheApp
->SetAppName(name
);
394 // Treat strings enclosed in double-quotes as single arguments
396 int len
= cmdLine
.Length();
400 while ((i
< len
) && isspace(cmdLine
.GetChar(i
)))
405 if (cmdLine
.GetChar(i
) == '"') // We found the start of a string
409 while ((i
< len
) && (cmdLine
.GetChar(i
) != '"'))
412 wxString
arg(cmdLine
.Mid(first
, (i
- first
)));
418 i
++; // Skip past 2nd quote
420 else // Unquoted argument
423 while ((i
< len
) && !isspace(cmdLine
.GetChar(i
)))
426 wxString
arg(cmdLine
.Mid(first
, (i
- first
)));
434 wxTheApp
->argv
= new char*[count
+ 1];
435 for (i
= 0; i
< count
; i
++)
437 wxString
arg(args
[i
]);
438 wxTheApp
->argv
[i
] = copystring((const char*)arg
);
440 wxTheApp
->argv
[count
] = NULL
; // argv[] is a NULL-terminated list
441 wxTheApp
->argc
= count
;
444 //// Cleans up any wxWindows internal structures left lying around
446 void wxApp::CleanUp()
449 wxModule::CleanUpModules();
451 #if wxUSE_WX_RESOURCES
452 wxCleanUpResourceSystem();
454 // wxDefaultResourceTable->ClearTable();
457 // Indicate that the cursor can be freed,
458 // so that cursor won't be deleted by deleting
459 // the bitmap list before g_globalCursor goes out
460 // of scope (double deletion of the cursor).
461 wxSetCursor(wxNullCursor
);
462 delete g_globalCursor
;
464 wxDeleteStockObjects() ;
466 // Destroy all GDI lists, etc.
467 wxDeleteStockLists();
469 delete wxTheColourDatabase
;
470 wxTheColourDatabase
= NULL
;
472 wxBitmap::CleanUpHandlers();
477 //// WINDOWS-SPECIFIC CLEANUP
479 wxSetKeyboardHook(FALSE
);
482 if (gs_hRichEdit
!= NULL
)
483 FreeLibrary(gs_hRichEdit
);
490 if (wxSTD_FRAME_ICON
)
491 DestroyIcon(wxSTD_FRAME_ICON
);
492 if (wxSTD_MDICHILDFRAME_ICON
)
493 DestroyIcon(wxSTD_MDICHILDFRAME_ICON
);
494 if (wxSTD_MDIPARENTFRAME_ICON
)
495 DestroyIcon(wxSTD_MDIPARENTFRAME_ICON
);
497 if (wxDEFAULT_FRAME_ICON
)
498 DestroyIcon(wxDEFAULT_FRAME_ICON
);
499 if (wxDEFAULT_MDICHILDFRAME_ICON
)
500 DestroyIcon(wxDEFAULT_MDICHILDFRAME_ICON
);
501 if (wxDEFAULT_MDIPARENTFRAME_ICON
)
502 DestroyIcon(wxDEFAULT_MDIPARENTFRAME_ICON
);
504 if ( wxDisableButtonBrush
)
505 ::DeleteObject( wxDisableButtonBrush
) ;
512 Ctl3dUnregister(wxhInstance
);
516 delete wxWinHandleList
;
518 wxClassInfo::CleanUpClasses();
523 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
524 // At this point we want to check if there are any memory
525 // blocks that aren't part of the wxDebugContext itself,
526 // as a special case. Then when dumping we need to ignore
527 // wxDebugContext, too.
528 if (wxDebugContext::CountObjectsLeft() > 0)
530 wxLogDebug("There were memory leaks.");
531 wxDebugContext::Dump();
532 wxDebugContext::PrintStatistics();
534 // wxDebugContext::SetStream(NULL, NULL);
537 // do it as the very last thing because everything else can log messages
538 wxLog::DontCreateOnDemand();
539 delete wxLog::SetActiveTarget(NULL
);
542 #if !defined(_WINDLL) || (defined(_WINDLL) && defined(WXMAKINGDLL))
544 //// Main wxWindows entry point
545 int wxEntry(WXHINSTANCE hInstance
,
546 WXHINSTANCE
WXUNUSED(hPrevInstance
),
551 #ifndef __WXDEBUG__ // take everything into a try-except block in release build
555 wxhInstance
= (HINSTANCE
) hInstance
;
557 if (!wxApp::Initialize())
560 // create the application object or ensure that one already exists
563 // The app may have declared a global application object, but we recommend
564 // the IMPLEMENT_APP macro is used instead, which sets an initializer
565 // function for delayed, dynamic app object construction.
566 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
567 "No initializer - use IMPLEMENT_APP macro." );
569 wxTheApp
= (*wxApp::GetInitializerFunction()) ();
572 wxCHECK_MSG( wxTheApp
, 0, "You have to define an instance of wxApp!" );
574 // save the WinMain() parameters
575 wxTheApp
->ConvertToStandardCommandArgs(lpCmdLine
);
576 wxTheApp
->m_nCmdShow
= nCmdShow
;
578 // GUI-specific initialisation. In fact on Windows we don't have any,
579 // but this call is provided for compatibility across platforms.
580 wxTheApp
->OnInitGui() ;
584 if ( wxTheApp
->OnInit() )
588 retValue
= wxTheApp
->OnRun();
591 //else: app initialization failed, so we skipped OnRun()
593 wxWindow
*topWindow
= wxTheApp
->GetTopWindow();
596 // Forcibly delete the window.
597 if ( topWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
598 topWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
600 topWindow
->Close(TRUE
);
601 wxTheApp
->DeletePendingObjects();
606 wxTheApp
->SetTopWindow(NULL
);
612 // flush the logged messages if any
613 wxLog
*pLog
= wxLog::GetActiveTarget();
614 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
621 #ifndef __WXDEBUG__ // catch exceptions only in release build
623 except ( EXCEPTION_EXECUTE_HANDLER
) {
626 wxTheApp->OnFatalException();
629 ::ExitProcess(3); // the same exit code as abort()
636 //// Entry point for DLLs
638 int wxEntry(WXHINSTANCE hInstance
)
640 wxhInstance
= (HINSTANCE
) hInstance
;
643 // The app may have declared a global application object, but we recommend
644 // the IMPLEMENT_APP macro is used instead, which sets an initializer function
645 // for delayed, dynamic app object construction.
649 if (!wxApp::GetInitializerFunction())
651 MessageBox(NULL
, "No initializer - use IMPLEMENT_APP macro.", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
655 wxTheApp
= (* wxApp::GetInitializerFunction()) ();
659 MessageBox(NULL
, "You have to define an instance of wxApp!", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
664 wxTheApp
->argv
= NULL
;
666 wxTheApp
->OnInitGui();
670 if (wxTheApp
->GetTopWindow() && wxTheApp
->GetTopWindow()->GetHWND()) {
671 wxTheApp
->GetTopWindow()->Show(TRUE
);
678 //// Static member initialization
680 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
687 m_wantDebugOutput
= TRUE
;
692 m_printMode
= wxPRINT_WINDOWS
;
694 m_printMode
= wxPRINT_POSTSCRIPT
;
696 m_exitOnFrameDelete
= TRUE
;
702 // Delete command-line args
704 for (i
= 0; i
< argc
; i
++)
711 bool wxApp::Initialized()
719 #ifdef _WINDLL // Assume initialized if DLL (no way of telling)
725 * Get and process a message, returning FALSE if WM_QUIT
729 bool wxApp::DoMessage()
731 if (!::GetMessage(&s_currentMsg
, (HWND
) NULL
, 0, 0))
736 // Process the message
737 if (!ProcessMessage((WXMSG
*)&s_currentMsg
))
739 ::TranslateMessage(&s_currentMsg
);
740 wxApp::sm_lastMessageTime
= s_currentMsg
.time
; /* MATTHEW: timeStamp impl. */
741 ::DispatchMessage(&s_currentMsg
);
747 * Keep trying to process messages until WM_QUIT
750 * If there are messages to be processed, they will all be
751 * processed and OnIdle will not be called.
752 * When there are no more messages, OnIdle is called.
753 * If OnIdle requests more time,
754 * it will be repeatedly called so long as there are no pending messages.
755 * A 'feature' of this is that once OnIdle has decided that no more processing
756 * is required, then it won't get processing time until further messages
757 * are processed (it'll sit in DoMessage).
760 int wxApp::MainLoop()
765 while (!::PeekMessage(&s_currentMsg
, 0, 0, 0, PM_NOREMOVE
) &&
771 return s_currentMsg
.wParam
;
774 // Returns TRUE if more time is needed.
775 bool wxApp::ProcessIdle()
778 event
.SetEventObject(this);
781 return event
.MoreRequested();
784 void wxApp::ExitMainLoop()
789 bool wxApp::Pending()
791 return (::PeekMessage(&s_currentMsg
, 0, 0, 0, PM_NOREMOVE
) != 0) ;
794 void wxApp::Dispatch()
801 * Give all windows a chance to preprocess
802 * the message. Some may have accelerator tables, or have
805 bool wxApp::ProcessMessage(WXMSG
*Msg
)
807 MSG
*msg
= (MSG
*)Msg
;
811 // Try translations first; find the youngest window with
812 // a translation table.
813 for (hWnd
= msg
->hwnd
; hWnd
!= NULL
; hWnd
= ::GetParent(hWnd
))
815 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
818 if (wnd
->MSWTranslateMessage(Msg
))
823 // Anyone for a non-translation message? Try youngest descendants first.
824 for (hWnd
= msg
->hwnd
; hWnd
!= NULL
; hWnd
= ::GetParent(hWnd
))
826 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
829 if (wnd
->MSWProcessMessage(Msg
))
836 void wxApp::OnIdle(wxIdleEvent
& event
)
838 static bool inOnIdle
= FALSE
;
840 // Avoid recursion (via ProcessEvent default case)
846 // 'Garbage' collection of windows deleted with Close().
847 DeletePendingObjects();
849 // flush the logged messages if any
850 wxLog
*pLog
= wxLog::GetActiveTarget();
851 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
854 // Send OnIdle events to all windows
855 bool needMore
= SendIdleEvents();
856 // bool needMore = FALSE;
859 event
.RequestMore(TRUE
);
864 // Send idle event to all top-level windows
865 bool wxApp::SendIdleEvents()
867 bool needMore
= FALSE
;
868 wxNode
* node
= wxTopLevelWindows
.First();
871 wxWindow
* win
= (wxWindow
*) node
->Data();
872 if (SendIdleEvents(win
))
880 // Send idle event to window and all subwindows
881 bool wxApp::SendIdleEvents(wxWindow
* win
)
883 bool needMore
= FALSE
;
886 event
.SetEventObject(win
);
887 win
->GetEventHandler()->ProcessEvent(event
);
889 if (event
.MoreRequested())
892 wxNode
* node
= win
->GetChildren().First();
895 wxWindow
* win
= (wxWindow
*) node
->Data();
896 if (SendIdleEvents(win
))
904 void wxApp::DeletePendingObjects()
906 wxNode
*node
= wxPendingDelete
.First();
909 wxObject
*obj
= (wxObject
*)node
->Data();
913 if (wxPendingDelete
.Member(obj
))
916 // Deleting one object may have deleted other pending
917 // objects, so start from beginning of list again.
918 node
= wxPendingDelete
.First();
922 void wxApp::OnEndSession(wxCloseEvent
& event
)
925 GetTopWindow()->Close(TRUE
);
928 // Default behaviour: close the application with prompts. The
929 // user can veto the close, and therefore the end session.
930 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
934 if (!GetTopWindow()->Close(!event
.CanVeto()))
939 wxLog
* wxApp::CreateLogTarget()
944 wxWindow
* wxApp::GetTopWindow() const
948 else if (wxTopLevelWindows
.Number() > 0)
949 return (wxWindow
*) wxTopLevelWindows
.First()->Data();
954 int wxApp::GetComCtl32Version() const
956 // have we loaded COMCTL32 yet?
957 HMODULE theModule
= ::GetModuleHandle("COMCTL32");
960 // if so, then we can check for the version
963 // InitCommonControlsEx is unique to 4.7 and later
964 FARPROC theProc
= ::GetProcAddress(theModule
, "InitCommonControlsEx");
967 { // not found, must be 4.00
972 // The following symbol are unique to 4.71
974 // FlatSB_EnableScrollBar FlatSB_GetScrollInfo FlatSB_GetScrollPos
975 // FlatSB_GetScrollProp FlatSB_GetScrollRange FlatSB_SetScrollInfo
976 // FlatSB_SetScrollPos FlatSB_SetScrollProp FlatSB_SetScrollRange
977 // FlatSB_ShowScrollBar
978 // _DrawIndirectImageList _DuplicateImageList
980 // UninitializeFlatSB
981 // we could check for any of these - I chose DllInstall
982 FARPROC theProc
= ::GetProcAddress(theModule
, "DllInstall");
985 // not found, must be 4.70
989 { // found, must be 4.71
1000 FatalAppExit(0, "Fatal error: exiting");
1003 // Yield to incoming messages
1007 // We want to go back to the main message loop
1008 // if we see a WM_QUIT. (?)
1009 while (PeekMessage(&msg
, NULL
, 0, 0, PM_NOREMOVE
) && msg
.message
!= WM_QUIT
)
1011 if (!wxTheApp
->DoMessage())
1018 HINSTANCE
wxGetInstance()
1023 // For some reason, with MSVC++ 1.5, WinMain isn't linked in properly
1024 // if in a separate file. So include it here to ensure it's linked.
1025 #if (defined(_MSC_VER) && !defined(__WIN32__)) || defined(__GNUWIN32__)