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
70 extern char *wxBuffer
;
71 extern char *wxOsVersion
;
72 extern wxList
*wxWinHandleList
;
73 extern wxList wxPendingDelete
;
74 extern void wxSetKeyboardHook(bool doIt
);
75 extern wxCursor
*g_globalCursor
;
77 HINSTANCE wxhInstance
= 0;
78 static MSG s_currentMsg
;
79 wxApp
*wxTheApp
= NULL
;
81 // @@ why not const? and not static?
82 char wxFrameClassName
[] = "wxFrameClass";
83 char wxMDIFrameClassName
[] = "wxMDIFrameClass";
84 char wxMDIChildFrameClassName
[] = "wxMDIChildFrameClass";
85 char wxPanelClassName
[] = "wxPanelClass";
86 char wxCanvasClassName
[] = "wxCanvasClass";
88 HICON wxSTD_FRAME_ICON
= NULL
;
89 HICON wxSTD_MDICHILDFRAME_ICON
= NULL
;
90 HICON wxSTD_MDIPARENTFRAME_ICON
= NULL
;
92 HICON wxDEFAULT_FRAME_ICON
= NULL
;
93 HICON wxDEFAULT_MDICHILDFRAME_ICON
= NULL
;
94 HICON wxDEFAULT_MDIPARENTFRAME_ICON
= NULL
;
96 HBRUSH wxDisableButtonBrush
= 0;
98 LRESULT APIENTRY
wxWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
100 #if !USE_SHARED_LIBRARY
101 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
103 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
104 EVT_IDLE(wxApp::OnIdle
)
105 EVT_END_SESSION(wxApp::OnEndSession
)
106 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
)
110 long wxApp::sm_lastMessageTime
= 0;
113 static HINSTANCE gs_hRichEdit
= NULL
;
118 bool wxApp::Initialize()
120 wxBuffer
= new char[1500];
122 #ifdef wxUSE_VC_CRTDBG
123 // do check for memory leaks on program exit
124 // (another useful flag is _CRTDBG_DELAY_FREE_MEM_DF which doesn't free
125 // deallocated memory which may be used to simulate low-memory condition)
126 _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG
) | _CRTDBG_LEAK_CHECK_DF
);
127 #endif // debug build under MS VC++
129 wxClassInfo::InitializeClasses();
132 wxGetResource("wxWindows", "OsVersion", &wxOsVersion
);
135 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
136 wxTheColourDatabase
->Initialize();
138 wxInitializeStockLists();
139 wxInitializeStockObjects();
141 #if wxUSE_WX_RESOURCES
142 wxInitializeResourceSystem();
145 wxBitmap::InitStandardHandlers();
147 #if defined(__WIN95__)
148 InitCommonControls();
149 gs_hRichEdit
= LoadLibrary("RICHED32.DLL");
151 if (gs_hRichEdit
== NULL
)
153 wxMessageBox("Could not initialise Rich Edit DLL");
159 // for OLE, enlarge message queue to be as large as possible
160 while (!SetMessageQueue(iMsg
) && (iMsg
-= 8));
164 dwOleVer = CoBuildVersion();
166 // check the OLE library version
167 if (rmm != HIWORD(dwOleVer))
169 wxMessageBox("Incorrect version of OLE libraries.");
174 // we need to initialize OLE library
175 if ( FAILED(::OleInitialize(NULL
)) )
176 wxFatalError(_("Cannot initialize OLE"));
179 if (!Ctl3dRegister(wxhInstance
))
180 wxFatalError("Cannot register CTL3D");
182 Ctl3dAutoSubclass(wxhInstance
);
185 g_globalCursor
= new wxCursor
;
187 wxSTD_FRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_FRAME");
188 wxSTD_MDIPARENTFRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_MDIPARENTFRAME");
189 wxSTD_MDICHILDFRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_MDICHILDFRAME");
191 wxDEFAULT_FRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_FRAME");
192 wxDEFAULT_MDIPARENTFRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_MDIPARENTFRAME");
193 wxDEFAULT_MDICHILDFRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_MDICHILDFRAME");
195 RegisterWindowClasses();
197 // Create the brush for disabling bitmap buttons
200 lb
.lbStyle
= BS_PATTERN
;
201 lb
.lbHatch
= (int)LoadBitmap( wxhInstance
, "wxDISABLE_BUTTON_BITMAP" ) ;
202 wxDisableButtonBrush
= ::CreateBrushIndirect( & lb
) ;
203 ::DeleteObject( (HGDIOBJ
)lb
.lbHatch
) ;
209 wxWinHandleList
= new wxList(wxKEY_INTEGER
);
211 // This is to foil optimizations in Visual C++ that
212 // throw out dummy.obj.
213 #if (_MSC_VER >= 800) && !defined(WXMAKINGDLL)
214 extern char wxDummyChar
;
215 if (wxDummyChar
) wxDummyChar
++;
218 wxSetKeyboardHook(TRUE
);
220 wxModule::RegisterModules();
221 if (!wxModule::InitializeModules())
226 //// RegisterWindowClasses
228 bool wxApp::RegisterWindowClasses()
230 ///////////////////////////////////////////////////////////////////////
231 // Register the frame window class.
232 WNDCLASS wndclass
; // Structure used to register Windows class.
234 wndclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
235 wndclass
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
236 wndclass
.cbClsExtra
= 0;
237 wndclass
.cbWndExtra
= sizeof( DWORD
); // was 4
238 wndclass
.hInstance
= wxhInstance
;
239 wndclass
.hIcon
= NULL
; // wxSTD_FRAME_ICON;
240 wndclass
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
241 wndclass
.hbrBackground
= (HBRUSH
)(COLOR_APPWORKSPACE
+1) ;
242 // wndclass.hbrBackground = GetStockObject( WHITE_BRUSH );
243 wndclass
.lpszMenuName
= NULL
;
244 #ifdef _MULTIPLE_INSTANCES
245 sprintf( wxFrameClassName
,"wxFrameClass%d", wxhInstance
);
247 wndclass
.lpszClassName
= wxFrameClassName
;
249 if (!RegisterClass( &wndclass
))
251 // wxFatalError("Can't register Frame Window class");
254 ///////////////////////////////////////////////////////////////////////
255 // Register the MDI frame window class.
256 WNDCLASS wndclass1
; // Structure used to register Windows class.
258 wndclass1
.style
= CS_HREDRAW
| CS_VREDRAW
;
259 wndclass1
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
260 wndclass1
.cbClsExtra
= 0;
261 wndclass1
.cbWndExtra
= sizeof( DWORD
); // was 4
262 wndclass1
.hInstance
= wxhInstance
;
263 wndclass1
.hIcon
= NULL
; // wxSTD_MDIPARENTFRAME_ICON;
264 wndclass1
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
265 // wndclass1.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1) ;
266 wndclass1
.hbrBackground
= NULL
;
267 wndclass1
.lpszMenuName
= NULL
;
269 wndclass1
.lpszClassName
= wxMDIFrameClassName
;
270 if (!RegisterClass( &wndclass1
))
272 // wxFatalError("Can't register MDI Frame window class");
276 ///////////////////////////////////////////////////////////////////////
277 // Register the MDI child frame window class.
278 WNDCLASS wndclass4
; // Structure used to register Windows class.
280 wndclass4
.style
= CS_HREDRAW
| CS_VREDRAW
;
281 wndclass4
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
282 wndclass4
.cbClsExtra
= 0;
283 wndclass4
.cbWndExtra
= sizeof( DWORD
); // was 4
284 wndclass4
.hInstance
= wxhInstance
;
285 wndclass4
.hIcon
= NULL
; // wxSTD_MDICHILDFRAME_ICON;
286 wndclass4
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
287 // TODO: perhaps this should be NULL so that Windows doesn't
288 // paint the background itself (would OnEraseBackground duplicate
290 wndclass4
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1) ;
291 // wndclass4.hbrBackground = NULL;
292 wndclass4
.lpszMenuName
= NULL
;
293 wndclass4
.lpszClassName
= wxMDIChildFrameClassName
;
295 if (!RegisterClass( &wndclass4
))
297 // wxFatalError("Can't register MDI child frame window class");
301 ///////////////////////////////////////////////////////////////////////
302 // Register the panel window class.
303 WNDCLASS wndclass2
; // Structure used to register Windows class.
304 memset(&wndclass2
, 0, sizeof(WNDCLASS
)); // start with NULL defaults
305 // Use CS_OWNDC to avoid messing about restoring the context
306 // for every graphic operation.
307 wndclass2
.style
= CS_HREDRAW
| CS_VREDRAW
;
308 wndclass2
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
309 wndclass2
.cbClsExtra
= 0;
310 wndclass2
.cbWndExtra
= sizeof( DWORD
); // was 4
311 wndclass2
.hInstance
= wxhInstance
;
312 wndclass2
.hIcon
= NULL
;
313 wndclass2
.hCursor
= NULL
;
314 // wndclass2.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1) ;
315 wndclass2
.hbrBackground
= (HBRUSH
) GetStockObject( LTGRAY_BRUSH
);
316 wndclass2
.lpszMenuName
= NULL
;
317 wndclass2
.lpszClassName
= wxPanelClassName
;
318 if (!RegisterClass( &wndclass2
))
320 // wxFatalError("Can't register Panel Window class");
324 ///////////////////////////////////////////////////////////////////////
325 // Register the canvas and textsubwindow class name
326 WNDCLASS wndclass3
; // Structure used to register Windows class.
327 memset(&wndclass3
, 0, sizeof(WNDCLASS
)); // start with NULL defaults
328 // Use CS_OWNDC to avoid messing about restoring the context
329 // for every graphic operation.
330 // wndclass3.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS ;
332 wndclass3
.style
= CS_HREDRAW
| CS_VREDRAW
| CS_DBLCLKS
;
333 wndclass3
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
334 wndclass3
.cbClsExtra
= 0;
335 wndclass3
.cbWndExtra
= sizeof( DWORD
); // was 4
336 wndclass3
.hInstance
= wxhInstance
;
337 wndclass3
.hIcon
= NULL
;
338 wndclass3
.hCursor
= NULL
;
339 // wndclass3.hbrBackground = (HBRUSH)(COLOR_WINDOW+1) ;
340 wndclass3
.hbrBackground
= NULL
;
341 wndclass3
.lpszMenuName
= NULL
;
342 wndclass3
.lpszClassName
= wxCanvasClassName
;
343 if (!RegisterClass( &wndclass3
))
345 // wxFatalError("Can't register Canvas class");
352 //// Convert Windows to argc, argv style
354 void wxApp::ConvertToStandardCommandArgs(char* lpCmdLine
)
358 wxString
cmdLine(lpCmdLine
);
361 // Get application name
362 char name
[260]; // 260 is MAX_PATH value from windef.h
363 ::GetModuleFileName(wxhInstance
, name
, WXSIZEOF(name
));
365 // GNUWIN32 already fills in the first arg with the application name.
366 #if !defined(__GNUWIN32__)
371 strcpy(name
, wxFileNameFromPath(name
));
372 wxStripExtension(name
);
373 wxTheApp
->SetAppName(name
);
376 // Treat strings enclosed in double-quotes as single arguments
378 int len
= cmdLine
.Length();
382 while ((i
< len
) && isspace(cmdLine
.GetChar(i
)))
387 if (cmdLine
.GetChar(i
) == '"') // We found the start of a string
391 while ((i
< len
) && (cmdLine
.GetChar(i
) != '"'))
394 wxString
arg(cmdLine
.Mid(first
, (i
- first
)));
400 i
++; // Skip past 2nd quote
402 else // Unquoted argument
405 while ((i
< len
) && !isspace(cmdLine
.GetChar(i
)))
408 wxString
arg(cmdLine
.Mid(first
, (i
- first
)));
416 wxTheApp
->argv
= new char*[count
+ 1];
417 for (i
= 0; i
< count
; i
++)
419 wxString
arg(args
[i
]);
420 wxTheApp
->argv
[i
] = copystring((const char*)arg
);
422 wxTheApp
->argv
[count
] = NULL
; // argv[] is a NULL-terminated list
423 wxTheApp
->argc
= count
;
426 //// Cleans up any wxWindows internal structures left lying around
428 void wxApp::CleanUp()
431 wxModule::CleanUpModules();
433 #if wxUSE_WX_RESOURCES
434 wxCleanUpResourceSystem();
436 // wxDefaultResourceTable->ClearTable();
439 // Indicate that the cursor can be freed,
440 // so that cursor won't be deleted by deleting
441 // the bitmap list before g_globalCursor goes out
442 // of scope (double deletion of the cursor).
443 wxSetCursor(wxNullCursor
);
444 delete g_globalCursor
;
446 wxDeleteStockObjects() ;
448 // Destroy all GDI lists, etc.
449 wxDeleteStockLists();
451 delete wxTheColourDatabase
;
452 wxTheColourDatabase
= NULL
;
454 wxBitmap::CleanUpHandlers();
459 //// WINDOWS-SPECIFIC CLEANUP
461 wxSetKeyboardHook(FALSE
);
464 if (gs_hRichEdit
!= NULL
)
465 FreeLibrary(gs_hRichEdit
);
472 if (wxSTD_FRAME_ICON
)
473 DestroyIcon(wxSTD_FRAME_ICON
);
474 if (wxSTD_MDICHILDFRAME_ICON
)
475 DestroyIcon(wxSTD_MDICHILDFRAME_ICON
);
476 if (wxSTD_MDIPARENTFRAME_ICON
)
477 DestroyIcon(wxSTD_MDIPARENTFRAME_ICON
);
479 if (wxDEFAULT_FRAME_ICON
)
480 DestroyIcon(wxDEFAULT_FRAME_ICON
);
481 if (wxDEFAULT_MDICHILDFRAME_ICON
)
482 DestroyIcon(wxDEFAULT_MDICHILDFRAME_ICON
);
483 if (wxDEFAULT_MDIPARENTFRAME_ICON
)
484 DestroyIcon(wxDEFAULT_MDIPARENTFRAME_ICON
);
486 if ( wxDisableButtonBrush
)
487 ::DeleteObject( wxDisableButtonBrush
) ;
492 Ctl3dUnregister(wxhInstance
);
496 delete wxWinHandleList
;
498 wxClassInfo::CleanUpClasses();
503 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
504 // At this point we want to check if there are any memory
505 // blocks that aren't part of the wxDebugContext itself,
506 // as a special case. Then when dumping we need to ignore
507 // wxDebugContext, too.
508 if (wxDebugContext::CountObjectsLeft() > 0)
510 wxLogDebug("There were memory leaks.");
511 wxDebugContext::Dump();
512 wxDebugContext::PrintStatistics();
514 // wxDebugContext::SetStream(NULL, NULL);
517 // do it as the very last thing because everything else can log messages
518 wxLog::DontCreateOnDemand();
519 delete wxLog::SetActiveTarget(NULL
);
522 #if !defined(_WINDLL) || (defined(_WINDLL) && defined(WXMAKINGDLL))
524 //// Main wxWindows entry point
525 int wxEntry(WXHINSTANCE hInstance
,
526 WXHINSTANCE
WXUNUSED(hPrevInstance
),
531 #ifndef __WXDEBUG__ // take everything into a try-except block in release build
535 wxhInstance
= (HINSTANCE
) hInstance
;
537 if (!wxApp::Initialize())
540 // create the application object or ensure that one already exists
543 // The app may have declared a global application object, but we recommend
544 // the IMPLEMENT_APP macro is used instead, which sets an initializer
545 // function for delayed, dynamic app object construction.
546 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
547 "No initializer - use IMPLEMENT_APP macro." );
549 wxTheApp
= (*wxApp::GetInitializerFunction()) ();
552 wxCHECK_MSG( wxTheApp
, 0, "You have to define an instance of wxApp!" );
554 // save the WinMain() parameters
555 wxTheApp
->ConvertToStandardCommandArgs(lpCmdLine
);
556 wxTheApp
->m_nCmdShow
= nCmdShow
;
558 // GUI-specific initialisation. In fact on Windows we don't have any,
559 // but this call is provided for compatibility across platforms.
560 wxTheApp
->OnInitGui() ;
564 if ( wxTheApp
->OnInit() )
568 retValue
= wxTheApp
->OnRun();
571 //else: app initialization failed, so we skipped OnRun()
573 wxWindow
*topWindow
= wxTheApp
->GetTopWindow();
576 // Forcibly delete the window.
577 if ( topWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
578 topWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
580 topWindow
->Close(TRUE
);
581 wxTheApp
->DeletePendingObjects();
586 wxTheApp
->SetTopWindow(NULL
);
592 // flush the logged messages if any
593 wxLog
*pLog
= wxLog::GetActiveTarget();
594 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
601 #ifndef __WXDEBUG__ // catch exceptions only in release build
603 except ( EXCEPTION_EXECUTE_HANDLER
) {
606 wxTheApp->OnFatalException();
609 ::ExitProcess(3); // the same exit code as abort()
616 //// Entry point for DLLs
618 int wxEntry(WXHINSTANCE hInstance
)
620 wxhInstance
= (HINSTANCE
) hInstance
;
623 // The app may have declared a global application object, but we recommend
624 // the IMPLEMENT_APP macro is used instead, which sets an initializer function
625 // for delayed, dynamic app object construction.
629 if (!wxApp::GetInitializerFunction())
631 MessageBox(NULL
, "No initializer - use IMPLEMENT_APP macro.", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
635 wxTheApp
= (* wxApp::GetInitializerFunction()) ();
639 MessageBox(NULL
, "You have to define an instance of wxApp!", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
644 wxTheApp
->argv
= NULL
;
646 wxTheApp
->OnInitGui();
650 if (wxTheApp
->GetTopWindow() && wxTheApp
->GetTopWindow()->GetHWND()) {
651 wxTheApp
->GetTopWindow()->Show(TRUE
);
658 //// Static member initialization
660 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
667 m_wantDebugOutput
= TRUE
;
672 m_printMode
= wxPRINT_WINDOWS
;
674 m_printMode
= wxPRINT_POSTSCRIPT
;
676 m_exitOnFrameDelete
= TRUE
;
682 // Delete command-line args
684 for (i
= 0; i
< argc
; i
++)
691 bool wxApp::Initialized()
699 #ifdef _WINDLL // Assume initialized if DLL (no way of telling)
705 * Get and process a message, returning FALSE if WM_QUIT
709 bool wxApp::DoMessage()
711 if (!::GetMessage(&s_currentMsg
, (HWND
) NULL
, 0, 0))
716 // Process the message
717 if (!ProcessMessage((WXMSG
*)&s_currentMsg
))
719 ::TranslateMessage(&s_currentMsg
);
720 wxApp::sm_lastMessageTime
= s_currentMsg
.time
; /* MATTHEW: timeStamp impl. */
721 ::DispatchMessage(&s_currentMsg
);
727 * Keep trying to process messages until WM_QUIT
730 * If there are messages to be processed, they will all be
731 * processed and OnIdle will not be called.
732 * When there are no more messages, OnIdle is called.
733 * If OnIdle requests more time,
734 * it will be repeatedly called so long as there are no pending messages.
735 * A 'feature' of this is that once OnIdle has decided that no more processing
736 * is required, then it won't get processing time until further messages
737 * are processed (it'll sit in DoMessage).
740 int wxApp::MainLoop()
745 while (!::PeekMessage(&s_currentMsg
, 0, 0, 0, PM_NOREMOVE
) &&
751 return s_currentMsg
.wParam
;
754 // Returns TRUE if more time is needed.
755 bool wxApp::ProcessIdle()
758 event
.SetEventObject(this);
761 return event
.MoreRequested();
764 void wxApp::ExitMainLoop()
769 bool wxApp::Pending()
771 return (::PeekMessage(&s_currentMsg
, 0, 0, 0, PM_NOREMOVE
) != 0) ;
774 void wxApp::Dispatch()
781 * Give all windows a chance to preprocess
782 * the message. Some may have accelerator tables, or have
785 bool wxApp::ProcessMessage(WXMSG
*Msg
)
787 MSG
*msg
= (MSG
*)Msg
;
791 // Try translations first; find the youngest window with
792 // a translation table.
793 for (hWnd
= msg
->hwnd
; hWnd
!= NULL
; hWnd
= ::GetParent(hWnd
))
795 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
798 if (wnd
->MSWTranslateMessage(Msg
))
803 // Anyone for a non-translation message? Try youngest descendants first.
804 for (hWnd
= msg
->hwnd
; hWnd
!= NULL
; hWnd
= ::GetParent(hWnd
))
806 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
809 if (wnd
->MSWProcessMessage(Msg
))
816 void wxApp::OnIdle(wxIdleEvent
& event
)
818 static bool inOnIdle
= FALSE
;
820 // Avoid recursion (via ProcessEvent default case)
826 // 'Garbage' collection of windows deleted with Close().
827 DeletePendingObjects();
829 // flush the logged messages if any
830 wxLog
*pLog
= wxLog::GetActiveTarget();
831 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
834 // Send OnIdle events to all windows
835 bool needMore
= SendIdleEvents();
836 // bool needMore = FALSE;
839 event
.RequestMore(TRUE
);
844 // Send idle event to all top-level windows
845 bool wxApp::SendIdleEvents()
847 bool needMore
= FALSE
;
848 wxNode
* node
= wxTopLevelWindows
.First();
851 wxWindow
* win
= (wxWindow
*) node
->Data();
852 if (SendIdleEvents(win
))
860 // Send idle event to window and all subwindows
861 bool wxApp::SendIdleEvents(wxWindow
* win
)
863 bool needMore
= FALSE
;
866 event
.SetEventObject(win
);
867 win
->GetEventHandler()->ProcessEvent(event
);
869 if (event
.MoreRequested())
872 wxNode
* node
= win
->GetChildren().First();
875 wxWindow
* win
= (wxWindow
*) node
->Data();
876 if (SendIdleEvents(win
))
884 void wxApp::DeletePendingObjects()
886 wxNode
*node
= wxPendingDelete
.First();
889 wxObject
*obj
= (wxObject
*)node
->Data();
893 if (wxPendingDelete
.Member(obj
))
896 // Deleting one object may have deleted other pending
897 // objects, so start from beginning of list again.
898 node
= wxPendingDelete
.First();
902 void wxApp::OnEndSession(wxCloseEvent
& event
)
905 GetTopWindow()->Close(TRUE
);
908 // Default behaviour: close the application with prompts. The
909 // user can veto the close, and therefore the end session.
910 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
914 if (!GetTopWindow()->Close(!event
.CanVeto()))
919 wxLog
* wxApp::CreateLogTarget()
924 wxWindow
* wxApp::GetTopWindow() const
928 else if (wxTopLevelWindows
.Number() > 0)
929 return (wxWindow
*) wxTopLevelWindows
.First()->Data();
934 int wxApp::GetComCtl32Version() const
936 // have we loaded COMCTL32 yet?
937 HMODULE theModule
= ::GetModuleHandle("COMCTL32");
940 // if so, then we can check for the version
943 // InitCommonControlsEx is unique to 4.7 and later
944 FARPROC theProc
= ::GetProcAddress(theModule
, "InitCommonControlsEx");
947 { // not found, must be 4.00
952 // The following symbol are unique to 4.71
954 // FlatSB_EnableScrollBar FlatSB_GetScrollInfo FlatSB_GetScrollPos
955 // FlatSB_GetScrollProp FlatSB_GetScrollRange FlatSB_SetScrollInfo
956 // FlatSB_SetScrollPos FlatSB_SetScrollProp FlatSB_SetScrollRange
957 // FlatSB_ShowScrollBar
958 // _DrawIndirectImageList _DuplicateImageList
960 // UninitializeFlatSB
961 // we could check for any of these - I chose DllInstall
962 FARPROC theProc
= ::GetProcAddress(theModule
, "DllInstall");
965 // not found, must be 4.70
969 { // found, must be 4.71
980 FatalAppExit(0, "Fatal error: exiting");
983 // Yield to incoming messages
987 // We want to go back to the main message loop
988 // if we see a WM_QUIT. (?)
989 while (PeekMessage(&msg
, NULL
, 0, 0, PM_NOREMOVE
) && msg
.message
!= WM_QUIT
)
991 if (!wxTheApp
->DoMessage())
998 HINSTANCE
wxGetInstance()
1003 // For some reason, with MSVC++ 1.5, WinMain isn't linked in properly
1004 // if in a separate file. So include it here to ensure it's linked.
1005 #if (defined(_MSC_VER) && !defined(__WIN32__)) || defined(__GNUWIN32__)