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
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");
157 #if defined(WX_DRAG_DROP)
158 // we need to initialize OLE library
159 if ( FAILED(::OleInitialize(NULL
)) )
160 wxFatalError(_("Cannot initialize OLE"));
164 if (!Ctl3dRegister(wxhInstance
))
165 wxFatalError("Cannot register CTL3D");
167 Ctl3dAutoSubclass(wxhInstance
);
170 g_globalCursor
= new wxCursor
;
172 wxSTD_FRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_FRAME");
173 wxSTD_MDIPARENTFRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_MDIPARENTFRAME");
174 wxSTD_MDICHILDFRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_MDICHILDFRAME");
176 wxDEFAULT_FRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_FRAME");
177 wxDEFAULT_MDIPARENTFRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_MDIPARENTFRAME");
178 wxDEFAULT_MDICHILDFRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_MDICHILDFRAME");
180 RegisterWindowClasses();
182 // Create the brush for disabling bitmap buttons
185 lb
.lbStyle
= BS_PATTERN
;
186 lb
.lbHatch
= (int)LoadBitmap( wxhInstance
, "wxDISABLE_BUTTON_BITMAP" ) ;
187 wxDisableButtonBrush
= ::CreateBrushIndirect( & lb
) ;
188 ::DeleteObject( (HGDIOBJ
)lb
.lbHatch
) ;
194 wxWinHandleList
= new wxList(wxKEY_INTEGER
);
196 // This is to foil optimizations in Visual C++ that
197 // throw out dummy.obj.
198 #if (_MSC_VER >= 800) && !defined(WXMAKINGDLL)
199 extern char wxDummyChar
;
200 if (wxDummyChar
) wxDummyChar
++;
203 wxSetKeyboardHook(TRUE
);
205 wxModule::RegisterModules();
206 if (!wxModule::InitializeModules())
211 //// RegisterWindowClasses
213 bool wxApp::RegisterWindowClasses()
215 ///////////////////////////////////////////////////////////////////////
216 // Register the frame window class.
217 WNDCLASS wndclass
; // Structure used to register Windows class.
219 wndclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
220 wndclass
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
221 wndclass
.cbClsExtra
= 0;
222 wndclass
.cbWndExtra
= sizeof( DWORD
); // was 4
223 wndclass
.hInstance
= wxhInstance
;
224 wndclass
.hIcon
= NULL
; // wxSTD_FRAME_ICON;
225 wndclass
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
226 wndclass
.hbrBackground
= (HBRUSH
)(COLOR_APPWORKSPACE
+1) ;
227 // wndclass.hbrBackground = GetStockObject( WHITE_BRUSH );
228 wndclass
.lpszMenuName
= NULL
;
229 #ifdef _MULTIPLE_INSTANCES
230 sprintf( wxFrameClassName
,"wxFrameClass%d", wxhInstance
);
232 wndclass
.lpszClassName
= wxFrameClassName
;
234 if (!RegisterClass( &wndclass
))
236 // wxFatalError("Can't register Frame Window class");
239 ///////////////////////////////////////////////////////////////////////
240 // Register the MDI frame window class.
241 WNDCLASS wndclass1
; // Structure used to register Windows class.
243 wndclass1
.style
= CS_HREDRAW
| CS_VREDRAW
;
244 wndclass1
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
245 wndclass1
.cbClsExtra
= 0;
246 wndclass1
.cbWndExtra
= sizeof( DWORD
); // was 4
247 wndclass1
.hInstance
= wxhInstance
;
248 wndclass1
.hIcon
= NULL
; // wxSTD_MDIPARENTFRAME_ICON;
249 wndclass1
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
250 // wndclass1.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1) ;
251 wndclass1
.hbrBackground
= NULL
;
252 wndclass1
.lpszMenuName
= NULL
;
254 wndclass1
.lpszClassName
= wxMDIFrameClassName
;
255 if (!RegisterClass( &wndclass1
))
257 // wxFatalError("Can't register MDI Frame window class");
261 ///////////////////////////////////////////////////////////////////////
262 // Register the MDI child frame window class.
263 WNDCLASS wndclass4
; // Structure used to register Windows class.
265 wndclass4
.style
= CS_HREDRAW
| CS_VREDRAW
;
266 wndclass4
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
267 wndclass4
.cbClsExtra
= 0;
268 wndclass4
.cbWndExtra
= sizeof( DWORD
); // was 4
269 wndclass4
.hInstance
= wxhInstance
;
270 wndclass4
.hIcon
= NULL
; // wxSTD_MDICHILDFRAME_ICON;
271 wndclass4
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
272 // TODO: perhaps this should be NULL so that Windows doesn't
273 // paint the background itself (would OnEraseBackground duplicate
275 wndclass4
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1) ;
276 // wndclass4.hbrBackground = NULL;
277 wndclass4
.lpszMenuName
= NULL
;
278 wndclass4
.lpszClassName
= wxMDIChildFrameClassName
;
280 if (!RegisterClass( &wndclass4
))
282 // wxFatalError("Can't register MDI child frame window class");
286 ///////////////////////////////////////////////////////////////////////
287 // Register the panel window class.
288 WNDCLASS wndclass2
; // Structure used to register Windows class.
289 memset(&wndclass2
, 0, sizeof(WNDCLASS
)); // start with NULL defaults
290 // Use CS_OWNDC to avoid messing about restoring the context
291 // for every graphic operation.
292 wndclass2
.style
= CS_HREDRAW
| CS_VREDRAW
;
293 wndclass2
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
294 wndclass2
.cbClsExtra
= 0;
295 wndclass2
.cbWndExtra
= sizeof( DWORD
); // was 4
296 wndclass2
.hInstance
= wxhInstance
;
297 wndclass2
.hIcon
= NULL
;
298 wndclass2
.hCursor
= NULL
;
299 // wndclass2.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1) ;
300 wndclass2
.hbrBackground
= (HBRUSH
) GetStockObject( LTGRAY_BRUSH
);
301 wndclass2
.lpszMenuName
= NULL
;
302 wndclass2
.lpszClassName
= wxPanelClassName
;
303 if (!RegisterClass( &wndclass2
))
305 // wxFatalError("Can't register Panel Window class");
309 ///////////////////////////////////////////////////////////////////////
310 // Register the canvas and textsubwindow class name
311 WNDCLASS wndclass3
; // Structure used to register Windows class.
312 memset(&wndclass3
, 0, sizeof(WNDCLASS
)); // start with NULL defaults
313 // Use CS_OWNDC to avoid messing about restoring the context
314 // for every graphic operation.
315 // wndclass3.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS ;
317 wndclass3
.style
= CS_HREDRAW
| CS_VREDRAW
| CS_DBLCLKS
;
318 wndclass3
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
319 wndclass3
.cbClsExtra
= 0;
320 wndclass3
.cbWndExtra
= sizeof( DWORD
); // was 4
321 wndclass3
.hInstance
= wxhInstance
;
322 wndclass3
.hIcon
= NULL
;
323 wndclass3
.hCursor
= NULL
;
324 // wndclass3.hbrBackground = (HBRUSH)(COLOR_WINDOW+1) ;
325 wndclass3
.hbrBackground
= NULL
;
326 wndclass3
.lpszMenuName
= NULL
;
327 wndclass3
.lpszClassName
= wxCanvasClassName
;
328 if (!RegisterClass( &wndclass3
))
330 // wxFatalError("Can't register Canvas class");
337 //// Convert Windows to argc, argv style
339 void wxApp::ConvertToStandardCommandArgs(char* lpCmdLine
)
343 wxString
cmdLine(lpCmdLine
);
346 // Get application name
347 char name
[260]; // 260 is MAX_PATH value from windef.h
348 ::GetModuleFileName(wxhInstance
, name
, WXSIZEOF(name
));
350 // GNUWIN32 already fills in the first arg with the application name.
351 #if !defined(__GNUWIN32__)
356 strcpy(name
, wxFileNameFromPath(name
));
357 wxStripExtension(name
);
358 wxTheApp
->SetAppName(name
);
361 // Treat strings enclosed in double-quotes as single arguments
363 int len
= cmdLine
.Length();
367 while ((i
< len
) && isspace(cmdLine
.GetChar(i
)))
372 if (cmdLine
.GetChar(i
) == '"') // We found the start of a string
376 while ((i
< len
) && (cmdLine
.GetChar(i
) != '"'))
379 wxString
arg(cmdLine
.Mid(first
, (i
- first
)));
385 i
++; // Skip past 2nd quote
387 else // Unquoted argument
390 while ((i
< len
) && !isspace(cmdLine
.GetChar(i
)))
393 wxString
arg(cmdLine
.Mid(first
, (i
- first
)));
401 wxTheApp
->argv
= new char*[count
+ 1];
402 for (i
= 0; i
< count
; i
++)
404 wxString
arg(args
[i
]);
405 wxTheApp
->argv
[i
] = copystring((const char*)arg
);
407 wxTheApp
->argv
[count
] = NULL
; // argv[] is a NULL-terminated list
408 wxTheApp
->argc
= count
;
411 //// Cleans up any wxWindows internal structures left lying around
413 void wxApp::CleanUp()
416 wxModule::CleanUpModules();
418 #if wxUSE_WX_RESOURCES
419 wxCleanUpResourceSystem();
421 // wxDefaultResourceTable->ClearTable();
424 // Indicate that the cursor can be freed,
425 // so that cursor won't be deleted by deleting
426 // the bitmap list before g_globalCursor goes out
427 // of scope (double deletion of the cursor).
428 wxSetCursor(wxNullCursor
);
429 delete g_globalCursor
;
431 wxDeleteStockObjects() ;
433 // Destroy all GDI lists, etc.
434 wxDeleteStockLists();
436 delete wxTheColourDatabase
;
437 wxTheColourDatabase
= NULL
;
439 wxBitmap::CleanUpHandlers();
444 //// WINDOWS-SPECIFIC CLEANUP
446 wxSetKeyboardHook(FALSE
);
449 if (gs_hRichEdit
!= NULL
)
450 FreeLibrary(gs_hRichEdit
);
457 if (wxSTD_FRAME_ICON
)
458 DestroyIcon(wxSTD_FRAME_ICON
);
459 if (wxSTD_MDICHILDFRAME_ICON
)
460 DestroyIcon(wxSTD_MDICHILDFRAME_ICON
);
461 if (wxSTD_MDIPARENTFRAME_ICON
)
462 DestroyIcon(wxSTD_MDIPARENTFRAME_ICON
);
464 if (wxDEFAULT_FRAME_ICON
)
465 DestroyIcon(wxDEFAULT_FRAME_ICON
);
466 if (wxDEFAULT_MDICHILDFRAME_ICON
)
467 DestroyIcon(wxDEFAULT_MDICHILDFRAME_ICON
);
468 if (wxDEFAULT_MDIPARENTFRAME_ICON
)
469 DestroyIcon(wxDEFAULT_MDIPARENTFRAME_ICON
);
471 if ( wxDisableButtonBrush
)
472 ::DeleteObject( wxDisableButtonBrush
) ;
474 #if defined(WX_DRAG_DROP)
479 Ctl3dUnregister(wxhInstance
);
483 delete wxWinHandleList
;
485 wxClassInfo::CleanUpClasses();
490 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
491 // At this point we want to check if there are any memory
492 // blocks that aren't part of the wxDebugContext itself,
493 // as a special case. Then when dumping we need to ignore
494 // wxDebugContext, too.
495 if (wxDebugContext::CountObjectsLeft() > 0)
497 wxLogDebug("There were memory leaks.");
498 wxDebugContext::Dump();
499 wxDebugContext::PrintStatistics();
501 // wxDebugContext::SetStream(NULL, NULL);
504 // do it as the very last thing because everything else can log messages
505 wxLog::DontCreateOnDemand();
506 delete wxLog::SetActiveTarget(NULL
);
509 #if !defined(_WINDLL) || (defined(_WINDLL) && defined(WXMAKINGDLL))
511 //// Main wxWindows entry point
512 int wxEntry(WXHINSTANCE hInstance
,
513 WXHINSTANCE
WXUNUSED(hPrevInstance
),
518 #ifndef __WXDEBUG__ // take everything into a try-except block in release build
522 wxhInstance
= (HINSTANCE
) hInstance
;
524 if (!wxApp::Initialize())
527 // create the application object or ensure that one already exists
530 // The app may have declared a global application object, but we recommend
531 // the IMPLEMENT_APP macro is used instead, which sets an initializer
532 // function for delayed, dynamic app object construction.
533 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
534 "No initializer - use IMPLEMENT_APP macro." );
536 wxTheApp
= (*wxApp::GetInitializerFunction()) ();
539 wxCHECK_MSG( wxTheApp
, 0, "You have to define an instance of wxApp!" );
541 // save the WinMain() parameters
542 wxTheApp
->ConvertToStandardCommandArgs(lpCmdLine
);
543 wxTheApp
->m_nCmdShow
= nCmdShow
;
545 // GUI-specific initialisation. In fact on Windows we don't have any,
546 // but this call is provided for compatibility across platforms.
547 wxTheApp
->OnInitGui() ;
551 if ( wxTheApp
->OnInit() )
555 retValue
= wxTheApp
->OnRun();
558 //else: app initialization failed, so we skipped OnRun()
560 wxWindow
*topWindow
= wxTheApp
->GetTopWindow();
563 // Forcibly delete the window.
564 if ( topWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
565 topWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
567 topWindow
->Close(TRUE
);
568 wxTheApp
->DeletePendingObjects();
573 wxTheApp
->SetTopWindow(NULL
);
579 // flush the logged messages if any
580 wxLog
*pLog
= wxLog::GetActiveTarget();
581 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
588 #ifndef __WXDEBUG__ // catch exceptions only in release build
590 except ( EXCEPTION_EXECUTE_HANDLER
) {
593 wxTheApp->OnFatalException();
596 ::ExitProcess(3); // the same exit code as abort()
603 //// Entry point for DLLs
605 int wxEntry(WXHINSTANCE hInstance
)
607 wxhInstance
= (HINSTANCE
) hInstance
;
610 // The app may have declared a global application object, but we recommend
611 // the IMPLEMENT_APP macro is used instead, which sets an initializer function
612 // for delayed, dynamic app object construction.
616 if (!wxApp::GetInitializerFunction())
618 MessageBox(NULL
, "No initializer - use IMPLEMENT_APP macro.", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
622 wxTheApp
= (* wxApp::GetInitializerFunction()) ();
626 MessageBox(NULL
, "You have to define an instance of wxApp!", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
631 wxTheApp
->argv
= NULL
;
633 wxTheApp
->OnInitGui();
637 if (wxTheApp
->GetTopWindow() && wxTheApp
->GetTopWindow()->GetHWND()) {
638 wxTheApp
->GetTopWindow()->Show(TRUE
);
645 //// Static member initialization
647 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
654 m_wantDebugOutput
= TRUE
;
659 m_printMode
= wxPRINT_WINDOWS
;
661 m_printMode
= wxPRINT_POSTSCRIPT
;
663 m_exitOnFrameDelete
= TRUE
;
669 // Delete command-line args
671 for (i
= 0; i
< argc
; i
++)
678 bool wxApp::Initialized()
686 #ifdef _WINDLL // Assume initialized if DLL (no way of telling)
692 * Get and process a message, returning FALSE if WM_QUIT
696 bool wxApp::DoMessage()
698 if (!::GetMessage(&s_currentMsg
, (HWND
) NULL
, 0, 0))
703 // Process the message
704 if (!ProcessMessage((WXMSG
*)&s_currentMsg
))
706 ::TranslateMessage(&s_currentMsg
);
707 wxApp::sm_lastMessageTime
= s_currentMsg
.time
; /* MATTHEW: timeStamp impl. */
708 ::DispatchMessage(&s_currentMsg
);
714 * Keep trying to process messages until WM_QUIT
717 * If there are messages to be processed, they will all be
718 * processed and OnIdle will not be called.
719 * When there are no more messages, OnIdle is called.
720 * If OnIdle requests more time,
721 * it will be repeatedly called so long as there are no pending messages.
722 * A 'feature' of this is that once OnIdle has decided that no more processing
723 * is required, then it won't get processing time until further messages
724 * are processed (it'll sit in DoMessage).
727 int wxApp::MainLoop()
732 while (!::PeekMessage(&s_currentMsg
, 0, 0, 0, PM_NOREMOVE
) &&
738 return s_currentMsg
.wParam
;
741 // Returns TRUE if more time is needed.
742 bool wxApp::ProcessIdle()
745 event
.SetEventObject(this);
748 return event
.MoreRequested();
751 void wxApp::ExitMainLoop()
756 bool wxApp::Pending()
758 return (::PeekMessage(&s_currentMsg
, 0, 0, 0, PM_NOREMOVE
) != 0) ;
761 void wxApp::Dispatch()
768 * Give all windows a chance to preprocess
769 * the message. Some may have accelerator tables, or have
772 bool wxApp::ProcessMessage(WXMSG
*Msg
)
774 MSG
*msg
= (MSG
*)Msg
;
778 // Try translations first; find the youngest window with
779 // a translation table.
780 for (hWnd
= msg
->hwnd
; hWnd
!= NULL
; hWnd
= ::GetParent(hWnd
))
782 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
785 if (wnd
->MSWTranslateMessage(Msg
))
790 // Anyone for a non-translation message? Try youngest descendants first.
791 for (hWnd
= msg
->hwnd
; hWnd
!= NULL
; hWnd
= ::GetParent(hWnd
))
793 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
796 if (wnd
->MSWProcessMessage(Msg
))
803 void wxApp::OnIdle(wxIdleEvent
& event
)
805 static bool inOnIdle
= FALSE
;
807 // Avoid recursion (via ProcessEvent default case)
813 // 'Garbage' collection of windows deleted with Close().
814 DeletePendingObjects();
816 // flush the logged messages if any
817 wxLog
*pLog
= wxLog::GetActiveTarget();
818 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
821 // Send OnIdle events to all windows
822 bool needMore
= SendIdleEvents();
823 // bool needMore = FALSE;
826 event
.RequestMore(TRUE
);
831 // Send idle event to all top-level windows
832 bool wxApp::SendIdleEvents()
834 bool needMore
= FALSE
;
835 wxNode
* node
= wxTopLevelWindows
.First();
838 wxWindow
* win
= (wxWindow
*) node
->Data();
839 if (SendIdleEvents(win
))
847 // Send idle event to window and all subwindows
848 bool wxApp::SendIdleEvents(wxWindow
* win
)
850 bool needMore
= FALSE
;
853 event
.SetEventObject(win
);
854 win
->GetEventHandler()->ProcessEvent(event
);
856 if (event
.MoreRequested())
859 wxNode
* node
= win
->GetChildren()->First();
862 wxWindow
* win
= (wxWindow
*) node
->Data();
863 if (SendIdleEvents(win
))
871 void wxApp::DeletePendingObjects()
873 wxNode
*node
= wxPendingDelete
.First();
876 wxObject
*obj
= (wxObject
*)node
->Data();
880 if (wxPendingDelete
.Member(obj
))
883 // Deleting one object may have deleted other pending
884 // objects, so start from beginning of list again.
885 node
= wxPendingDelete
.First();
889 void wxApp::OnEndSession(wxCloseEvent
& event
)
892 GetTopWindow()->Close(TRUE
);
895 // Default behaviour: close the application with prompts. The
896 // user can veto the close, and therefore the end session.
897 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
901 if (!GetTopWindow()->Close(!event
.CanVeto()))
906 wxLog
* wxApp::CreateLogTarget()
911 wxWindow
* wxApp::GetTopWindow() const
915 else if (wxTopLevelWindows
.Number() > 0)
916 return (wxWindow
*) wxTopLevelWindows
.First()->Data();
921 int wxApp::GetComCtl32Version() const
923 // have we loaded COMCTL32 yet?
924 HMODULE theModule
= ::GetModuleHandle("COMCTL32");
927 // if so, then we can check for the version
930 // InitCommonControlsEx is unique to 4.7 and later
931 FARPROC theProc
= ::GetProcAddress(theModule
, "InitCommonControlsEx");
934 { // not found, must be 4.00
939 // The following symbol are unique to 4.71
941 // FlatSB_EnableScrollBar FlatSB_GetScrollInfo FlatSB_GetScrollPos
942 // FlatSB_GetScrollProp FlatSB_GetScrollRange FlatSB_SetScrollInfo
943 // FlatSB_SetScrollPos FlatSB_SetScrollProp FlatSB_SetScrollRange
944 // FlatSB_ShowScrollBar
945 // _DrawIndirectImageList _DuplicateImageList
947 // UninitializeFlatSB
948 // we could check for any of these - I chose DllInstall
949 FARPROC theProc
= ::GetProcAddress(theModule
, "DllInstall");
952 // not found, must be 4.70
956 { // found, must be 4.71
967 FatalAppExit(0, "Fatal error: exiting");
970 // Yield to incoming messages
974 // We want to go back to the main message loop
975 // if we see a WM_QUIT. (?)
976 while (PeekMessage(&msg
, NULL
, 0, 0, PM_NOREMOVE
) && msg
.message
!= WM_QUIT
)
978 if (!wxTheApp
->DoMessage())
985 HINSTANCE
wxGetInstance()
990 // For some reason, with MSVC++ 1.5, WinMain isn't linked in properly
991 // if in a separate file. So include it here to ensure it's linked.
992 #if (defined(_MSC_VER) && !defined(__WIN32__)) || defined(__GNUWIN32__)