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 /* This still doesn't work for me, Vadim.
55 #if defined(__WXDEBUG__) && defined(_MSC_VER)
56 // VC++ uses this macro as debug/release mode indicator
65 extern char *wxBuffer
;
66 extern char *wxOsVersion
;
67 extern wxList
*wxWinHandleList
;
68 extern wxList wxPendingDelete
;
69 extern void wxSetKeyboardHook(bool doIt
);
70 extern wxCursor
*g_globalCursor
;
72 HINSTANCE wxhInstance
= 0;
73 static MSG s_currentMsg
;
74 wxApp
*wxTheApp
= NULL
;
76 // @@ why not const? and not static?
77 char wxFrameClassName
[] = "wxFrameClass";
78 char wxMDIFrameClassName
[] = "wxMDIFrameClass";
79 char wxMDIChildFrameClassName
[] = "wxMDIChildFrameClass";
80 char wxPanelClassName
[] = "wxPanelClass";
81 char wxCanvasClassName
[] = "wxCanvasClass";
83 HICON wxSTD_FRAME_ICON
= NULL
;
84 HICON wxSTD_MDICHILDFRAME_ICON
= NULL
;
85 HICON wxSTD_MDIPARENTFRAME_ICON
= NULL
;
87 HICON wxDEFAULT_FRAME_ICON
= NULL
;
88 HICON wxDEFAULT_MDICHILDFRAME_ICON
= NULL
;
89 HICON wxDEFAULT_MDIPARENTFRAME_ICON
= NULL
;
91 HBRUSH wxDisableButtonBrush
= 0;
93 LRESULT APIENTRY
wxWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
95 #if !USE_SHARED_LIBRARY
96 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
98 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
99 EVT_IDLE(wxApp::OnIdle
)
100 EVT_END_SESSION(wxApp::OnEndSession
)
101 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
)
105 long wxApp::sm_lastMessageTime
= 0;
108 static HINSTANCE gs_hRichEdit
= NULL
;
113 bool wxApp::Initialize()
115 wxBuffer
= new char[1500];
118 #if defined(__WXDEBUG__) && defined(_MSC_VER)
119 // do check for memory leaks on program exit
120 // (another useful flag is _CRTDBG_DELAY_FREE_MEM_DF which doesn't free
121 // deallocated memory which may be used to simulate low-memory condition)
122 _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);
123 #endif // debug build under MS VC++
126 #if (WXDEBUG && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
128 streambuf
* sBuf
= NULL
;
130 streambuf
* sBuf
= new wxDebugStreamBuf
;
133 ostream
* oStr
= new ostream(sBuf
) ;
134 wxDebugContext::SetStream(oStr
, sBuf
);
135 #endif // wxUSE_MEMORY_TRACING
137 wxClassInfo::InitializeClasses();
140 wxGetResource("wxWindows", "OsVersion", &wxOsVersion
);
143 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
144 wxTheColourDatabase
->Initialize();
146 wxInitializeStockLists();
147 wxInitializeStockObjects();
149 #if wxUSE_WX_RESOURCES
150 wxInitializeResourceSystem();
153 wxBitmap::InitStandardHandlers();
155 #if defined(__WIN95__)
156 InitCommonControls();
157 gs_hRichEdit
= LoadLibrary("RICHED32.DLL");
159 if (gs_hRichEdit
== NULL
)
161 wxMessageBox("Could not initialise Rich Edit DLL");
165 #if defined(WX_DRAG_DROP)
166 // we need to initialize OLE library
167 if ( FAILED(::OleInitialize(NULL
)) )
168 wxFatalError(_("Cannot initialize OLE"));
172 if (!Ctl3dRegister(wxhInstance
))
173 wxFatalError("Cannot register CTL3D");
175 Ctl3dAutoSubclass(wxhInstance
);
178 g_globalCursor
= new wxCursor
;
180 wxSTD_FRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_FRAME");
181 wxSTD_MDIPARENTFRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_MDIPARENTFRAME");
182 wxSTD_MDICHILDFRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_MDICHILDFRAME");
184 wxDEFAULT_FRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_FRAME");
185 wxDEFAULT_MDIPARENTFRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_MDIPARENTFRAME");
186 wxDEFAULT_MDICHILDFRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_MDICHILDFRAME");
188 RegisterWindowClasses();
190 // Create the brush for disabling bitmap buttons
193 lb
.lbStyle
= BS_PATTERN
;
194 lb
.lbHatch
= (int)LoadBitmap( wxhInstance
, "wxDISABLE_BUTTON_BITMAP" ) ;
195 wxDisableButtonBrush
= ::CreateBrushIndirect( & lb
) ;
196 ::DeleteObject( (HGDIOBJ
)lb
.lbHatch
) ;
202 wxWinHandleList
= new wxList(wxKEY_INTEGER
);
204 // This is to foil optimizations in Visual C++ that
205 // throw out dummy.obj.
206 #if (_MSC_VER >= 800) && !defined(WXMAKINGDLL)
207 extern char wxDummyChar
;
208 if (wxDummyChar
) wxDummyChar
++;
211 wxSetKeyboardHook(TRUE
);
213 wxModule::RegisterModules();
214 if (!wxModule::InitializeModules())
219 //// RegisterWindowClasses
221 bool wxApp::RegisterWindowClasses()
223 ///////////////////////////////////////////////////////////////////////
224 // Register the frame window class.
225 WNDCLASS wndclass
; // Structure used to register Windows class.
227 wndclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
228 wndclass
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
229 wndclass
.cbClsExtra
= 0;
230 wndclass
.cbWndExtra
= sizeof( DWORD
); // was 4
231 wndclass
.hInstance
= wxhInstance
;
232 wndclass
.hIcon
= NULL
; // wxSTD_FRAME_ICON;
233 wndclass
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
234 wndclass
.hbrBackground
= (HBRUSH
)(COLOR_APPWORKSPACE
+1) ;
235 // wndclass.hbrBackground = GetStockObject( WHITE_BRUSH );
236 wndclass
.lpszMenuName
= NULL
;
237 #ifdef _MULTIPLE_INSTANCES
238 sprintf( wxFrameClassName
,"wxFrameClass%d", wxhInstance
);
240 wndclass
.lpszClassName
= wxFrameClassName
;
242 if (!RegisterClass( &wndclass
))
244 // wxFatalError("Can't register Frame Window class");
247 ///////////////////////////////////////////////////////////////////////
248 // Register the MDI frame window class.
249 WNDCLASS wndclass1
; // Structure used to register Windows class.
251 wndclass1
.style
= CS_HREDRAW
| CS_VREDRAW
;
252 wndclass1
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
253 wndclass1
.cbClsExtra
= 0;
254 wndclass1
.cbWndExtra
= sizeof( DWORD
); // was 4
255 wndclass1
.hInstance
= wxhInstance
;
256 wndclass1
.hIcon
= NULL
; // wxSTD_MDIPARENTFRAME_ICON;
257 wndclass1
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
258 // wndclass1.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1) ;
259 wndclass1
.hbrBackground
= NULL
;
260 wndclass1
.lpszMenuName
= NULL
;
262 wndclass1
.lpszClassName
= wxMDIFrameClassName
;
263 if (!RegisterClass( &wndclass1
))
265 // wxFatalError("Can't register MDI Frame window class");
269 ///////////////////////////////////////////////////////////////////////
270 // Register the MDI child frame window class.
271 WNDCLASS wndclass4
; // Structure used to register Windows class.
273 wndclass4
.style
= CS_HREDRAW
| CS_VREDRAW
;
274 wndclass4
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
275 wndclass4
.cbClsExtra
= 0;
276 wndclass4
.cbWndExtra
= sizeof( DWORD
); // was 4
277 wndclass4
.hInstance
= wxhInstance
;
278 wndclass4
.hIcon
= NULL
; // wxSTD_MDICHILDFRAME_ICON;
279 wndclass4
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
280 // TODO: perhaps this should be NULL so that Windows doesn't
281 // paint the background itself (would OnEraseBackground duplicate
283 wndclass4
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1) ;
284 // wndclass4.hbrBackground = NULL;
285 wndclass4
.lpszMenuName
= NULL
;
286 wndclass4
.lpszClassName
= wxMDIChildFrameClassName
;
288 if (!RegisterClass( &wndclass4
))
290 // wxFatalError("Can't register MDI child frame window class");
294 ///////////////////////////////////////////////////////////////////////
295 // Register the panel window class.
296 WNDCLASS wndclass2
; // Structure used to register Windows class.
297 memset(&wndclass2
, 0, sizeof(WNDCLASS
)); // start with NULL defaults
298 // Use CS_OWNDC to avoid messing about restoring the context
299 // for every graphic operation.
300 wndclass2
.style
= CS_HREDRAW
| CS_VREDRAW
;
301 wndclass2
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
302 wndclass2
.cbClsExtra
= 0;
303 wndclass2
.cbWndExtra
= sizeof( DWORD
); // was 4
304 wndclass2
.hInstance
= wxhInstance
;
305 wndclass2
.hIcon
= NULL
;
306 wndclass2
.hCursor
= NULL
;
307 // wndclass2.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1) ;
308 wndclass2
.hbrBackground
= (HBRUSH
) GetStockObject( LTGRAY_BRUSH
);
309 wndclass2
.lpszMenuName
= NULL
;
310 wndclass2
.lpszClassName
= wxPanelClassName
;
311 if (!RegisterClass( &wndclass2
))
313 // wxFatalError("Can't register Panel Window class");
317 ///////////////////////////////////////////////////////////////////////
318 // Register the canvas and textsubwindow class name
319 WNDCLASS wndclass3
; // Structure used to register Windows class.
320 memset(&wndclass3
, 0, sizeof(WNDCLASS
)); // start with NULL defaults
321 // Use CS_OWNDC to avoid messing about restoring the context
322 // for every graphic operation.
323 // wndclass3.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS ;
325 wndclass3
.style
= CS_HREDRAW
| CS_VREDRAW
| CS_DBLCLKS
;
326 wndclass3
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
327 wndclass3
.cbClsExtra
= 0;
328 wndclass3
.cbWndExtra
= sizeof( DWORD
); // was 4
329 wndclass3
.hInstance
= wxhInstance
;
330 wndclass3
.hIcon
= NULL
;
331 wndclass3
.hCursor
= NULL
;
332 // wndclass3.hbrBackground = (HBRUSH)(COLOR_WINDOW+1) ;
333 wndclass3
.hbrBackground
= NULL
;
334 wndclass3
.lpszMenuName
= NULL
;
335 wndclass3
.lpszClassName
= wxCanvasClassName
;
336 if (!RegisterClass( &wndclass3
))
338 // wxFatalError("Can't register Canvas class");
345 //// Convert Windows to argc, argv style
347 void wxApp::ConvertToStandardCommandArgs(char* lpCmdLine
)
351 wxString
cmdLine(lpCmdLine
);
354 // Get application name
356 ::GetModuleFileName(wxhInstance
, name
, WXSIZEOF(name
));
358 // GNUWIN32 already fills in the first arg with the application name.
359 #if !defined(__GNUWIN32__)
364 strcpy(name
, wxFileNameFromPath(name
));
365 wxStripExtension(name
);
366 wxTheApp
->SetAppName(name
);
369 // Treat strings enclosed in double-quotes as single arguments
371 int len
= cmdLine
.Length();
375 while ((i
< len
) && isspace(cmdLine
.GetChar(i
)))
380 if (cmdLine
.GetChar(i
) == '"') // We found the start of a string
384 while ((i
< len
) && (cmdLine
.GetChar(i
) != '"'))
387 wxString
arg(cmdLine
.Mid(first
, (i
- first
)));
393 i
++; // Skip past 2nd quote
395 else // Unquoted argument
398 while ((i
< len
) && !isspace(cmdLine
.GetChar(i
)))
401 wxString
arg(cmdLine
.Mid(first
, (i
- first
)));
409 wxTheApp
->argv
= new char*[count
+ 1];
410 for (i
= 0; i
< count
; i
++)
412 wxString
arg(args
[i
]);
413 wxTheApp
->argv
[i
] = copystring((const char*)arg
);
415 wxTheApp
->argv
[count
] = NULL
; // argv[] is a NULL-terminated list
416 wxTheApp
->argc
= count
;
419 //// Cleans up any wxWindows internal structures left lying around
421 void wxApp::CleanUp()
424 wxModule::CleanUpModules();
426 #if wxUSE_WX_RESOURCES
427 wxCleanUpResourceSystem();
429 // wxDefaultResourceTable->ClearTable();
432 // Indicate that the cursor can be freed,
433 // so that cursor won't be deleted by deleting
434 // the bitmap list before g_globalCursor goes out
435 // of scope (double deletion of the cursor).
436 wxSetCursor(wxNullCursor
);
437 delete g_globalCursor
;
439 wxDeleteStockObjects() ;
441 // Destroy all GDI lists, etc.
442 wxDeleteStockLists();
444 delete wxTheColourDatabase
;
445 wxTheColourDatabase
= NULL
;
447 wxBitmap::CleanUpHandlers();
452 //// WINDOWS-SPECIFIC CLEANUP
454 wxSetKeyboardHook(FALSE
);
457 if (gs_hRichEdit
!= NULL
)
458 FreeLibrary(gs_hRichEdit
);
465 if (wxSTD_FRAME_ICON
)
466 DestroyIcon(wxSTD_FRAME_ICON
);
467 if (wxSTD_MDICHILDFRAME_ICON
)
468 DestroyIcon(wxSTD_MDICHILDFRAME_ICON
);
469 if (wxSTD_MDIPARENTFRAME_ICON
)
470 DestroyIcon(wxSTD_MDIPARENTFRAME_ICON
);
472 if (wxDEFAULT_FRAME_ICON
)
473 DestroyIcon(wxDEFAULT_FRAME_ICON
);
474 if (wxDEFAULT_MDICHILDFRAME_ICON
)
475 DestroyIcon(wxDEFAULT_MDICHILDFRAME_ICON
);
476 if (wxDEFAULT_MDIPARENTFRAME_ICON
)
477 DestroyIcon(wxDEFAULT_MDIPARENTFRAME_ICON
);
479 if ( wxDisableButtonBrush
)
480 ::DeleteObject( wxDisableButtonBrush
) ;
482 #if defined(WX_DRAG_DROP)
487 Ctl3dUnregister(wxhInstance
);
491 delete wxWinHandleList
;
493 wxClassInfo::CleanUpClasses();
495 // do it as the very last thing because everything else can log messages
496 wxLog::DontCreateOnDemand();
497 delete wxLog::SetActiveTarget(NULL
);
500 #if !defined(_WINDLL) || (defined(_WINDLL) && defined(WXMAKINGDLL))
502 //// Main wxWindows entry point
503 int wxEntry(WXHINSTANCE hInstance
,
504 WXHINSTANCE
WXUNUSED(hPrevInstance
),
509 #ifndef __WXDEBUG__ // take everything into a try-except block in release build
513 wxhInstance
= (HINSTANCE
) hInstance
;
515 if (!wxApp::Initialize())
518 // create the application object or ensure that one already exists
521 // The app may have declared a global application object, but we recommend
522 // the IMPLEMENT_APP macro is used instead, which sets an initializer
523 // function for delayed, dynamic app object construction.
524 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
525 "No initializer - use IMPLEMENT_APP macro." );
527 wxTheApp
= (*wxApp::GetInitializerFunction()) ();
530 wxCHECK_MSG( wxTheApp
, 0, "You have to define an instance of wxApp!" );
532 // save the WinMain() parameters
533 wxTheApp
->ConvertToStandardCommandArgs(lpCmdLine
);
534 wxTheApp
->m_nCmdShow
= nCmdShow
;
536 // GUI-specific initialisation. In fact on Windows we don't have any,
537 // but this call is provided for compatibility across platforms.
538 wxTheApp
->OnInitGui() ;
542 if ( wxTheApp
->OnInit() )
546 retValue
= wxTheApp
->OnRun();
549 //else: app initialization failed, so we skipped OnRun()
551 wxWindow
*topWindow
= wxTheApp
->GetTopWindow();
554 // Forcibly delete the window.
555 if ( topWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
556 topWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
558 topWindow
->Close(TRUE
);
559 wxTheApp
->DeletePendingObjects();
564 wxTheApp
->SetTopWindow(NULL
);
574 #if (WXDEBUG && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
575 // At this point we want to check if there are any memory
576 // blocks that aren't part of the wxDebugContext itself,
577 // as a special case. Then when dumping we need to ignore
578 // wxDebugContext, too.
579 if (wxDebugContext::CountObjectsLeft() > 0)
581 wxTrace("There were memory leaks.\n");
582 wxDebugContext::Dump();
583 wxDebugContext::PrintStatistics();
585 wxDebugContext::SetStream(NULL
, NULL
);
589 #ifndef __WXDEBUG__ // catch exceptions only in release build
591 except ( EXCEPTION_EXECUTE_HANDLER
) {
594 wxTheApp->OnFatalException();
597 ::ExitProcess(3); // the same exit code as abort()
604 //// Entry point for DLLs
606 int wxEntry(WXHINSTANCE hInstance
)
608 wxhInstance
= (HINSTANCE
) hInstance
;
611 // The app may have declared a global application object, but we recommend
612 // the IMPLEMENT_APP macro is used instead, which sets an initializer function
613 // for delayed, dynamic app object construction.
617 if (!wxApp::GetInitializerFunction())
619 MessageBox(NULL
, "No initializer - use IMPLEMENT_APP macro.", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
623 wxTheApp
= (* wxApp::GetInitializerFunction()) ();
627 MessageBox(NULL
, "You have to define an instance of wxApp!", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
632 wxTheApp
->argv
= NULL
;
634 wxTheApp
->OnInitGui();
638 if (wxTheApp
->GetTopWindow() && wxTheApp
->GetTopWindow()->GetHWND()) {
639 wxTheApp
->GetTopWindow()->Show(TRUE
);
646 //// Static member initialization
648 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
655 m_wantDebugOutput
= TRUE
;
660 m_printMode
= wxPRINT_WINDOWS
;
662 m_printMode
= wxPRINT_POSTSCRIPT
;
664 m_exitOnFrameDelete
= TRUE
;
670 // Delete command-line args
672 for (i
= 0; i
< argc
; i
++)
679 bool wxApp::Initialized()
687 #ifdef _WINDLL // Assume initialized if DLL (no way of telling)
693 * Get and process a message, returning FALSE if WM_QUIT
697 bool wxApp::DoMessage()
699 if (!::GetMessage(&s_currentMsg
, (HWND
) NULL
, 0, 0))
704 // Process the message
705 if (!ProcessMessage((WXMSG
*)&s_currentMsg
))
707 ::TranslateMessage(&s_currentMsg
);
708 wxApp::sm_lastMessageTime
= s_currentMsg
.time
; /* MATTHEW: timeStamp impl. */
709 ::DispatchMessage(&s_currentMsg
);
715 * Keep trying to process messages until WM_QUIT
718 * If there are messages to be processed, they will all be
719 * processed and OnIdle will not be called.
720 * When there are no more messages, OnIdle is called.
721 * If OnIdle requests more time,
722 * it will be repeatedly called so long as there are no pending messages.
723 * A 'feature' of this is that once OnIdle has decided that no more processing
724 * is required, then it won't get processing time until further messages
725 * are processed (it'll sit in DoMessage).
728 int wxApp::MainLoop()
733 while (!::PeekMessage(&s_currentMsg
, 0, 0, 0, PM_NOREMOVE
) &&
739 return s_currentMsg
.wParam
;
742 // Returns TRUE if more time is needed.
743 bool wxApp::ProcessIdle()
746 event
.SetEventObject(this);
749 return event
.MoreRequested();
752 void wxApp::ExitMainLoop()
757 bool wxApp::Pending()
759 return (::PeekMessage(&s_currentMsg
, 0, 0, 0, PM_NOREMOVE
) != 0) ;
762 void wxApp::Dispatch()
769 * Give all windows a chance to preprocess
770 * the message. Some may have accelerator tables, or have
773 bool wxApp::ProcessMessage(WXMSG
*Msg
)
775 MSG
*msg
= (MSG
*)Msg
;
779 // Try translations first; find the youngest window with
780 // a translation table.
781 for (hWnd
= msg
->hwnd
; hWnd
!= NULL
; hWnd
= ::GetParent(hWnd
))
783 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
786 if (wnd
->MSWTranslateMessage(Msg
))
791 // Anyone for a non-translation message? Try youngest descendants first.
792 for (hWnd
= msg
->hwnd
; hWnd
!= NULL
; hWnd
= ::GetParent(hWnd
))
794 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
797 if (wnd
->MSWProcessMessage(Msg
))
804 void wxApp::OnIdle(wxIdleEvent
& event
)
806 static bool inOnIdle
= FALSE
;
808 // Avoid recursion (via ProcessEvent default case)
814 // 'Garbage' collection of windows deleted with Close().
815 DeletePendingObjects();
817 // flush the logged messages if any
818 wxLog
*pLog
= wxLog::GetActiveTarget();
819 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
822 // Send OnIdle events to all windows
823 bool needMore
= SendIdleEvents();
824 // bool needMore = FALSE;
827 event
.RequestMore(TRUE
);
832 // Send idle event to all top-level windows
833 bool wxApp::SendIdleEvents()
835 bool needMore
= FALSE
;
836 wxNode
* node
= wxTopLevelWindows
.First();
839 wxWindow
* win
= (wxWindow
*) node
->Data();
840 if (SendIdleEvents(win
))
848 // Send idle event to window and all subwindows
849 bool wxApp::SendIdleEvents(wxWindow
* win
)
851 bool needMore
= FALSE
;
854 event
.SetEventObject(win
);
855 win
->ProcessEvent(event
);
857 if (event
.MoreRequested())
860 wxNode
* node
= win
->GetChildren()->First();
863 wxWindow
* win
= (wxWindow
*) node
->Data();
864 if (SendIdleEvents(win
))
872 void wxApp::DeletePendingObjects()
874 wxNode
*node
= wxPendingDelete
.First();
877 wxObject
*obj
= (wxObject
*)node
->Data();
881 if (wxPendingDelete
.Member(obj
))
884 // Deleting one object may have deleted other pending
885 // objects, so start from beginning of list again.
886 node
= wxPendingDelete
.First();
890 void wxApp::OnEndSession(wxCloseEvent
& event
)
893 GetTopWindow()->Close(TRUE
);
896 // Default behaviour: close the application with prompts. The
897 // user can veto the close, and therefore the end session.
898 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
902 if (!GetTopWindow()->Close(!event
.CanVeto()))
907 wxLog
* wxApp::CreateLogTarget()
912 wxWindow
* wxApp::GetTopWindow() const
916 else if (wxTopLevelWindows
.Number() > 0)
917 return (wxWindow
*) wxTopLevelWindows
.First()->Data();
922 int wxApp::GetComCtl32Version() const
924 // have we loaded COMCTL32 yet?
925 HMODULE theModule
= ::GetModuleHandle("COMCTL32");
928 // if so, then we can check for the version
931 // InitCommonControlsEx is unique to 4.7 and later
932 FARPROC theProc
= ::GetProcAddress(theModule
, "InitCommonControlsEx");
935 { // not found, must be 4.00
940 // The following symbol are unique to 4.71
942 // FlatSB_EnableScrollBar FlatSB_GetScrollInfo FlatSB_GetScrollPos
943 // FlatSB_GetScrollProp FlatSB_GetScrollRange FlatSB_SetScrollInfo
944 // FlatSB_SetScrollPos FlatSB_SetScrollProp FlatSB_SetScrollRange
945 // FlatSB_ShowScrollBar
946 // _DrawIndirectImageList _DuplicateImageList
948 // UninitializeFlatSB
949 // we could check for any of these - I chose DllInstall
950 FARPROC theProc
= ::GetProcAddress(theModule
, "DllInstall");
953 // not found, must be 4.70
957 { // found, must be 4.71
968 FatalAppExit(0, "Fatal error: exiting");
971 // Yield to incoming messages
975 // We want to go back to the main message loop
976 // if we see a WM_QUIT. (?)
977 while (PeekMessage(&msg
, NULL
, 0, 0, PM_NOREMOVE
) && msg
.message
!= WM_QUIT
)
979 if (!wxTheApp
->DoMessage())
986 HINSTANCE
wxGetInstance()
991 // For some reason, with MSVC++ 1.5, WinMain isn't linked in properly
992 // if in a separate file. So include it here to ensure it's linked.
993 #if (defined(_MSC_VER) && !defined(__WIN32__)) || defined(__GNUWIN32__)