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 #if defined(__WXDEBUG__) && defined(_MSC_VER)
55 // VC++ uses this macro as debug/release mode indicator
63 extern char *wxBuffer
;
64 extern char *wxOsVersion
;
65 extern wxList
*wxWinHandleList
;
66 extern wxList wxPendingDelete
;
67 extern void wxSetKeyboardHook(bool doIt
);
68 extern wxCursor
*g_globalCursor
;
70 HINSTANCE wxhInstance
= 0;
71 static MSG s_currentMsg
;
72 wxApp
*wxTheApp
= NULL
;
74 // @@ why not const? and not static?
75 char wxFrameClassName
[] = "wxFrameClass";
76 char wxMDIFrameClassName
[] = "wxMDIFrameClass";
77 char wxMDIChildFrameClassName
[] = "wxMDIChildFrameClass";
78 char wxPanelClassName
[] = "wxPanelClass";
79 char wxCanvasClassName
[] = "wxCanvasClass";
81 HICON wxSTD_FRAME_ICON
= NULL
;
82 HICON wxSTD_MDICHILDFRAME_ICON
= NULL
;
83 HICON wxSTD_MDIPARENTFRAME_ICON
= NULL
;
85 HICON wxDEFAULT_FRAME_ICON
= NULL
;
86 HICON wxDEFAULT_MDICHILDFRAME_ICON
= NULL
;
87 HICON wxDEFAULT_MDIPARENTFRAME_ICON
= NULL
;
89 HBRUSH wxDisableButtonBrush
= 0;
91 LRESULT APIENTRY
wxWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
93 #if !USE_SHARED_LIBRARY
94 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
96 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
97 EVT_IDLE(wxApp::OnIdle
)
98 EVT_END_SESSION(wxApp::OnEndSession
)
99 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
)
103 long wxApp::sm_lastMessageTime
= 0;
106 static HINSTANCE gs_hRichEdit
= NULL
;
111 bool wxApp::Initialize()
113 wxBuffer
= new char[1500];
115 #if defined(__WXDEBUG__) && defined(_MSC_VER)
116 // do check for memory leaks on program exit
117 // (another useful flag is _CRTDBG_DELAY_FREE_MEM_DF which doesn't free
118 // deallocated memory which may be used to simulate low-memory condition)
119 _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG
) | _CRTDBG_LEAK_CHECK_DF
);
120 #endif // debug build under MS VC++
122 #if (WXDEBUG && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
124 streambuf
* sBuf
= NULL
;
126 streambuf
* sBuf
= new wxDebugStreamBuf
;
129 ostream
* oStr
= new ostream(sBuf
) ;
130 wxDebugContext::SetStream(oStr
, sBuf
);
131 #endif // wxUSE_MEMORY_TRACING
133 wxClassInfo::InitializeClasses();
136 wxGetResource("wxWindows", "OsVersion", &wxOsVersion
);
139 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
140 wxTheColourDatabase
->Initialize();
142 wxInitializeStockLists();
143 wxInitializeStockObjects();
145 #if wxUSE_WX_RESOURCES
146 wxInitializeResourceSystem();
149 wxBitmap::InitStandardHandlers();
151 #if defined(__WIN95__)
152 InitCommonControls();
153 gs_hRichEdit
= LoadLibrary("RICHED32.DLL");
155 if (gs_hRichEdit
== NULL
)
157 wxMessageBox("Could not initialise Rich Edit DLL");
161 #if defined(WX_DRAG_DROP)
162 // we need to initialize OLE library
163 if ( FAILED(::OleInitialize(NULL
)) )
164 wxFatalError(_("Cannot initialize OLE"));
168 if (!Ctl3dRegister(wxhInstance
))
169 wxFatalError("Cannot register CTL3D");
171 Ctl3dAutoSubclass(wxhInstance
);
174 g_globalCursor
= new wxCursor
;
176 wxSTD_FRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_FRAME");
177 wxSTD_MDIPARENTFRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_MDIPARENTFRAME");
178 wxSTD_MDICHILDFRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_MDICHILDFRAME");
180 wxDEFAULT_FRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_FRAME");
181 wxDEFAULT_MDIPARENTFRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_MDIPARENTFRAME");
182 wxDEFAULT_MDICHILDFRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_MDICHILDFRAME");
184 RegisterWindowClasses();
186 // Create the brush for disabling bitmap buttons
189 lb
.lbStyle
= BS_PATTERN
;
190 lb
.lbHatch
= (int)LoadBitmap( wxhInstance
, "wxDISABLE_BUTTON_BITMAP" ) ;
191 wxDisableButtonBrush
= ::CreateBrushIndirect( & lb
) ;
192 ::DeleteObject( (HGDIOBJ
)lb
.lbHatch
) ;
198 wxWinHandleList
= new wxList(wxKEY_INTEGER
);
200 // This is to foil optimizations in Visual C++ that
201 // throw out dummy.obj.
202 #if (_MSC_VER >= 800) && !defined(WXMAKINGDLL)
203 extern char wxDummyChar
;
204 if (wxDummyChar
) wxDummyChar
++;
207 wxSetKeyboardHook(TRUE
);
209 wxModule::RegisterModules();
210 if (!wxModule::InitializeModules())
215 //// RegisterWindowClasses
217 bool wxApp::RegisterWindowClasses()
219 ///////////////////////////////////////////////////////////////////////
220 // Register the frame window class.
221 WNDCLASS wndclass
; // Structure used to register Windows class.
223 wndclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
224 wndclass
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
225 wndclass
.cbClsExtra
= 0;
226 wndclass
.cbWndExtra
= sizeof( DWORD
); // was 4
227 wndclass
.hInstance
= wxhInstance
;
228 wndclass
.hIcon
= NULL
; // wxSTD_FRAME_ICON;
229 wndclass
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
230 wndclass
.hbrBackground
= (HBRUSH
)(COLOR_APPWORKSPACE
+1) ;
231 // wndclass.hbrBackground = GetStockObject( WHITE_BRUSH );
232 wndclass
.lpszMenuName
= NULL
;
233 #ifdef _MULTIPLE_INSTANCES
234 sprintf( wxFrameClassName
,"wxFrameClass%d", wxhInstance
);
236 wndclass
.lpszClassName
= wxFrameClassName
;
238 if (!RegisterClass( &wndclass
))
240 // wxFatalError("Can't register Frame Window class");
243 ///////////////////////////////////////////////////////////////////////
244 // Register the MDI frame window class.
245 WNDCLASS wndclass1
; // Structure used to register Windows class.
247 wndclass1
.style
= CS_HREDRAW
| CS_VREDRAW
;
248 wndclass1
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
249 wndclass1
.cbClsExtra
= 0;
250 wndclass1
.cbWndExtra
= sizeof( DWORD
); // was 4
251 wndclass1
.hInstance
= wxhInstance
;
252 wndclass1
.hIcon
= NULL
; // wxSTD_MDIPARENTFRAME_ICON;
253 wndclass1
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
254 // wndclass1.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1) ;
255 wndclass1
.hbrBackground
= NULL
;
256 wndclass1
.lpszMenuName
= NULL
;
258 wndclass1
.lpszClassName
= wxMDIFrameClassName
;
259 if (!RegisterClass( &wndclass1
))
261 // wxFatalError("Can't register MDI Frame window class");
265 ///////////////////////////////////////////////////////////////////////
266 // Register the MDI child frame window class.
267 WNDCLASS wndclass4
; // Structure used to register Windows class.
269 wndclass4
.style
= CS_HREDRAW
| CS_VREDRAW
;
270 wndclass4
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
271 wndclass4
.cbClsExtra
= 0;
272 wndclass4
.cbWndExtra
= sizeof( DWORD
); // was 4
273 wndclass4
.hInstance
= wxhInstance
;
274 wndclass4
.hIcon
= NULL
; // wxSTD_MDICHILDFRAME_ICON;
275 wndclass4
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
276 // TODO: perhaps this should be NULL so that Windows doesn't
277 // paint the background itself (would OnEraseBackground duplicate
279 wndclass4
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1) ;
280 // wndclass4.hbrBackground = NULL;
281 wndclass4
.lpszMenuName
= NULL
;
282 wndclass4
.lpszClassName
= wxMDIChildFrameClassName
;
284 if (!RegisterClass( &wndclass4
))
286 // wxFatalError("Can't register MDI child frame window class");
290 ///////////////////////////////////////////////////////////////////////
291 // Register the panel window class.
292 WNDCLASS wndclass2
; // Structure used to register Windows class.
293 memset(&wndclass2
, 0, sizeof(WNDCLASS
)); // start with NULL defaults
294 // Use CS_OWNDC to avoid messing about restoring the context
295 // for every graphic operation.
296 wndclass2
.style
= CS_HREDRAW
| CS_VREDRAW
;
297 wndclass2
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
298 wndclass2
.cbClsExtra
= 0;
299 wndclass2
.cbWndExtra
= sizeof( DWORD
); // was 4
300 wndclass2
.hInstance
= wxhInstance
;
301 wndclass2
.hIcon
= NULL
;
302 wndclass2
.hCursor
= NULL
;
303 // wndclass2.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1) ;
304 wndclass2
.hbrBackground
= (HBRUSH
) GetStockObject( LTGRAY_BRUSH
);
305 wndclass2
.lpszMenuName
= NULL
;
306 wndclass2
.lpszClassName
= wxPanelClassName
;
307 if (!RegisterClass( &wndclass2
))
309 // wxFatalError("Can't register Panel Window class");
313 ///////////////////////////////////////////////////////////////////////
314 // Register the canvas and textsubwindow class name
315 WNDCLASS wndclass3
; // Structure used to register Windows class.
316 memset(&wndclass3
, 0, sizeof(WNDCLASS
)); // start with NULL defaults
317 // Use CS_OWNDC to avoid messing about restoring the context
318 // for every graphic operation.
319 // wndclass3.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS ;
321 wndclass3
.style
= CS_HREDRAW
| CS_VREDRAW
| CS_DBLCLKS
;
322 wndclass3
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
323 wndclass3
.cbClsExtra
= 0;
324 wndclass3
.cbWndExtra
= sizeof( DWORD
); // was 4
325 wndclass3
.hInstance
= wxhInstance
;
326 wndclass3
.hIcon
= NULL
;
327 wndclass3
.hCursor
= NULL
;
328 // wndclass3.hbrBackground = (HBRUSH)(COLOR_WINDOW+1) ;
329 wndclass3
.hbrBackground
= NULL
;
330 wndclass3
.lpszMenuName
= NULL
;
331 wndclass3
.lpszClassName
= wxCanvasClassName
;
332 if (!RegisterClass( &wndclass3
))
334 // wxFatalError("Can't register Canvas class");
341 //// Convert Windows to argc, argv style
343 void wxApp::ConvertToStandardCommandArgs(char* lpCmdLine
)
347 wxString
cmdLine(lpCmdLine
);
350 // Get application name
351 char name
[260]; // 260 is MAX_PATH value from windef.h
352 ::GetModuleFileName(wxhInstance
, name
, WXSIZEOF(name
));
354 // GNUWIN32 already fills in the first arg with the application name.
355 #if !defined(__GNUWIN32__)
360 strcpy(name
, wxFileNameFromPath(name
));
361 wxStripExtension(name
);
362 wxTheApp
->SetAppName(name
);
365 // Treat strings enclosed in double-quotes as single arguments
367 int len
= cmdLine
.Length();
371 while ((i
< len
) && isspace(cmdLine
.GetChar(i
)))
376 if (cmdLine
.GetChar(i
) == '"') // We found the start of a string
380 while ((i
< len
) && (cmdLine
.GetChar(i
) != '"'))
383 wxString
arg(cmdLine
.Mid(first
, (i
- first
)));
389 i
++; // Skip past 2nd quote
391 else // Unquoted argument
394 while ((i
< len
) && !isspace(cmdLine
.GetChar(i
)))
397 wxString
arg(cmdLine
.Mid(first
, (i
- first
)));
405 wxTheApp
->argv
= new char*[count
+ 1];
406 for (i
= 0; i
< count
; i
++)
408 wxString
arg(args
[i
]);
409 wxTheApp
->argv
[i
] = copystring((const char*)arg
);
411 wxTheApp
->argv
[count
] = NULL
; // argv[] is a NULL-terminated list
412 wxTheApp
->argc
= count
;
415 //// Cleans up any wxWindows internal structures left lying around
417 void wxApp::CleanUp()
420 wxModule::CleanUpModules();
422 #if wxUSE_WX_RESOURCES
423 wxCleanUpResourceSystem();
425 // wxDefaultResourceTable->ClearTable();
428 // Indicate that the cursor can be freed,
429 // so that cursor won't be deleted by deleting
430 // the bitmap list before g_globalCursor goes out
431 // of scope (double deletion of the cursor).
432 wxSetCursor(wxNullCursor
);
433 delete g_globalCursor
;
435 wxDeleteStockObjects() ;
437 // Destroy all GDI lists, etc.
438 wxDeleteStockLists();
440 delete wxTheColourDatabase
;
441 wxTheColourDatabase
= NULL
;
443 wxBitmap::CleanUpHandlers();
448 //// WINDOWS-SPECIFIC CLEANUP
450 wxSetKeyboardHook(FALSE
);
453 if (gs_hRichEdit
!= NULL
)
454 FreeLibrary(gs_hRichEdit
);
461 if (wxSTD_FRAME_ICON
)
462 DestroyIcon(wxSTD_FRAME_ICON
);
463 if (wxSTD_MDICHILDFRAME_ICON
)
464 DestroyIcon(wxSTD_MDICHILDFRAME_ICON
);
465 if (wxSTD_MDIPARENTFRAME_ICON
)
466 DestroyIcon(wxSTD_MDIPARENTFRAME_ICON
);
468 if (wxDEFAULT_FRAME_ICON
)
469 DestroyIcon(wxDEFAULT_FRAME_ICON
);
470 if (wxDEFAULT_MDICHILDFRAME_ICON
)
471 DestroyIcon(wxDEFAULT_MDICHILDFRAME_ICON
);
472 if (wxDEFAULT_MDIPARENTFRAME_ICON
)
473 DestroyIcon(wxDEFAULT_MDIPARENTFRAME_ICON
);
475 if ( wxDisableButtonBrush
)
476 ::DeleteObject( wxDisableButtonBrush
) ;
478 #if defined(WX_DRAG_DROP)
483 Ctl3dUnregister(wxhInstance
);
487 delete wxWinHandleList
;
489 wxClassInfo::CleanUpClasses();
491 // do it as the very last thing because everything else can log messages
492 wxLog::DontCreateOnDemand();
493 delete wxLog::SetActiveTarget(NULL
);
496 #if !defined(_WINDLL) || (defined(_WINDLL) && defined(WXMAKINGDLL))
498 //// Main wxWindows entry point
499 int wxEntry(WXHINSTANCE hInstance
,
500 WXHINSTANCE
WXUNUSED(hPrevInstance
),
505 #ifndef __WXDEBUG__ // take everything into a try-except block in release build
509 wxhInstance
= (HINSTANCE
) hInstance
;
511 if (!wxApp::Initialize())
514 // create the application object or ensure that one already exists
517 // The app may have declared a global application object, but we recommend
518 // the IMPLEMENT_APP macro is used instead, which sets an initializer
519 // function for delayed, dynamic app object construction.
520 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
521 "No initializer - use IMPLEMENT_APP macro." );
523 wxTheApp
= (*wxApp::GetInitializerFunction()) ();
526 wxCHECK_MSG( wxTheApp
, 0, "You have to define an instance of wxApp!" );
528 // save the WinMain() parameters
529 wxTheApp
->ConvertToStandardCommandArgs(lpCmdLine
);
530 wxTheApp
->m_nCmdShow
= nCmdShow
;
532 // GUI-specific initialisation. In fact on Windows we don't have any,
533 // but this call is provided for compatibility across platforms.
534 wxTheApp
->OnInitGui() ;
538 if ( wxTheApp
->OnInit() )
542 retValue
= wxTheApp
->OnRun();
545 //else: app initialization failed, so we skipped OnRun()
547 wxWindow
*topWindow
= wxTheApp
->GetTopWindow();
550 // Forcibly delete the window.
551 if ( topWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
552 topWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
554 topWindow
->Close(TRUE
);
555 wxTheApp
->DeletePendingObjects();
560 wxTheApp
->SetTopWindow(NULL
);
570 #if (WXDEBUG && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
571 // At this point we want to check if there are any memory
572 // blocks that aren't part of the wxDebugContext itself,
573 // as a special case. Then when dumping we need to ignore
574 // wxDebugContext, too.
575 if (wxDebugContext::CountObjectsLeft() > 0)
577 wxTrace("There were memory leaks.\n");
578 wxDebugContext::Dump();
579 wxDebugContext::PrintStatistics();
581 wxDebugContext::SetStream(NULL
, NULL
);
585 #ifndef __WXDEBUG__ // catch exceptions only in release build
587 except ( EXCEPTION_EXECUTE_HANDLER
) {
590 wxTheApp->OnFatalException();
593 ::ExitProcess(3); // the same exit code as abort()
600 //// Entry point for DLLs
602 int wxEntry(WXHINSTANCE hInstance
)
604 wxhInstance
= (HINSTANCE
) hInstance
;
607 // The app may have declared a global application object, but we recommend
608 // the IMPLEMENT_APP macro is used instead, which sets an initializer function
609 // for delayed, dynamic app object construction.
613 if (!wxApp::GetInitializerFunction())
615 MessageBox(NULL
, "No initializer - use IMPLEMENT_APP macro.", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
619 wxTheApp
= (* wxApp::GetInitializerFunction()) ();
623 MessageBox(NULL
, "You have to define an instance of wxApp!", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
628 wxTheApp
->argv
= NULL
;
630 wxTheApp
->OnInitGui();
634 if (wxTheApp
->GetTopWindow() && wxTheApp
->GetTopWindow()->GetHWND()) {
635 wxTheApp
->GetTopWindow()->Show(TRUE
);
642 //// Static member initialization
644 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
651 m_wantDebugOutput
= TRUE
;
656 m_printMode
= wxPRINT_WINDOWS
;
658 m_printMode
= wxPRINT_POSTSCRIPT
;
660 m_exitOnFrameDelete
= TRUE
;
666 // Delete command-line args
668 for (i
= 0; i
< argc
; i
++)
675 bool wxApp::Initialized()
683 #ifdef _WINDLL // Assume initialized if DLL (no way of telling)
689 * Get and process a message, returning FALSE if WM_QUIT
693 bool wxApp::DoMessage()
695 if (!::GetMessage(&s_currentMsg
, (HWND
) NULL
, 0, 0))
700 // Process the message
701 if (!ProcessMessage((WXMSG
*)&s_currentMsg
))
703 ::TranslateMessage(&s_currentMsg
);
704 wxApp::sm_lastMessageTime
= s_currentMsg
.time
; /* MATTHEW: timeStamp impl. */
705 ::DispatchMessage(&s_currentMsg
);
711 * Keep trying to process messages until WM_QUIT
714 * If there are messages to be processed, they will all be
715 * processed and OnIdle will not be called.
716 * When there are no more messages, OnIdle is called.
717 * If OnIdle requests more time,
718 * it will be repeatedly called so long as there are no pending messages.
719 * A 'feature' of this is that once OnIdle has decided that no more processing
720 * is required, then it won't get processing time until further messages
721 * are processed (it'll sit in DoMessage).
724 int wxApp::MainLoop()
729 while (!::PeekMessage(&s_currentMsg
, 0, 0, 0, PM_NOREMOVE
) &&
735 return s_currentMsg
.wParam
;
738 // Returns TRUE if more time is needed.
739 bool wxApp::ProcessIdle()
742 event
.SetEventObject(this);
745 return event
.MoreRequested();
748 void wxApp::ExitMainLoop()
753 bool wxApp::Pending()
755 return (::PeekMessage(&s_currentMsg
, 0, 0, 0, PM_NOREMOVE
) != 0) ;
758 void wxApp::Dispatch()
765 * Give all windows a chance to preprocess
766 * the message. Some may have accelerator tables, or have
769 bool wxApp::ProcessMessage(WXMSG
*Msg
)
771 MSG
*msg
= (MSG
*)Msg
;
775 // Try translations first; find the youngest window with
776 // a translation table.
777 for (hWnd
= msg
->hwnd
; hWnd
!= NULL
; hWnd
= ::GetParent(hWnd
))
779 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
782 if (wnd
->MSWTranslateMessage(Msg
))
787 // Anyone for a non-translation message? Try youngest descendants first.
788 for (hWnd
= msg
->hwnd
; hWnd
!= NULL
; hWnd
= ::GetParent(hWnd
))
790 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
793 if (wnd
->MSWProcessMessage(Msg
))
800 void wxApp::OnIdle(wxIdleEvent
& event
)
802 static bool inOnIdle
= FALSE
;
804 // Avoid recursion (via ProcessEvent default case)
810 // 'Garbage' collection of windows deleted with Close().
811 DeletePendingObjects();
813 // flush the logged messages if any
814 wxLog
*pLog
= wxLog::GetActiveTarget();
815 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
818 // Send OnIdle events to all windows
819 bool needMore
= SendIdleEvents();
820 // bool needMore = FALSE;
823 event
.RequestMore(TRUE
);
828 // Send idle event to all top-level windows
829 bool wxApp::SendIdleEvents()
831 bool needMore
= FALSE
;
832 wxNode
* node
= wxTopLevelWindows
.First();
835 wxWindow
* win
= (wxWindow
*) node
->Data();
836 if (SendIdleEvents(win
))
844 // Send idle event to window and all subwindows
845 bool wxApp::SendIdleEvents(wxWindow
* win
)
847 bool needMore
= FALSE
;
850 event
.SetEventObject(win
);
851 win
->ProcessEvent(event
);
853 if (event
.MoreRequested())
856 wxNode
* node
= win
->GetChildren()->First();
859 wxWindow
* win
= (wxWindow
*) node
->Data();
860 if (SendIdleEvents(win
))
868 void wxApp::DeletePendingObjects()
870 wxNode
*node
= wxPendingDelete
.First();
873 wxObject
*obj
= (wxObject
*)node
->Data();
877 if (wxPendingDelete
.Member(obj
))
880 // Deleting one object may have deleted other pending
881 // objects, so start from beginning of list again.
882 node
= wxPendingDelete
.First();
886 void wxApp::OnEndSession(wxCloseEvent
& event
)
889 GetTopWindow()->Close(TRUE
);
892 // Default behaviour: close the application with prompts. The
893 // user can veto the close, and therefore the end session.
894 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
898 if (!GetTopWindow()->Close(!event
.CanVeto()))
903 wxLog
* wxApp::CreateLogTarget()
908 wxWindow
* wxApp::GetTopWindow() const
912 else if (wxTopLevelWindows
.Number() > 0)
913 return (wxWindow
*) wxTopLevelWindows
.First()->Data();
918 int wxApp::GetComCtl32Version() const
920 // have we loaded COMCTL32 yet?
921 HMODULE theModule
= ::GetModuleHandle("COMCTL32");
924 // if so, then we can check for the version
927 // InitCommonControlsEx is unique to 4.7 and later
928 FARPROC theProc
= ::GetProcAddress(theModule
, "InitCommonControlsEx");
931 { // not found, must be 4.00
936 // The following symbol are unique to 4.71
938 // FlatSB_EnableScrollBar FlatSB_GetScrollInfo FlatSB_GetScrollPos
939 // FlatSB_GetScrollProp FlatSB_GetScrollRange FlatSB_SetScrollInfo
940 // FlatSB_SetScrollPos FlatSB_SetScrollProp FlatSB_SetScrollRange
941 // FlatSB_ShowScrollBar
942 // _DrawIndirectImageList _DuplicateImageList
944 // UninitializeFlatSB
945 // we could check for any of these - I chose DllInstall
946 FARPROC theProc
= ::GetProcAddress(theModule
, "DllInstall");
949 // not found, must be 4.70
953 { // found, must be 4.71
964 FatalAppExit(0, "Fatal error: exiting");
967 // Yield to incoming messages
971 // We want to go back to the main message loop
972 // if we see a WM_QUIT. (?)
973 while (PeekMessage(&msg
, NULL
, 0, 0, PM_NOREMOVE
) && msg
.message
!= WM_QUIT
)
975 if (!wxTheApp
->DoMessage())
982 HINSTANCE
wxGetInstance()
987 // For some reason, with MSVC++ 1.5, WinMain isn't linked in properly
988 // if in a separate file. So include it here to ensure it's linked.
989 #if (defined(_MSC_VER) && !defined(__WIN32__)) || defined(__GNUWIN32__)