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"
46 #if wxUSE_DRAG_AND_DROP
52 #if defined(__WIN95__) && !defined(__GNUWIN32__)
56 // use debug CRT functions for memory leak detections in VC++ if we're not
57 // using wxWindows own methods
58 #if defined(__WXDEBUG__) && defined(_MSC_VER) && !wxUSE_GLOBAL_MEMORY_OPERATORS && !defined(__NO_VC_CRTDBG__)
59 #define wxUSE_VC_CRTDBG
61 #undef wxUSE_VC_CRTDBG
64 #ifdef wxUSE_VC_CRTDBG
65 // VC++ uses this macro as debug/release mode indicator
70 /* Need to undef new if including crtdbg.h */
77 #if defined(__WXDEBUG__) && wxUSE_GLOBAL_MEMORY_OPERATORS && wxUSE_DEBUG_NEW_ALWAYS
78 #define new new(__FILE__,__LINE__)
83 extern char *wxBuffer
;
84 extern char *wxOsVersion
;
85 extern wxList
*wxWinHandleList
;
86 extern wxList wxPendingDelete
;
87 extern void wxSetKeyboardHook(bool doIt
);
88 extern wxCursor
*g_globalCursor
;
90 HINSTANCE wxhInstance
= 0;
91 static MSG s_currentMsg
;
92 wxApp
*wxTheApp
= NULL
;
94 // @@ why not const? and not static?
95 char wxFrameClassName
[] = "wxFrameClass";
96 char wxMDIFrameClassName
[] = "wxMDIFrameClass";
97 char wxMDIChildFrameClassName
[] = "wxMDIChildFrameClass";
98 char wxPanelClassName
[] = "wxPanelClass";
99 char wxCanvasClassName
[] = "wxCanvasClass";
101 HICON wxSTD_FRAME_ICON
= NULL
;
102 HICON wxSTD_MDICHILDFRAME_ICON
= NULL
;
103 HICON wxSTD_MDIPARENTFRAME_ICON
= NULL
;
105 HICON wxDEFAULT_FRAME_ICON
= NULL
;
106 HICON wxDEFAULT_MDICHILDFRAME_ICON
= NULL
;
107 HICON wxDEFAULT_MDIPARENTFRAME_ICON
= NULL
;
109 HBRUSH wxDisableButtonBrush
= 0;
111 LRESULT APIENTRY
wxWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
113 #if !USE_SHARED_LIBRARY
114 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
116 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
117 EVT_IDLE(wxApp::OnIdle
)
118 EVT_END_SESSION(wxApp::OnEndSession
)
119 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
)
123 long wxApp::sm_lastMessageTime
= 0;
126 static HINSTANCE gs_hRichEdit
= NULL
;
131 bool wxApp::Initialize()
133 // Some people may wish to use this, but
134 // probably it shouldn't be here by default.
136 // wxRedirectIOToConsole();
139 wxBuffer
= new char[1500];
141 #ifdef wxUSE_VC_CRTDBG
142 // do check for memory leaks on program exit
143 // (another useful flag is _CRTDBG_DELAY_FREE_MEM_DF which doesn't free
144 // deallocated memory which may be used to simulate low-memory condition)
145 _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG
) | _CRTDBG_LEAK_CHECK_DF
);
146 #endif // debug build under MS VC++
148 wxClassInfo::InitializeClasses();
151 wxGetResource("wxWindows", "OsVersion", &wxOsVersion
);
154 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
155 wxTheColourDatabase
->Initialize();
157 wxInitializeStockLists();
158 wxInitializeStockObjects();
160 #if wxUSE_WX_RESOURCES
161 wxInitializeResourceSystem();
164 wxBitmap::InitStandardHandlers();
166 #if defined(__WIN95__)
167 InitCommonControls();
168 gs_hRichEdit
= LoadLibrary("RICHED32.DLL");
170 if (gs_hRichEdit
== NULL
)
172 wxMessageBox("Could not initialise Rich Edit DLL");
178 // for OLE, enlarge message queue to be as large as possible
179 while (!SetMessageQueue(iMsg
) && (iMsg
-= 8));
183 dwOleVer = CoBuildVersion();
185 // check the OLE library version
186 if (rmm != HIWORD(dwOleVer))
188 wxMessageBox("Incorrect version of OLE libraries.");
194 // we need to initialize OLE library
195 if ( FAILED(::OleInitialize(NULL
)) )
196 wxFatalError(_("Cannot initialize OLE"));
200 if (!Ctl3dRegister(wxhInstance
))
201 wxFatalError("Cannot register CTL3D");
203 Ctl3dAutoSubclass(wxhInstance
);
206 g_globalCursor
= new wxCursor
;
208 wxSTD_FRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_FRAME");
209 wxSTD_MDIPARENTFRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_MDIPARENTFRAME");
210 wxSTD_MDICHILDFRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_MDICHILDFRAME");
212 wxDEFAULT_FRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_FRAME");
213 wxDEFAULT_MDIPARENTFRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_MDIPARENTFRAME");
214 wxDEFAULT_MDICHILDFRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_MDICHILDFRAME");
216 RegisterWindowClasses();
218 // Create the brush for disabling bitmap buttons
221 lb
.lbStyle
= BS_PATTERN
;
222 lb
.lbHatch
= (int)LoadBitmap( wxhInstance
, "wxDISABLE_BUTTON_BITMAP" ) ;
223 wxDisableButtonBrush
= ::CreateBrushIndirect( & lb
) ;
224 ::DeleteObject( (HGDIOBJ
)lb
.lbHatch
) ;
230 wxWinHandleList
= new wxList(wxKEY_INTEGER
);
232 // This is to foil optimizations in Visual C++ that
233 // throw out dummy.obj.
234 #if (_MSC_VER >= 800) && !defined(WXMAKINGDLL)
235 extern char wxDummyChar
;
236 if (wxDummyChar
) wxDummyChar
++;
239 wxSetKeyboardHook(TRUE
);
241 wxModule::RegisterModules();
242 if (!wxModule::InitializeModules())
247 //// RegisterWindowClasses
249 bool wxApp::RegisterWindowClasses()
251 ///////////////////////////////////////////////////////////////////////
252 // Register the frame window class.
253 WNDCLASS wndclass
; // Structure used to register Windows class.
255 wndclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
256 wndclass
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
257 wndclass
.cbClsExtra
= 0;
258 wndclass
.cbWndExtra
= sizeof( DWORD
); // was 4
259 wndclass
.hInstance
= wxhInstance
;
260 wndclass
.hIcon
= NULL
; // wxSTD_FRAME_ICON;
261 wndclass
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
262 wndclass
.hbrBackground
= (HBRUSH
)(COLOR_APPWORKSPACE
+1) ;
263 // wndclass.hbrBackground = GetStockObject( WHITE_BRUSH );
264 wndclass
.lpszMenuName
= NULL
;
265 #ifdef _MULTIPLE_INSTANCES
266 sprintf( wxFrameClassName
,"wxFrameClass%d", wxhInstance
);
268 wndclass
.lpszClassName
= wxFrameClassName
;
270 if (!RegisterClass( &wndclass
))
272 // wxFatalError("Can't register Frame Window class");
275 ///////////////////////////////////////////////////////////////////////
276 // Register the MDI frame window class.
277 WNDCLASS wndclass1
; // Structure used to register Windows class.
279 wndclass1
.style
= CS_HREDRAW
| CS_VREDRAW
;
280 wndclass1
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
281 wndclass1
.cbClsExtra
= 0;
282 wndclass1
.cbWndExtra
= sizeof( DWORD
); // was 4
283 wndclass1
.hInstance
= wxhInstance
;
284 wndclass1
.hIcon
= NULL
; // wxSTD_MDIPARENTFRAME_ICON;
285 wndclass1
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
286 // wndclass1.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1) ;
287 wndclass1
.hbrBackground
= NULL
;
288 wndclass1
.lpszMenuName
= NULL
;
290 wndclass1
.lpszClassName
= wxMDIFrameClassName
;
291 if (!RegisterClass( &wndclass1
))
293 // wxFatalError("Can't register MDI Frame window class");
297 ///////////////////////////////////////////////////////////////////////
298 // Register the MDI child frame window class.
299 WNDCLASS wndclass4
; // Structure used to register Windows class.
301 wndclass4
.style
= CS_HREDRAW
| CS_VREDRAW
;
302 wndclass4
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
303 wndclass4
.cbClsExtra
= 0;
304 wndclass4
.cbWndExtra
= sizeof( DWORD
); // was 4
305 wndclass4
.hInstance
= wxhInstance
;
306 wndclass4
.hIcon
= NULL
; // wxSTD_MDICHILDFRAME_ICON;
307 wndclass4
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
308 // TODO: perhaps this should be NULL so that Windows doesn't
309 // paint the background itself (would OnEraseBackground duplicate
311 wndclass4
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1) ;
312 // wndclass4.hbrBackground = NULL;
313 wndclass4
.lpszMenuName
= NULL
;
314 wndclass4
.lpszClassName
= wxMDIChildFrameClassName
;
316 if (!RegisterClass( &wndclass4
))
318 // wxFatalError("Can't register MDI child frame window class");
322 ///////////////////////////////////////////////////////////////////////
323 // Register the panel window class.
324 WNDCLASS wndclass2
; // Structure used to register Windows class.
325 memset(&wndclass2
, 0, sizeof(WNDCLASS
)); // start with NULL defaults
326 // Use CS_OWNDC to avoid messing about restoring the context
327 // for every graphic operation.
328 wndclass2
.style
= CS_HREDRAW
| CS_VREDRAW
;
329 wndclass2
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
330 wndclass2
.cbClsExtra
= 0;
331 wndclass2
.cbWndExtra
= sizeof( DWORD
); // was 4
332 wndclass2
.hInstance
= wxhInstance
;
333 wndclass2
.hIcon
= NULL
;
334 wndclass2
.hCursor
= NULL
;
335 // wndclass2.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1) ;
336 wndclass2
.hbrBackground
= (HBRUSH
) GetStockObject( LTGRAY_BRUSH
);
337 wndclass2
.lpszMenuName
= NULL
;
338 wndclass2
.lpszClassName
= wxPanelClassName
;
339 if (!RegisterClass( &wndclass2
))
341 // wxFatalError("Can't register Panel Window class");
345 ///////////////////////////////////////////////////////////////////////
346 // Register the canvas and textsubwindow class name
347 WNDCLASS wndclass3
; // Structure used to register Windows class.
348 memset(&wndclass3
, 0, sizeof(WNDCLASS
)); // start with NULL defaults
349 // Use CS_OWNDC to avoid messing about restoring the context
350 // for every graphic operation.
351 // wndclass3.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS ;
353 wndclass3
.style
= CS_HREDRAW
| CS_VREDRAW
| CS_DBLCLKS
;
354 wndclass3
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
355 wndclass3
.cbClsExtra
= 0;
356 wndclass3
.cbWndExtra
= sizeof( DWORD
); // was 4
357 wndclass3
.hInstance
= wxhInstance
;
358 wndclass3
.hIcon
= NULL
;
359 wndclass3
.hCursor
= NULL
;
360 // wndclass3.hbrBackground = (HBRUSH)(COLOR_WINDOW+1) ;
361 wndclass3
.hbrBackground
= NULL
;
362 wndclass3
.lpszMenuName
= NULL
;
363 wndclass3
.lpszClassName
= wxCanvasClassName
;
364 if (!RegisterClass( &wndclass3
))
366 // wxFatalError("Can't register Canvas class");
373 //// Convert Windows to argc, argv style
375 void wxApp::ConvertToStandardCommandArgs(char* lpCmdLine
)
379 wxString
cmdLine(lpCmdLine
);
382 // Get application name
383 char name
[260]; // 260 is MAX_PATH value from windef.h
384 ::GetModuleFileName(wxhInstance
, name
, WXSIZEOF(name
));
386 // GNUWIN32 already fills in the first arg with the application name.
387 #if !defined(__GNUWIN32__)
392 strcpy(name
, wxFileNameFromPath(name
));
393 wxStripExtension(name
);
394 wxTheApp
->SetAppName(name
);
397 // Treat strings enclosed in double-quotes as single arguments
399 int len
= cmdLine
.Length();
403 while ((i
< len
) && isspace(cmdLine
.GetChar(i
)))
408 if (cmdLine
.GetChar(i
) == '"') // We found the start of a string
412 while ((i
< len
) && (cmdLine
.GetChar(i
) != '"'))
415 wxString
arg(cmdLine
.Mid(first
, (i
- first
)));
421 i
++; // Skip past 2nd quote
423 else // Unquoted argument
426 while ((i
< len
) && !isspace(cmdLine
.GetChar(i
)))
429 wxString
arg(cmdLine
.Mid(first
, (i
- first
)));
437 wxTheApp
->argv
= new char*[count
+ 1];
438 for (i
= 0; i
< count
; i
++)
440 wxString
arg(args
[i
]);
441 wxTheApp
->argv
[i
] = copystring((const char*)arg
);
443 wxTheApp
->argv
[count
] = NULL
; // argv[] is a NULL-terminated list
444 wxTheApp
->argc
= count
;
447 //// Cleans up any wxWindows internal structures left lying around
449 void wxApp::CleanUp()
452 wxModule::CleanUpModules();
454 #if wxUSE_WX_RESOURCES
455 wxCleanUpResourceSystem();
457 // wxDefaultResourceTable->ClearTable();
460 // Indicate that the cursor can be freed,
461 // so that cursor won't be deleted by deleting
462 // the bitmap list before g_globalCursor goes out
463 // of scope (double deletion of the cursor).
464 wxSetCursor(wxNullCursor
);
465 delete g_globalCursor
;
467 wxDeleteStockObjects() ;
469 // Destroy all GDI lists, etc.
470 wxDeleteStockLists();
472 delete wxTheColourDatabase
;
473 wxTheColourDatabase
= NULL
;
475 wxBitmap::CleanUpHandlers();
480 //// WINDOWS-SPECIFIC CLEANUP
482 wxSetKeyboardHook(FALSE
);
485 if (gs_hRichEdit
!= NULL
)
486 FreeLibrary(gs_hRichEdit
);
493 if (wxSTD_FRAME_ICON
)
494 DestroyIcon(wxSTD_FRAME_ICON
);
495 if (wxSTD_MDICHILDFRAME_ICON
)
496 DestroyIcon(wxSTD_MDICHILDFRAME_ICON
);
497 if (wxSTD_MDIPARENTFRAME_ICON
)
498 DestroyIcon(wxSTD_MDIPARENTFRAME_ICON
);
500 if (wxDEFAULT_FRAME_ICON
)
501 DestroyIcon(wxDEFAULT_FRAME_ICON
);
502 if (wxDEFAULT_MDICHILDFRAME_ICON
)
503 DestroyIcon(wxDEFAULT_MDICHILDFRAME_ICON
);
504 if (wxDEFAULT_MDIPARENTFRAME_ICON
)
505 DestroyIcon(wxDEFAULT_MDIPARENTFRAME_ICON
);
507 if ( wxDisableButtonBrush
)
508 ::DeleteObject( wxDisableButtonBrush
) ;
515 Ctl3dUnregister(wxhInstance
);
519 delete wxWinHandleList
;
521 wxClassInfo::CleanUpClasses();
526 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
527 // At this point we want to check if there are any memory
528 // blocks that aren't part of the wxDebugContext itself,
529 // as a special case. Then when dumping we need to ignore
530 // wxDebugContext, too.
531 if (wxDebugContext::CountObjectsLeft() > 0)
533 wxLogDebug("There were memory leaks.");
534 wxDebugContext::Dump();
535 wxDebugContext::PrintStatistics();
537 // wxDebugContext::SetStream(NULL, NULL);
540 // do it as the very last thing because everything else can log messages
541 wxLog::DontCreateOnDemand();
542 delete wxLog::SetActiveTarget(NULL
);
545 #if !defined(_WINDLL) || (defined(_WINDLL) && defined(WXMAKINGDLL))
547 //// Main wxWindows entry point
548 int wxEntry(WXHINSTANCE hInstance
,
549 WXHINSTANCE
WXUNUSED(hPrevInstance
),
554 #ifndef __WXDEBUG__ // take everything into a try-except block in release build
558 wxhInstance
= (HINSTANCE
) hInstance
;
560 if (!wxApp::Initialize())
563 // create the application object or ensure that one already exists
566 // The app may have declared a global application object, but we recommend
567 // the IMPLEMENT_APP macro is used instead, which sets an initializer
568 // function for delayed, dynamic app object construction.
569 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
570 "No initializer - use IMPLEMENT_APP macro." );
572 wxTheApp
= (*wxApp::GetInitializerFunction()) ();
575 wxCHECK_MSG( wxTheApp
, 0, "You have to define an instance of wxApp!" );
577 // save the WinMain() parameters
578 wxTheApp
->ConvertToStandardCommandArgs(lpCmdLine
);
579 wxTheApp
->m_nCmdShow
= nCmdShow
;
581 // GUI-specific initialisation. In fact on Windows we don't have any,
582 // but this call is provided for compatibility across platforms.
583 wxTheApp
->OnInitGui() ;
587 if ( wxTheApp
->OnInit() )
591 retValue
= wxTheApp
->OnRun();
594 //else: app initialization failed, so we skipped OnRun()
596 wxWindow
*topWindow
= wxTheApp
->GetTopWindow();
599 // Forcibly delete the window.
600 if ( topWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
601 topWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
603 topWindow
->Close(TRUE
);
604 wxTheApp
->DeletePendingObjects();
609 wxTheApp
->SetTopWindow(NULL
);
615 // flush the logged messages if any
616 wxLog
*pLog
= wxLog::GetActiveTarget();
617 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
624 #ifndef __WXDEBUG__ // catch exceptions only in release build
626 except ( EXCEPTION_EXECUTE_HANDLER
) {
629 wxTheApp->OnFatalException();
632 ::ExitProcess(3); // the same exit code as abort()
639 //// Entry point for DLLs
641 int wxEntry(WXHINSTANCE hInstance
)
643 wxhInstance
= (HINSTANCE
) hInstance
;
646 // The app may have declared a global application object, but we recommend
647 // the IMPLEMENT_APP macro is used instead, which sets an initializer function
648 // for delayed, dynamic app object construction.
652 if (!wxApp::GetInitializerFunction())
654 MessageBox(NULL
, "No initializer - use IMPLEMENT_APP macro.", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
658 wxTheApp
= (* wxApp::GetInitializerFunction()) ();
662 MessageBox(NULL
, "You have to define an instance of wxApp!", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
667 wxTheApp
->argv
= NULL
;
669 wxTheApp
->OnInitGui();
673 if (wxTheApp
->GetTopWindow() && wxTheApp
->GetTopWindow()->GetHWND()) {
674 wxTheApp
->GetTopWindow()->Show(TRUE
);
681 //// Static member initialization
683 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
690 m_wantDebugOutput
= TRUE
;
695 m_printMode
= wxPRINT_WINDOWS
;
697 m_printMode
= wxPRINT_POSTSCRIPT
;
699 m_exitOnFrameDelete
= TRUE
;
705 // Delete command-line args
707 for (i
= 0; i
< argc
; i
++)
714 bool wxApp::Initialized()
722 #ifdef _WINDLL // Assume initialized if DLL (no way of telling)
728 * Get and process a message, returning FALSE if WM_QUIT
732 bool wxApp::DoMessage()
734 if (!::GetMessage(&s_currentMsg
, (HWND
) NULL
, 0, 0))
739 // Process the message
740 if (!ProcessMessage((WXMSG
*)&s_currentMsg
))
742 ::TranslateMessage(&s_currentMsg
);
743 wxApp::sm_lastMessageTime
= s_currentMsg
.time
; /* MATTHEW: timeStamp impl. */
744 ::DispatchMessage(&s_currentMsg
);
750 * Keep trying to process messages until WM_QUIT
753 * If there are messages to be processed, they will all be
754 * processed and OnIdle will not be called.
755 * When there are no more messages, OnIdle is called.
756 * If OnIdle requests more time,
757 * it will be repeatedly called so long as there are no pending messages.
758 * A 'feature' of this is that once OnIdle has decided that no more processing
759 * is required, then it won't get processing time until further messages
760 * are processed (it'll sit in DoMessage).
763 int wxApp::MainLoop()
768 while (!::PeekMessage(&s_currentMsg
, 0, 0, 0, PM_NOREMOVE
) &&
774 return s_currentMsg
.wParam
;
777 // Returns TRUE if more time is needed.
778 bool wxApp::ProcessIdle()
781 event
.SetEventObject(this);
784 return event
.MoreRequested();
787 void wxApp::ExitMainLoop()
792 bool wxApp::Pending()
794 return (::PeekMessage(&s_currentMsg
, 0, 0, 0, PM_NOREMOVE
) != 0) ;
797 void wxApp::Dispatch()
804 * Give all windows a chance to preprocess
805 * the message. Some may have accelerator tables, or have
808 bool wxApp::ProcessMessage(WXMSG
*Msg
)
810 MSG
*msg
= (MSG
*)Msg
;
814 // Try translations first; find the youngest window with
815 // a translation table.
816 for (hWnd
= msg
->hwnd
; hWnd
!= NULL
; hWnd
= ::GetParent(hWnd
))
818 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
821 if (wnd
->MSWTranslateMessage(Msg
))
826 // Anyone for a non-translation message? Try youngest descendants first.
827 for (hWnd
= msg
->hwnd
; hWnd
!= NULL
; hWnd
= ::GetParent(hWnd
))
829 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
832 if (wnd
->MSWProcessMessage(Msg
))
839 void wxApp::OnIdle(wxIdleEvent
& event
)
841 static bool inOnIdle
= FALSE
;
843 // Avoid recursion (via ProcessEvent default case)
849 // 'Garbage' collection of windows deleted with Close().
850 DeletePendingObjects();
852 // flush the logged messages if any
853 wxLog
*pLog
= wxLog::GetActiveTarget();
854 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
857 // Send OnIdle events to all windows
858 bool needMore
= SendIdleEvents();
859 // bool needMore = FALSE;
862 event
.RequestMore(TRUE
);
867 // Send idle event to all top-level windows
868 bool wxApp::SendIdleEvents()
870 bool needMore
= FALSE
;
871 wxNode
* node
= wxTopLevelWindows
.First();
874 wxWindow
* win
= (wxWindow
*) node
->Data();
875 if (SendIdleEvents(win
))
883 // Send idle event to window and all subwindows
884 bool wxApp::SendIdleEvents(wxWindow
* win
)
886 bool needMore
= FALSE
;
889 event
.SetEventObject(win
);
890 win
->GetEventHandler()->ProcessEvent(event
);
892 if (event
.MoreRequested())
895 wxNode
* node
= win
->GetChildren().First();
898 wxWindow
* win
= (wxWindow
*) node
->Data();
899 if (SendIdleEvents(win
))
907 void wxApp::DeletePendingObjects()
909 wxNode
*node
= wxPendingDelete
.First();
912 wxObject
*obj
= (wxObject
*)node
->Data();
916 if (wxPendingDelete
.Member(obj
))
919 // Deleting one object may have deleted other pending
920 // objects, so start from beginning of list again.
921 node
= wxPendingDelete
.First();
925 void wxApp::OnEndSession(wxCloseEvent
& event
)
928 GetTopWindow()->Close(TRUE
);
931 // Default behaviour: close the application with prompts. The
932 // user can veto the close, and therefore the end session.
933 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
937 if (!GetTopWindow()->Close(!event
.CanVeto()))
942 wxLog
* wxApp::CreateLogTarget()
947 wxWindow
* wxApp::GetTopWindow() const
951 else if (wxTopLevelWindows
.Number() > 0)
952 return (wxWindow
*) wxTopLevelWindows
.First()->Data();
957 int wxApp::GetComCtl32Version() const
959 // have we loaded COMCTL32 yet?
960 HMODULE theModule
= ::GetModuleHandle("COMCTL32");
963 // if so, then we can check for the version
966 // InitCommonControlsEx is unique to 4.7 and later
967 FARPROC theProc
= ::GetProcAddress(theModule
, "InitCommonControlsEx");
970 { // not found, must be 4.00
975 // The following symbol are unique to 4.71
977 // FlatSB_EnableScrollBar FlatSB_GetScrollInfo FlatSB_GetScrollPos
978 // FlatSB_GetScrollProp FlatSB_GetScrollRange FlatSB_SetScrollInfo
979 // FlatSB_SetScrollPos FlatSB_SetScrollProp FlatSB_SetScrollRange
980 // FlatSB_ShowScrollBar
981 // _DrawIndirectImageList _DuplicateImageList
983 // UninitializeFlatSB
984 // we could check for any of these - I chose DllInstall
985 FARPROC theProc
= ::GetProcAddress(theModule
, "DllInstall");
988 // not found, must be 4.70
992 { // found, must be 4.71
1003 FatalAppExit(0, "Fatal error: exiting");
1006 // Yield to incoming messages
1010 // We want to go back to the main message loop
1011 // if we see a WM_QUIT. (?)
1012 while (PeekMessage(&msg
, NULL
, 0, 0, PM_NOREMOVE
) && msg
.message
!= WM_QUIT
)
1014 if (!wxTheApp
->DoMessage())
1021 HINSTANCE
wxGetInstance()
1026 // For some reason, with MSVC++ 1.5, WinMain isn't linked in properly
1027 // if in a separate file. So include it here to ensure it's linked.
1028 #if (defined(_MSC_VER) && !defined(__WIN32__)) || defined(__GNUWIN32__)