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.");
190 // we need to initialize OLE library
191 if ( FAILED(::OleInitialize(NULL
)) )
192 wxFatalError(_("Cannot initialize OLE"));
195 if (!Ctl3dRegister(wxhInstance
))
196 wxFatalError("Cannot register CTL3D");
198 Ctl3dAutoSubclass(wxhInstance
);
201 g_globalCursor
= new wxCursor
;
203 wxSTD_FRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_FRAME");
204 wxSTD_MDIPARENTFRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_MDIPARENTFRAME");
205 wxSTD_MDICHILDFRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_MDICHILDFRAME");
207 wxDEFAULT_FRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_FRAME");
208 wxDEFAULT_MDIPARENTFRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_MDIPARENTFRAME");
209 wxDEFAULT_MDICHILDFRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_MDICHILDFRAME");
211 RegisterWindowClasses();
213 // Create the brush for disabling bitmap buttons
216 lb
.lbStyle
= BS_PATTERN
;
217 lb
.lbHatch
= (int)LoadBitmap( wxhInstance
, "wxDISABLE_BUTTON_BITMAP" ) ;
218 wxDisableButtonBrush
= ::CreateBrushIndirect( & lb
) ;
219 ::DeleteObject( (HGDIOBJ
)lb
.lbHatch
) ;
225 wxWinHandleList
= new wxList(wxKEY_INTEGER
);
227 // This is to foil optimizations in Visual C++ that
228 // throw out dummy.obj.
229 #if (_MSC_VER >= 800) && !defined(WXMAKINGDLL)
230 extern char wxDummyChar
;
231 if (wxDummyChar
) wxDummyChar
++;
234 wxSetKeyboardHook(TRUE
);
236 wxModule::RegisterModules();
237 if (!wxModule::InitializeModules())
242 //// RegisterWindowClasses
244 bool wxApp::RegisterWindowClasses()
246 ///////////////////////////////////////////////////////////////////////
247 // Register the frame window class.
248 WNDCLASS wndclass
; // Structure used to register Windows class.
250 wndclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
251 wndclass
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
252 wndclass
.cbClsExtra
= 0;
253 wndclass
.cbWndExtra
= sizeof( DWORD
); // was 4
254 wndclass
.hInstance
= wxhInstance
;
255 wndclass
.hIcon
= NULL
; // wxSTD_FRAME_ICON;
256 wndclass
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
257 wndclass
.hbrBackground
= (HBRUSH
)(COLOR_APPWORKSPACE
+1) ;
258 // wndclass.hbrBackground = GetStockObject( WHITE_BRUSH );
259 wndclass
.lpszMenuName
= NULL
;
260 #ifdef _MULTIPLE_INSTANCES
261 sprintf( wxFrameClassName
,"wxFrameClass%d", wxhInstance
);
263 wndclass
.lpszClassName
= wxFrameClassName
;
265 if (!RegisterClass( &wndclass
))
267 // wxFatalError("Can't register Frame Window class");
270 ///////////////////////////////////////////////////////////////////////
271 // Register the MDI frame window class.
272 WNDCLASS wndclass1
; // Structure used to register Windows class.
274 wndclass1
.style
= CS_HREDRAW
| CS_VREDRAW
;
275 wndclass1
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
276 wndclass1
.cbClsExtra
= 0;
277 wndclass1
.cbWndExtra
= sizeof( DWORD
); // was 4
278 wndclass1
.hInstance
= wxhInstance
;
279 wndclass1
.hIcon
= NULL
; // wxSTD_MDIPARENTFRAME_ICON;
280 wndclass1
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
281 // wndclass1.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1) ;
282 wndclass1
.hbrBackground
= NULL
;
283 wndclass1
.lpszMenuName
= NULL
;
285 wndclass1
.lpszClassName
= wxMDIFrameClassName
;
286 if (!RegisterClass( &wndclass1
))
288 // wxFatalError("Can't register MDI Frame window class");
292 ///////////////////////////////////////////////////////////////////////
293 // Register the MDI child frame window class.
294 WNDCLASS wndclass4
; // Structure used to register Windows class.
296 wndclass4
.style
= CS_HREDRAW
| CS_VREDRAW
;
297 wndclass4
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
298 wndclass4
.cbClsExtra
= 0;
299 wndclass4
.cbWndExtra
= sizeof( DWORD
); // was 4
300 wndclass4
.hInstance
= wxhInstance
;
301 wndclass4
.hIcon
= NULL
; // wxSTD_MDICHILDFRAME_ICON;
302 wndclass4
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
303 // TODO: perhaps this should be NULL so that Windows doesn't
304 // paint the background itself (would OnEraseBackground duplicate
306 wndclass4
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1) ;
307 // wndclass4.hbrBackground = NULL;
308 wndclass4
.lpszMenuName
= NULL
;
309 wndclass4
.lpszClassName
= wxMDIChildFrameClassName
;
311 if (!RegisterClass( &wndclass4
))
313 // wxFatalError("Can't register MDI child frame window class");
317 ///////////////////////////////////////////////////////////////////////
318 // Register the panel window class.
319 WNDCLASS wndclass2
; // Structure used to register Windows class.
320 memset(&wndclass2
, 0, sizeof(WNDCLASS
)); // start with NULL defaults
321 // Use CS_OWNDC to avoid messing about restoring the context
322 // for every graphic operation.
323 wndclass2
.style
= CS_HREDRAW
| CS_VREDRAW
;
324 wndclass2
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
325 wndclass2
.cbClsExtra
= 0;
326 wndclass2
.cbWndExtra
= sizeof( DWORD
); // was 4
327 wndclass2
.hInstance
= wxhInstance
;
328 wndclass2
.hIcon
= NULL
;
329 wndclass2
.hCursor
= NULL
;
330 // wndclass2.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1) ;
331 wndclass2
.hbrBackground
= (HBRUSH
) GetStockObject( LTGRAY_BRUSH
);
332 wndclass2
.lpszMenuName
= NULL
;
333 wndclass2
.lpszClassName
= wxPanelClassName
;
334 if (!RegisterClass( &wndclass2
))
336 // wxFatalError("Can't register Panel Window class");
340 ///////////////////////////////////////////////////////////////////////
341 // Register the canvas and textsubwindow class name
342 WNDCLASS wndclass3
; // Structure used to register Windows class.
343 memset(&wndclass3
, 0, sizeof(WNDCLASS
)); // start with NULL defaults
344 // Use CS_OWNDC to avoid messing about restoring the context
345 // for every graphic operation.
346 // wndclass3.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS ;
348 wndclass3
.style
= CS_HREDRAW
| CS_VREDRAW
| CS_DBLCLKS
;
349 wndclass3
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
350 wndclass3
.cbClsExtra
= 0;
351 wndclass3
.cbWndExtra
= sizeof( DWORD
); // was 4
352 wndclass3
.hInstance
= wxhInstance
;
353 wndclass3
.hIcon
= NULL
;
354 wndclass3
.hCursor
= NULL
;
355 // wndclass3.hbrBackground = (HBRUSH)(COLOR_WINDOW+1) ;
356 wndclass3
.hbrBackground
= NULL
;
357 wndclass3
.lpszMenuName
= NULL
;
358 wndclass3
.lpszClassName
= wxCanvasClassName
;
359 if (!RegisterClass( &wndclass3
))
361 // wxFatalError("Can't register Canvas class");
368 //// Convert Windows to argc, argv style
370 void wxApp::ConvertToStandardCommandArgs(char* lpCmdLine
)
374 wxString
cmdLine(lpCmdLine
);
377 // Get application name
378 char name
[260]; // 260 is MAX_PATH value from windef.h
379 ::GetModuleFileName(wxhInstance
, name
, WXSIZEOF(name
));
381 // GNUWIN32 already fills in the first arg with the application name.
382 #if !defined(__GNUWIN32__)
387 strcpy(name
, wxFileNameFromPath(name
));
388 wxStripExtension(name
);
389 wxTheApp
->SetAppName(name
);
392 // Treat strings enclosed in double-quotes as single arguments
394 int len
= cmdLine
.Length();
398 while ((i
< len
) && isspace(cmdLine
.GetChar(i
)))
403 if (cmdLine
.GetChar(i
) == '"') // We found the start of a string
407 while ((i
< len
) && (cmdLine
.GetChar(i
) != '"'))
410 wxString
arg(cmdLine
.Mid(first
, (i
- first
)));
416 i
++; // Skip past 2nd quote
418 else // Unquoted argument
421 while ((i
< len
) && !isspace(cmdLine
.GetChar(i
)))
424 wxString
arg(cmdLine
.Mid(first
, (i
- first
)));
432 wxTheApp
->argv
= new char*[count
+ 1];
433 for (i
= 0; i
< count
; i
++)
435 wxString
arg(args
[i
]);
436 wxTheApp
->argv
[i
] = copystring((const char*)arg
);
438 wxTheApp
->argv
[count
] = NULL
; // argv[] is a NULL-terminated list
439 wxTheApp
->argc
= count
;
442 //// Cleans up any wxWindows internal structures left lying around
444 void wxApp::CleanUp()
447 wxModule::CleanUpModules();
449 #if wxUSE_WX_RESOURCES
450 wxCleanUpResourceSystem();
452 // wxDefaultResourceTable->ClearTable();
455 // Indicate that the cursor can be freed,
456 // so that cursor won't be deleted by deleting
457 // the bitmap list before g_globalCursor goes out
458 // of scope (double deletion of the cursor).
459 wxSetCursor(wxNullCursor
);
460 delete g_globalCursor
;
462 wxDeleteStockObjects() ;
464 // Destroy all GDI lists, etc.
465 wxDeleteStockLists();
467 delete wxTheColourDatabase
;
468 wxTheColourDatabase
= NULL
;
470 wxBitmap::CleanUpHandlers();
475 //// WINDOWS-SPECIFIC CLEANUP
477 wxSetKeyboardHook(FALSE
);
480 if (gs_hRichEdit
!= NULL
)
481 FreeLibrary(gs_hRichEdit
);
488 if (wxSTD_FRAME_ICON
)
489 DestroyIcon(wxSTD_FRAME_ICON
);
490 if (wxSTD_MDICHILDFRAME_ICON
)
491 DestroyIcon(wxSTD_MDICHILDFRAME_ICON
);
492 if (wxSTD_MDIPARENTFRAME_ICON
)
493 DestroyIcon(wxSTD_MDIPARENTFRAME_ICON
);
495 if (wxDEFAULT_FRAME_ICON
)
496 DestroyIcon(wxDEFAULT_FRAME_ICON
);
497 if (wxDEFAULT_MDICHILDFRAME_ICON
)
498 DestroyIcon(wxDEFAULT_MDICHILDFRAME_ICON
);
499 if (wxDEFAULT_MDIPARENTFRAME_ICON
)
500 DestroyIcon(wxDEFAULT_MDIPARENTFRAME_ICON
);
502 if ( wxDisableButtonBrush
)
503 ::DeleteObject( wxDisableButtonBrush
) ;
508 Ctl3dUnregister(wxhInstance
);
512 delete wxWinHandleList
;
514 wxClassInfo::CleanUpClasses();
519 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
520 // At this point we want to check if there are any memory
521 // blocks that aren't part of the wxDebugContext itself,
522 // as a special case. Then when dumping we need to ignore
523 // wxDebugContext, too.
524 if (wxDebugContext::CountObjectsLeft() > 0)
526 wxLogDebug("There were memory leaks.");
527 wxDebugContext::Dump();
528 wxDebugContext::PrintStatistics();
530 // wxDebugContext::SetStream(NULL, NULL);
533 // do it as the very last thing because everything else can log messages
534 wxLog::DontCreateOnDemand();
535 delete wxLog::SetActiveTarget(NULL
);
538 #if !defined(_WINDLL) || (defined(_WINDLL) && defined(WXMAKINGDLL))
540 //// Main wxWindows entry point
541 int wxEntry(WXHINSTANCE hInstance
,
542 WXHINSTANCE
WXUNUSED(hPrevInstance
),
547 #ifndef __WXDEBUG__ // take everything into a try-except block in release build
551 wxhInstance
= (HINSTANCE
) hInstance
;
553 if (!wxApp::Initialize())
556 // create the application object or ensure that one already exists
559 // The app may have declared a global application object, but we recommend
560 // the IMPLEMENT_APP macro is used instead, which sets an initializer
561 // function for delayed, dynamic app object construction.
562 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
563 "No initializer - use IMPLEMENT_APP macro." );
565 wxTheApp
= (*wxApp::GetInitializerFunction()) ();
568 wxCHECK_MSG( wxTheApp
, 0, "You have to define an instance of wxApp!" );
570 // save the WinMain() parameters
571 wxTheApp
->ConvertToStandardCommandArgs(lpCmdLine
);
572 wxTheApp
->m_nCmdShow
= nCmdShow
;
574 // GUI-specific initialisation. In fact on Windows we don't have any,
575 // but this call is provided for compatibility across platforms.
576 wxTheApp
->OnInitGui() ;
580 if ( wxTheApp
->OnInit() )
584 retValue
= wxTheApp
->OnRun();
587 //else: app initialization failed, so we skipped OnRun()
589 wxWindow
*topWindow
= wxTheApp
->GetTopWindow();
592 // Forcibly delete the window.
593 if ( topWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
594 topWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
596 topWindow
->Close(TRUE
);
597 wxTheApp
->DeletePendingObjects();
602 wxTheApp
->SetTopWindow(NULL
);
608 // flush the logged messages if any
609 wxLog
*pLog
= wxLog::GetActiveTarget();
610 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
617 #ifndef __WXDEBUG__ // catch exceptions only in release build
619 except ( EXCEPTION_EXECUTE_HANDLER
) {
622 wxTheApp->OnFatalException();
625 ::ExitProcess(3); // the same exit code as abort()
632 //// Entry point for DLLs
634 int wxEntry(WXHINSTANCE hInstance
)
636 wxhInstance
= (HINSTANCE
) hInstance
;
639 // The app may have declared a global application object, but we recommend
640 // the IMPLEMENT_APP macro is used instead, which sets an initializer function
641 // for delayed, dynamic app object construction.
645 if (!wxApp::GetInitializerFunction())
647 MessageBox(NULL
, "No initializer - use IMPLEMENT_APP macro.", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
651 wxTheApp
= (* wxApp::GetInitializerFunction()) ();
655 MessageBox(NULL
, "You have to define an instance of wxApp!", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
660 wxTheApp
->argv
= NULL
;
662 wxTheApp
->OnInitGui();
666 if (wxTheApp
->GetTopWindow() && wxTheApp
->GetTopWindow()->GetHWND()) {
667 wxTheApp
->GetTopWindow()->Show(TRUE
);
674 //// Static member initialization
676 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
683 m_wantDebugOutput
= TRUE
;
688 m_printMode
= wxPRINT_WINDOWS
;
690 m_printMode
= wxPRINT_POSTSCRIPT
;
692 m_exitOnFrameDelete
= TRUE
;
698 // Delete command-line args
700 for (i
= 0; i
< argc
; i
++)
707 bool wxApp::Initialized()
715 #ifdef _WINDLL // Assume initialized if DLL (no way of telling)
721 * Get and process a message, returning FALSE if WM_QUIT
725 bool wxApp::DoMessage()
727 if (!::GetMessage(&s_currentMsg
, (HWND
) NULL
, 0, 0))
732 // Process the message
733 if (!ProcessMessage((WXMSG
*)&s_currentMsg
))
735 ::TranslateMessage(&s_currentMsg
);
736 wxApp::sm_lastMessageTime
= s_currentMsg
.time
; /* MATTHEW: timeStamp impl. */
737 ::DispatchMessage(&s_currentMsg
);
743 * Keep trying to process messages until WM_QUIT
746 * If there are messages to be processed, they will all be
747 * processed and OnIdle will not be called.
748 * When there are no more messages, OnIdle is called.
749 * If OnIdle requests more time,
750 * it will be repeatedly called so long as there are no pending messages.
751 * A 'feature' of this is that once OnIdle has decided that no more processing
752 * is required, then it won't get processing time until further messages
753 * are processed (it'll sit in DoMessage).
756 int wxApp::MainLoop()
761 while (!::PeekMessage(&s_currentMsg
, 0, 0, 0, PM_NOREMOVE
) &&
767 return s_currentMsg
.wParam
;
770 // Returns TRUE if more time is needed.
771 bool wxApp::ProcessIdle()
774 event
.SetEventObject(this);
777 return event
.MoreRequested();
780 void wxApp::ExitMainLoop()
785 bool wxApp::Pending()
787 return (::PeekMessage(&s_currentMsg
, 0, 0, 0, PM_NOREMOVE
) != 0) ;
790 void wxApp::Dispatch()
797 * Give all windows a chance to preprocess
798 * the message. Some may have accelerator tables, or have
801 bool wxApp::ProcessMessage(WXMSG
*Msg
)
803 MSG
*msg
= (MSG
*)Msg
;
807 // Try translations first; find the youngest window with
808 // a translation table.
809 for (hWnd
= msg
->hwnd
; hWnd
!= NULL
; hWnd
= ::GetParent(hWnd
))
811 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
814 if (wnd
->MSWTranslateMessage(Msg
))
819 // Anyone for a non-translation message? Try youngest descendants first.
820 for (hWnd
= msg
->hwnd
; hWnd
!= NULL
; hWnd
= ::GetParent(hWnd
))
822 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
825 if (wnd
->MSWProcessMessage(Msg
))
832 void wxApp::OnIdle(wxIdleEvent
& event
)
834 static bool inOnIdle
= FALSE
;
836 // Avoid recursion (via ProcessEvent default case)
842 // 'Garbage' collection of windows deleted with Close().
843 DeletePendingObjects();
845 // flush the logged messages if any
846 wxLog
*pLog
= wxLog::GetActiveTarget();
847 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
850 // Send OnIdle events to all windows
851 bool needMore
= SendIdleEvents();
852 // bool needMore = FALSE;
855 event
.RequestMore(TRUE
);
860 // Send idle event to all top-level windows
861 bool wxApp::SendIdleEvents()
863 bool needMore
= FALSE
;
864 wxNode
* node
= wxTopLevelWindows
.First();
867 wxWindow
* win
= (wxWindow
*) node
->Data();
868 if (SendIdleEvents(win
))
876 // Send idle event to window and all subwindows
877 bool wxApp::SendIdleEvents(wxWindow
* win
)
879 bool needMore
= FALSE
;
882 event
.SetEventObject(win
);
883 win
->GetEventHandler()->ProcessEvent(event
);
885 if (event
.MoreRequested())
888 wxNode
* node
= win
->GetChildren().First();
891 wxWindow
* win
= (wxWindow
*) node
->Data();
892 if (SendIdleEvents(win
))
900 void wxApp::DeletePendingObjects()
902 wxNode
*node
= wxPendingDelete
.First();
905 wxObject
*obj
= (wxObject
*)node
->Data();
909 if (wxPendingDelete
.Member(obj
))
912 // Deleting one object may have deleted other pending
913 // objects, so start from beginning of list again.
914 node
= wxPendingDelete
.First();
918 void wxApp::OnEndSession(wxCloseEvent
& event
)
921 GetTopWindow()->Close(TRUE
);
924 // Default behaviour: close the application with prompts. The
925 // user can veto the close, and therefore the end session.
926 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
930 if (!GetTopWindow()->Close(!event
.CanVeto()))
935 wxLog
* wxApp::CreateLogTarget()
940 wxWindow
* wxApp::GetTopWindow() const
944 else if (wxTopLevelWindows
.Number() > 0)
945 return (wxWindow
*) wxTopLevelWindows
.First()->Data();
950 int wxApp::GetComCtl32Version() const
952 // have we loaded COMCTL32 yet?
953 HMODULE theModule
= ::GetModuleHandle("COMCTL32");
956 // if so, then we can check for the version
959 // InitCommonControlsEx is unique to 4.7 and later
960 FARPROC theProc
= ::GetProcAddress(theModule
, "InitCommonControlsEx");
963 { // not found, must be 4.00
968 // The following symbol are unique to 4.71
970 // FlatSB_EnableScrollBar FlatSB_GetScrollInfo FlatSB_GetScrollPos
971 // FlatSB_GetScrollProp FlatSB_GetScrollRange FlatSB_SetScrollInfo
972 // FlatSB_SetScrollPos FlatSB_SetScrollProp FlatSB_SetScrollRange
973 // FlatSB_ShowScrollBar
974 // _DrawIndirectImageList _DuplicateImageList
976 // UninitializeFlatSB
977 // we could check for any of these - I chose DllInstall
978 FARPROC theProc
= ::GetProcAddress(theModule
, "DllInstall");
981 // not found, must be 4.70
985 { // found, must be 4.71
996 FatalAppExit(0, "Fatal error: exiting");
999 // Yield to incoming messages
1003 // We want to go back to the main message loop
1004 // if we see a WM_QUIT. (?)
1005 while (PeekMessage(&msg
, NULL
, 0, 0, PM_NOREMOVE
) && msg
.message
!= WM_QUIT
)
1007 if (!wxTheApp
->DoMessage())
1014 HINSTANCE
wxGetInstance()
1019 // For some reason, with MSVC++ 1.5, WinMain isn't linked in properly
1020 // if in a separate file. So include it here to ensure it's linked.
1021 #if (defined(_MSC_VER) && !defined(__WIN32__)) || defined(__GNUWIN32__)