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++
54 /* Here we go again commenting it out. PLEASE don't
55 * uncomment this again.
56 #if defined(__WXDEBUG__) && defined(_MSC_VER)
57 // VC++ uses this macro as debug/release mode indicator
66 extern char *wxBuffer
;
67 extern char *wxOsVersion
;
68 extern wxList
*wxWinHandleList
;
69 extern wxList wxPendingDelete
;
70 extern void wxSetKeyboardHook(bool doIt
);
71 extern wxCursor
*g_globalCursor
;
73 HINSTANCE wxhInstance
= 0;
74 static MSG s_currentMsg
;
75 wxApp
*wxTheApp
= NULL
;
77 // @@ why not const? and not static?
78 char wxFrameClassName
[] = "wxFrameClass";
79 char wxMDIFrameClassName
[] = "wxMDIFrameClass";
80 char wxMDIChildFrameClassName
[] = "wxMDIChildFrameClass";
81 char wxPanelClassName
[] = "wxPanelClass";
82 char wxCanvasClassName
[] = "wxCanvasClass";
84 HICON wxSTD_FRAME_ICON
= NULL
;
85 HICON wxSTD_MDICHILDFRAME_ICON
= NULL
;
86 HICON wxSTD_MDIPARENTFRAME_ICON
= NULL
;
88 HICON wxDEFAULT_FRAME_ICON
= NULL
;
89 HICON wxDEFAULT_MDICHILDFRAME_ICON
= NULL
;
90 HICON wxDEFAULT_MDIPARENTFRAME_ICON
= NULL
;
92 HBRUSH wxDisableButtonBrush
= 0;
94 LRESULT APIENTRY
wxWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
96 #if !USE_SHARED_LIBRARY
97 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
99 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
100 EVT_IDLE(wxApp::OnIdle
)
101 EVT_END_SESSION(wxApp::OnEndSession
)
102 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
)
106 long wxApp::sm_lastMessageTime
= 0;
109 static HINSTANCE gs_hRichEdit
= NULL
;
114 bool wxApp::Initialize()
116 wxBuffer
= new char[1500];
118 /* PLEASE don't uncomment this again. IT DOESN'T WORK when building
119 * using the makefile.
120 #if defined(__WXDEBUG__) && defined(_MSC_VER)
121 // do check for memory leaks on program exit
122 // (another useful flag is _CRTDBG_DELAY_FREE_MEM_DF which doesn't free
123 // deallocated memory which may be used to simulate low-memory condition)
124 _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);
125 #endif // debug build under MS VC++
129 // 22/11/98: we're converting to wxLogDebug instead of wxTrace,
130 // so these are now obsolete.
133 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
135 streambuf
* sBuf
= NULL
;
137 streambuf
* sBuf
= new wxDebugStreamBuf
;
140 ostream
* oStr
= new ostream(sBuf
) ;
141 wxDebugContext::SetStream(oStr
, sBuf
);
142 #endif // wxUSE_MEMORY_TRACING
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");
173 #if defined(WX_DRAG_DROP)
174 // we need to initialize OLE library
175 if ( FAILED(::OleInitialize(NULL
)) )
176 wxFatalError(_("Cannot initialize OLE"));
180 if (!Ctl3dRegister(wxhInstance
))
181 wxFatalError("Cannot register CTL3D");
183 Ctl3dAutoSubclass(wxhInstance
);
186 g_globalCursor
= new wxCursor
;
188 wxSTD_FRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_FRAME");
189 wxSTD_MDIPARENTFRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_MDIPARENTFRAME");
190 wxSTD_MDICHILDFRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_MDICHILDFRAME");
192 wxDEFAULT_FRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_FRAME");
193 wxDEFAULT_MDIPARENTFRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_MDIPARENTFRAME");
194 wxDEFAULT_MDICHILDFRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_MDICHILDFRAME");
196 RegisterWindowClasses();
198 // Create the brush for disabling bitmap buttons
201 lb
.lbStyle
= BS_PATTERN
;
202 lb
.lbHatch
= (int)LoadBitmap( wxhInstance
, "wxDISABLE_BUTTON_BITMAP" ) ;
203 wxDisableButtonBrush
= ::CreateBrushIndirect( & lb
) ;
204 ::DeleteObject( (HGDIOBJ
)lb
.lbHatch
) ;
210 wxWinHandleList
= new wxList(wxKEY_INTEGER
);
212 // This is to foil optimizations in Visual C++ that
213 // throw out dummy.obj.
214 #if (_MSC_VER >= 800) && !defined(WXMAKINGDLL)
215 extern char wxDummyChar
;
216 if (wxDummyChar
) wxDummyChar
++;
219 wxSetKeyboardHook(TRUE
);
221 wxModule::RegisterModules();
222 if (!wxModule::InitializeModules())
227 //// RegisterWindowClasses
229 bool wxApp::RegisterWindowClasses()
231 ///////////////////////////////////////////////////////////////////////
232 // Register the frame window class.
233 WNDCLASS wndclass
; // Structure used to register Windows class.
235 wndclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
236 wndclass
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
237 wndclass
.cbClsExtra
= 0;
238 wndclass
.cbWndExtra
= sizeof( DWORD
); // was 4
239 wndclass
.hInstance
= wxhInstance
;
240 wndclass
.hIcon
= NULL
; // wxSTD_FRAME_ICON;
241 wndclass
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
242 wndclass
.hbrBackground
= (HBRUSH
)(COLOR_APPWORKSPACE
+1) ;
243 // wndclass.hbrBackground = GetStockObject( WHITE_BRUSH );
244 wndclass
.lpszMenuName
= NULL
;
245 #ifdef _MULTIPLE_INSTANCES
246 sprintf( wxFrameClassName
,"wxFrameClass%d", wxhInstance
);
248 wndclass
.lpszClassName
= wxFrameClassName
;
250 if (!RegisterClass( &wndclass
))
252 // wxFatalError("Can't register Frame Window class");
255 ///////////////////////////////////////////////////////////////////////
256 // Register the MDI frame window class.
257 WNDCLASS wndclass1
; // Structure used to register Windows class.
259 wndclass1
.style
= CS_HREDRAW
| CS_VREDRAW
;
260 wndclass1
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
261 wndclass1
.cbClsExtra
= 0;
262 wndclass1
.cbWndExtra
= sizeof( DWORD
); // was 4
263 wndclass1
.hInstance
= wxhInstance
;
264 wndclass1
.hIcon
= NULL
; // wxSTD_MDIPARENTFRAME_ICON;
265 wndclass1
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
266 // wndclass1.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1) ;
267 wndclass1
.hbrBackground
= NULL
;
268 wndclass1
.lpszMenuName
= NULL
;
270 wndclass1
.lpszClassName
= wxMDIFrameClassName
;
271 if (!RegisterClass( &wndclass1
))
273 // wxFatalError("Can't register MDI Frame window class");
277 ///////////////////////////////////////////////////////////////////////
278 // Register the MDI child frame window class.
279 WNDCLASS wndclass4
; // Structure used to register Windows class.
281 wndclass4
.style
= CS_HREDRAW
| CS_VREDRAW
;
282 wndclass4
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
283 wndclass4
.cbClsExtra
= 0;
284 wndclass4
.cbWndExtra
= sizeof( DWORD
); // was 4
285 wndclass4
.hInstance
= wxhInstance
;
286 wndclass4
.hIcon
= NULL
; // wxSTD_MDICHILDFRAME_ICON;
287 wndclass4
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
288 // TODO: perhaps this should be NULL so that Windows doesn't
289 // paint the background itself (would OnEraseBackground duplicate
291 wndclass4
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1) ;
292 // wndclass4.hbrBackground = NULL;
293 wndclass4
.lpszMenuName
= NULL
;
294 wndclass4
.lpszClassName
= wxMDIChildFrameClassName
;
296 if (!RegisterClass( &wndclass4
))
298 // wxFatalError("Can't register MDI child frame window class");
302 ///////////////////////////////////////////////////////////////////////
303 // Register the panel window class.
304 WNDCLASS wndclass2
; // Structure used to register Windows class.
305 memset(&wndclass2
, 0, sizeof(WNDCLASS
)); // start with NULL defaults
306 // Use CS_OWNDC to avoid messing about restoring the context
307 // for every graphic operation.
308 wndclass2
.style
= CS_HREDRAW
| CS_VREDRAW
;
309 wndclass2
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
310 wndclass2
.cbClsExtra
= 0;
311 wndclass2
.cbWndExtra
= sizeof( DWORD
); // was 4
312 wndclass2
.hInstance
= wxhInstance
;
313 wndclass2
.hIcon
= NULL
;
314 wndclass2
.hCursor
= NULL
;
315 // wndclass2.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1) ;
316 wndclass2
.hbrBackground
= (HBRUSH
) GetStockObject( LTGRAY_BRUSH
);
317 wndclass2
.lpszMenuName
= NULL
;
318 wndclass2
.lpszClassName
= wxPanelClassName
;
319 if (!RegisterClass( &wndclass2
))
321 // wxFatalError("Can't register Panel Window class");
325 ///////////////////////////////////////////////////////////////////////
326 // Register the canvas and textsubwindow class name
327 WNDCLASS wndclass3
; // Structure used to register Windows class.
328 memset(&wndclass3
, 0, sizeof(WNDCLASS
)); // start with NULL defaults
329 // Use CS_OWNDC to avoid messing about restoring the context
330 // for every graphic operation.
331 // wndclass3.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS ;
333 wndclass3
.style
= CS_HREDRAW
| CS_VREDRAW
| CS_DBLCLKS
;
334 wndclass3
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
335 wndclass3
.cbClsExtra
= 0;
336 wndclass3
.cbWndExtra
= sizeof( DWORD
); // was 4
337 wndclass3
.hInstance
= wxhInstance
;
338 wndclass3
.hIcon
= NULL
;
339 wndclass3
.hCursor
= NULL
;
340 // wndclass3.hbrBackground = (HBRUSH)(COLOR_WINDOW+1) ;
341 wndclass3
.hbrBackground
= NULL
;
342 wndclass3
.lpszMenuName
= NULL
;
343 wndclass3
.lpszClassName
= wxCanvasClassName
;
344 if (!RegisterClass( &wndclass3
))
346 // wxFatalError("Can't register Canvas class");
353 //// Convert Windows to argc, argv style
355 void wxApp::ConvertToStandardCommandArgs(char* lpCmdLine
)
359 wxString
cmdLine(lpCmdLine
);
362 // Get application name
363 char name
[260]; // 260 is MAX_PATH value from windef.h
364 ::GetModuleFileName(wxhInstance
, name
, WXSIZEOF(name
));
366 // GNUWIN32 already fills in the first arg with the application name.
367 #if !defined(__GNUWIN32__)
372 strcpy(name
, wxFileNameFromPath(name
));
373 wxStripExtension(name
);
374 wxTheApp
->SetAppName(name
);
377 // Treat strings enclosed in double-quotes as single arguments
379 int len
= cmdLine
.Length();
383 while ((i
< len
) && isspace(cmdLine
.GetChar(i
)))
388 if (cmdLine
.GetChar(i
) == '"') // We found the start of a string
392 while ((i
< len
) && (cmdLine
.GetChar(i
) != '"'))
395 wxString
arg(cmdLine
.Mid(first
, (i
- first
)));
401 i
++; // Skip past 2nd quote
403 else // Unquoted argument
406 while ((i
< len
) && !isspace(cmdLine
.GetChar(i
)))
409 wxString
arg(cmdLine
.Mid(first
, (i
- first
)));
417 wxTheApp
->argv
= new char*[count
+ 1];
418 for (i
= 0; i
< count
; i
++)
420 wxString
arg(args
[i
]);
421 wxTheApp
->argv
[i
] = copystring((const char*)arg
);
423 wxTheApp
->argv
[count
] = NULL
; // argv[] is a NULL-terminated list
424 wxTheApp
->argc
= count
;
427 //// Cleans up any wxWindows internal structures left lying around
429 void wxApp::CleanUp()
432 wxModule::CleanUpModules();
434 #if wxUSE_WX_RESOURCES
435 wxCleanUpResourceSystem();
437 // wxDefaultResourceTable->ClearTable();
440 // Indicate that the cursor can be freed,
441 // so that cursor won't be deleted by deleting
442 // the bitmap list before g_globalCursor goes out
443 // of scope (double deletion of the cursor).
444 wxSetCursor(wxNullCursor
);
445 delete g_globalCursor
;
447 wxDeleteStockObjects() ;
449 // Destroy all GDI lists, etc.
450 wxDeleteStockLists();
452 delete wxTheColourDatabase
;
453 wxTheColourDatabase
= NULL
;
455 wxBitmap::CleanUpHandlers();
460 //// WINDOWS-SPECIFIC CLEANUP
462 wxSetKeyboardHook(FALSE
);
465 if (gs_hRichEdit
!= NULL
)
466 FreeLibrary(gs_hRichEdit
);
473 if (wxSTD_FRAME_ICON
)
474 DestroyIcon(wxSTD_FRAME_ICON
);
475 if (wxSTD_MDICHILDFRAME_ICON
)
476 DestroyIcon(wxSTD_MDICHILDFRAME_ICON
);
477 if (wxSTD_MDIPARENTFRAME_ICON
)
478 DestroyIcon(wxSTD_MDIPARENTFRAME_ICON
);
480 if (wxDEFAULT_FRAME_ICON
)
481 DestroyIcon(wxDEFAULT_FRAME_ICON
);
482 if (wxDEFAULT_MDICHILDFRAME_ICON
)
483 DestroyIcon(wxDEFAULT_MDICHILDFRAME_ICON
);
484 if (wxDEFAULT_MDIPARENTFRAME_ICON
)
485 DestroyIcon(wxDEFAULT_MDIPARENTFRAME_ICON
);
487 if ( wxDisableButtonBrush
)
488 ::DeleteObject( wxDisableButtonBrush
) ;
490 #if defined(WX_DRAG_DROP)
495 Ctl3dUnregister(wxhInstance
);
499 delete wxWinHandleList
;
501 wxClassInfo::CleanUpClasses();
506 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
507 // At this point we want to check if there are any memory
508 // blocks that aren't part of the wxDebugContext itself,
509 // as a special case. Then when dumping we need to ignore
510 // wxDebugContext, too.
511 if (wxDebugContext::CountObjectsLeft() > 0)
513 wxLogDebug("There were memory leaks.");
514 wxDebugContext::Dump();
515 wxDebugContext::PrintStatistics();
517 // wxDebugContext::SetStream(NULL, NULL);
520 // do it as the very last thing because everything else can log messages
521 wxLog::DontCreateOnDemand();
522 delete wxLog::SetActiveTarget(NULL
);
525 #if !defined(_WINDLL) || (defined(_WINDLL) && defined(WXMAKINGDLL))
527 //// Main wxWindows entry point
528 int wxEntry(WXHINSTANCE hInstance
,
529 WXHINSTANCE
WXUNUSED(hPrevInstance
),
534 #ifndef __WXDEBUG__ // take everything into a try-except block in release build
538 wxhInstance
= (HINSTANCE
) hInstance
;
540 if (!wxApp::Initialize())
543 // create the application object or ensure that one already exists
546 // The app may have declared a global application object, but we recommend
547 // the IMPLEMENT_APP macro is used instead, which sets an initializer
548 // function for delayed, dynamic app object construction.
549 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
550 "No initializer - use IMPLEMENT_APP macro." );
552 wxTheApp
= (*wxApp::GetInitializerFunction()) ();
555 wxCHECK_MSG( wxTheApp
, 0, "You have to define an instance of wxApp!" );
557 // save the WinMain() parameters
558 wxTheApp
->ConvertToStandardCommandArgs(lpCmdLine
);
559 wxTheApp
->m_nCmdShow
= nCmdShow
;
561 // GUI-specific initialisation. In fact on Windows we don't have any,
562 // but this call is provided for compatibility across platforms.
563 wxTheApp
->OnInitGui() ;
567 if ( wxTheApp
->OnInit() )
571 retValue
= wxTheApp
->OnRun();
574 //else: app initialization failed, so we skipped OnRun()
576 wxWindow
*topWindow
= wxTheApp
->GetTopWindow();
579 // Forcibly delete the window.
580 if ( topWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
581 topWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
583 topWindow
->Close(TRUE
);
584 wxTheApp
->DeletePendingObjects();
589 wxTheApp
->SetTopWindow(NULL
);
595 // flush the logged messages if any
596 wxLog
*pLog
= wxLog::GetActiveTarget();
597 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
604 #ifndef __WXDEBUG__ // catch exceptions only in release build
606 except ( EXCEPTION_EXECUTE_HANDLER
) {
609 wxTheApp->OnFatalException();
612 ::ExitProcess(3); // the same exit code as abort()
619 //// Entry point for DLLs
621 int wxEntry(WXHINSTANCE hInstance
)
623 wxhInstance
= (HINSTANCE
) hInstance
;
626 // The app may have declared a global application object, but we recommend
627 // the IMPLEMENT_APP macro is used instead, which sets an initializer function
628 // for delayed, dynamic app object construction.
632 if (!wxApp::GetInitializerFunction())
634 MessageBox(NULL
, "No initializer - use IMPLEMENT_APP macro.", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
638 wxTheApp
= (* wxApp::GetInitializerFunction()) ();
642 MessageBox(NULL
, "You have to define an instance of wxApp!", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
647 wxTheApp
->argv
= NULL
;
649 wxTheApp
->OnInitGui();
653 if (wxTheApp
->GetTopWindow() && wxTheApp
->GetTopWindow()->GetHWND()) {
654 wxTheApp
->GetTopWindow()->Show(TRUE
);
661 //// Static member initialization
663 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
670 m_wantDebugOutput
= TRUE
;
675 m_printMode
= wxPRINT_WINDOWS
;
677 m_printMode
= wxPRINT_POSTSCRIPT
;
679 m_exitOnFrameDelete
= TRUE
;
685 // Delete command-line args
687 for (i
= 0; i
< argc
; i
++)
694 bool wxApp::Initialized()
702 #ifdef _WINDLL // Assume initialized if DLL (no way of telling)
708 * Get and process a message, returning FALSE if WM_QUIT
712 bool wxApp::DoMessage()
714 if (!::GetMessage(&s_currentMsg
, (HWND
) NULL
, 0, 0))
719 // Process the message
720 if (!ProcessMessage((WXMSG
*)&s_currentMsg
))
722 ::TranslateMessage(&s_currentMsg
);
723 wxApp::sm_lastMessageTime
= s_currentMsg
.time
; /* MATTHEW: timeStamp impl. */
724 ::DispatchMessage(&s_currentMsg
);
730 * Keep trying to process messages until WM_QUIT
733 * If there are messages to be processed, they will all be
734 * processed and OnIdle will not be called.
735 * When there are no more messages, OnIdle is called.
736 * If OnIdle requests more time,
737 * it will be repeatedly called so long as there are no pending messages.
738 * A 'feature' of this is that once OnIdle has decided that no more processing
739 * is required, then it won't get processing time until further messages
740 * are processed (it'll sit in DoMessage).
743 int wxApp::MainLoop()
748 while (!::PeekMessage(&s_currentMsg
, 0, 0, 0, PM_NOREMOVE
) &&
754 return s_currentMsg
.wParam
;
757 // Returns TRUE if more time is needed.
758 bool wxApp::ProcessIdle()
761 event
.SetEventObject(this);
764 return event
.MoreRequested();
767 void wxApp::ExitMainLoop()
772 bool wxApp::Pending()
774 return (::PeekMessage(&s_currentMsg
, 0, 0, 0, PM_NOREMOVE
) != 0) ;
777 void wxApp::Dispatch()
784 * Give all windows a chance to preprocess
785 * the message. Some may have accelerator tables, or have
788 bool wxApp::ProcessMessage(WXMSG
*Msg
)
790 MSG
*msg
= (MSG
*)Msg
;
794 // Try translations first; find the youngest window with
795 // a translation table.
796 for (hWnd
= msg
->hwnd
; hWnd
!= NULL
; hWnd
= ::GetParent(hWnd
))
798 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
801 if (wnd
->MSWTranslateMessage(Msg
))
806 // Anyone for a non-translation message? Try youngest descendants first.
807 for (hWnd
= msg
->hwnd
; hWnd
!= NULL
; hWnd
= ::GetParent(hWnd
))
809 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
812 if (wnd
->MSWProcessMessage(Msg
))
819 void wxApp::OnIdle(wxIdleEvent
& event
)
821 static bool inOnIdle
= FALSE
;
823 // Avoid recursion (via ProcessEvent default case)
829 // 'Garbage' collection of windows deleted with Close().
830 DeletePendingObjects();
832 // flush the logged messages if any
833 wxLog
*pLog
= wxLog::GetActiveTarget();
834 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
837 // Send OnIdle events to all windows
838 bool needMore
= SendIdleEvents();
839 // bool needMore = FALSE;
842 event
.RequestMore(TRUE
);
847 // Send idle event to all top-level windows
848 bool wxApp::SendIdleEvents()
850 bool needMore
= FALSE
;
851 wxNode
* node
= wxTopLevelWindows
.First();
854 wxWindow
* win
= (wxWindow
*) node
->Data();
855 if (SendIdleEvents(win
))
863 // Send idle event to window and all subwindows
864 bool wxApp::SendIdleEvents(wxWindow
* win
)
866 bool needMore
= FALSE
;
869 event
.SetEventObject(win
);
870 win
->GetEventHandler()->ProcessEvent(event
);
872 if (event
.MoreRequested())
875 wxNode
* node
= win
->GetChildren()->First();
878 wxWindow
* win
= (wxWindow
*) node
->Data();
879 if (SendIdleEvents(win
))
887 void wxApp::DeletePendingObjects()
889 wxNode
*node
= wxPendingDelete
.First();
892 wxObject
*obj
= (wxObject
*)node
->Data();
896 if (wxPendingDelete
.Member(obj
))
899 // Deleting one object may have deleted other pending
900 // objects, so start from beginning of list again.
901 node
= wxPendingDelete
.First();
905 void wxApp::OnEndSession(wxCloseEvent
& event
)
908 GetTopWindow()->Close(TRUE
);
911 // Default behaviour: close the application with prompts. The
912 // user can veto the close, and therefore the end session.
913 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
917 if (!GetTopWindow()->Close(!event
.CanVeto()))
922 wxLog
* wxApp::CreateLogTarget()
927 wxWindow
* wxApp::GetTopWindow() const
931 else if (wxTopLevelWindows
.Number() > 0)
932 return (wxWindow
*) wxTopLevelWindows
.First()->Data();
937 int wxApp::GetComCtl32Version() const
939 // have we loaded COMCTL32 yet?
940 HMODULE theModule
= ::GetModuleHandle("COMCTL32");
943 // if so, then we can check for the version
946 // InitCommonControlsEx is unique to 4.7 and later
947 FARPROC theProc
= ::GetProcAddress(theModule
, "InitCommonControlsEx");
950 { // not found, must be 4.00
955 // The following symbol are unique to 4.71
957 // FlatSB_EnableScrollBar FlatSB_GetScrollInfo FlatSB_GetScrollPos
958 // FlatSB_GetScrollProp FlatSB_GetScrollRange FlatSB_SetScrollInfo
959 // FlatSB_SetScrollPos FlatSB_SetScrollProp FlatSB_SetScrollRange
960 // FlatSB_ShowScrollBar
961 // _DrawIndirectImageList _DuplicateImageList
963 // UninitializeFlatSB
964 // we could check for any of these - I chose DllInstall
965 FARPROC theProc
= ::GetProcAddress(theModule
, "DllInstall");
968 // not found, must be 4.70
972 { // found, must be 4.71
983 FatalAppExit(0, "Fatal error: exiting");
986 // Yield to incoming messages
990 // We want to go back to the main message loop
991 // if we see a WM_QUIT. (?)
992 while (PeekMessage(&msg
, NULL
, 0, 0, PM_NOREMOVE
) && msg
.message
!= WM_QUIT
)
994 if (!wxTheApp
->DoMessage())
1001 HINSTANCE
wxGetInstance()
1006 // For some reason, with MSVC++ 1.5, WinMain isn't linked in properly
1007 // if in a separate file. So include it here to ensure it's linked.
1008 #if (defined(_MSC_VER) && !defined(__WIN32__)) || defined(__GNUWIN32__)