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++
128 #if (WXDEBUG && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
130 streambuf
* sBuf
= NULL
;
132 streambuf
* sBuf
= new wxDebugStreamBuf
;
135 ostream
* oStr
= new ostream(sBuf
) ;
136 wxDebugContext::SetStream(oStr
, sBuf
);
137 #endif // wxUSE_MEMORY_TRACING
139 wxClassInfo::InitializeClasses();
142 wxGetResource("wxWindows", "OsVersion", &wxOsVersion
);
145 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
146 wxTheColourDatabase
->Initialize();
148 wxInitializeStockLists();
149 wxInitializeStockObjects();
151 #if wxUSE_WX_RESOURCES
152 wxInitializeResourceSystem();
155 wxBitmap::InitStandardHandlers();
157 #if defined(__WIN95__)
158 InitCommonControls();
159 gs_hRichEdit
= LoadLibrary("RICHED32.DLL");
161 if (gs_hRichEdit
== NULL
)
163 wxMessageBox("Could not initialise Rich Edit DLL");
167 #if defined(WX_DRAG_DROP)
168 // we need to initialize OLE library
169 if ( FAILED(::OleInitialize(NULL
)) )
170 wxFatalError(_("Cannot initialize OLE"));
174 if (!Ctl3dRegister(wxhInstance
))
175 wxFatalError("Cannot register CTL3D");
177 Ctl3dAutoSubclass(wxhInstance
);
180 g_globalCursor
= new wxCursor
;
182 wxSTD_FRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_FRAME");
183 wxSTD_MDIPARENTFRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_MDIPARENTFRAME");
184 wxSTD_MDICHILDFRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_MDICHILDFRAME");
186 wxDEFAULT_FRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_FRAME");
187 wxDEFAULT_MDIPARENTFRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_MDIPARENTFRAME");
188 wxDEFAULT_MDICHILDFRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_MDICHILDFRAME");
190 RegisterWindowClasses();
192 // Create the brush for disabling bitmap buttons
195 lb
.lbStyle
= BS_PATTERN
;
196 lb
.lbHatch
= (int)LoadBitmap( wxhInstance
, "wxDISABLE_BUTTON_BITMAP" ) ;
197 wxDisableButtonBrush
= ::CreateBrushIndirect( & lb
) ;
198 ::DeleteObject( (HGDIOBJ
)lb
.lbHatch
) ;
204 wxWinHandleList
= new wxList(wxKEY_INTEGER
);
206 // This is to foil optimizations in Visual C++ that
207 // throw out dummy.obj.
208 #if (_MSC_VER >= 800) && !defined(WXMAKINGDLL)
209 extern char wxDummyChar
;
210 if (wxDummyChar
) wxDummyChar
++;
213 wxSetKeyboardHook(TRUE
);
215 wxModule::RegisterModules();
216 if (!wxModule::InitializeModules())
221 //// RegisterWindowClasses
223 bool wxApp::RegisterWindowClasses()
225 ///////////////////////////////////////////////////////////////////////
226 // Register the frame window class.
227 WNDCLASS wndclass
; // Structure used to register Windows class.
229 wndclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
230 wndclass
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
231 wndclass
.cbClsExtra
= 0;
232 wndclass
.cbWndExtra
= sizeof( DWORD
); // was 4
233 wndclass
.hInstance
= wxhInstance
;
234 wndclass
.hIcon
= NULL
; // wxSTD_FRAME_ICON;
235 wndclass
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
236 wndclass
.hbrBackground
= (HBRUSH
)(COLOR_APPWORKSPACE
+1) ;
237 // wndclass.hbrBackground = GetStockObject( WHITE_BRUSH );
238 wndclass
.lpszMenuName
= NULL
;
239 #ifdef _MULTIPLE_INSTANCES
240 sprintf( wxFrameClassName
,"wxFrameClass%d", wxhInstance
);
242 wndclass
.lpszClassName
= wxFrameClassName
;
244 if (!RegisterClass( &wndclass
))
246 // wxFatalError("Can't register Frame Window class");
249 ///////////////////////////////////////////////////////////////////////
250 // Register the MDI frame window class.
251 WNDCLASS wndclass1
; // Structure used to register Windows class.
253 wndclass1
.style
= CS_HREDRAW
| CS_VREDRAW
;
254 wndclass1
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
255 wndclass1
.cbClsExtra
= 0;
256 wndclass1
.cbWndExtra
= sizeof( DWORD
); // was 4
257 wndclass1
.hInstance
= wxhInstance
;
258 wndclass1
.hIcon
= NULL
; // wxSTD_MDIPARENTFRAME_ICON;
259 wndclass1
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
260 // wndclass1.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1) ;
261 wndclass1
.hbrBackground
= NULL
;
262 wndclass1
.lpszMenuName
= NULL
;
264 wndclass1
.lpszClassName
= wxMDIFrameClassName
;
265 if (!RegisterClass( &wndclass1
))
267 // wxFatalError("Can't register MDI Frame window class");
271 ///////////////////////////////////////////////////////////////////////
272 // Register the MDI child frame window class.
273 WNDCLASS wndclass4
; // Structure used to register Windows class.
275 wndclass4
.style
= CS_HREDRAW
| CS_VREDRAW
;
276 wndclass4
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
277 wndclass4
.cbClsExtra
= 0;
278 wndclass4
.cbWndExtra
= sizeof( DWORD
); // was 4
279 wndclass4
.hInstance
= wxhInstance
;
280 wndclass4
.hIcon
= NULL
; // wxSTD_MDICHILDFRAME_ICON;
281 wndclass4
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
282 // TODO: perhaps this should be NULL so that Windows doesn't
283 // paint the background itself (would OnEraseBackground duplicate
285 wndclass4
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1) ;
286 // wndclass4.hbrBackground = NULL;
287 wndclass4
.lpszMenuName
= NULL
;
288 wndclass4
.lpszClassName
= wxMDIChildFrameClassName
;
290 if (!RegisterClass( &wndclass4
))
292 // wxFatalError("Can't register MDI child frame window class");
296 ///////////////////////////////////////////////////////////////////////
297 // Register the panel window class.
298 WNDCLASS wndclass2
; // Structure used to register Windows class.
299 memset(&wndclass2
, 0, sizeof(WNDCLASS
)); // start with NULL defaults
300 // Use CS_OWNDC to avoid messing about restoring the context
301 // for every graphic operation.
302 wndclass2
.style
= CS_HREDRAW
| CS_VREDRAW
;
303 wndclass2
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
304 wndclass2
.cbClsExtra
= 0;
305 wndclass2
.cbWndExtra
= sizeof( DWORD
); // was 4
306 wndclass2
.hInstance
= wxhInstance
;
307 wndclass2
.hIcon
= NULL
;
308 wndclass2
.hCursor
= NULL
;
309 // wndclass2.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1) ;
310 wndclass2
.hbrBackground
= (HBRUSH
) GetStockObject( LTGRAY_BRUSH
);
311 wndclass2
.lpszMenuName
= NULL
;
312 wndclass2
.lpszClassName
= wxPanelClassName
;
313 if (!RegisterClass( &wndclass2
))
315 // wxFatalError("Can't register Panel Window class");
319 ///////////////////////////////////////////////////////////////////////
320 // Register the canvas and textsubwindow class name
321 WNDCLASS wndclass3
; // Structure used to register Windows class.
322 memset(&wndclass3
, 0, sizeof(WNDCLASS
)); // start with NULL defaults
323 // Use CS_OWNDC to avoid messing about restoring the context
324 // for every graphic operation.
325 // wndclass3.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS ;
327 wndclass3
.style
= CS_HREDRAW
| CS_VREDRAW
| CS_DBLCLKS
;
328 wndclass3
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
329 wndclass3
.cbClsExtra
= 0;
330 wndclass3
.cbWndExtra
= sizeof( DWORD
); // was 4
331 wndclass3
.hInstance
= wxhInstance
;
332 wndclass3
.hIcon
= NULL
;
333 wndclass3
.hCursor
= NULL
;
334 // wndclass3.hbrBackground = (HBRUSH)(COLOR_WINDOW+1) ;
335 wndclass3
.hbrBackground
= NULL
;
336 wndclass3
.lpszMenuName
= NULL
;
337 wndclass3
.lpszClassName
= wxCanvasClassName
;
338 if (!RegisterClass( &wndclass3
))
340 // wxFatalError("Can't register Canvas class");
347 //// Convert Windows to argc, argv style
349 void wxApp::ConvertToStandardCommandArgs(char* lpCmdLine
)
353 wxString
cmdLine(lpCmdLine
);
356 // Get application name
357 char name
[260]; // 260 is MAX_PATH value from windef.h
358 ::GetModuleFileName(wxhInstance
, name
, WXSIZEOF(name
));
360 // GNUWIN32 already fills in the first arg with the application name.
361 #if !defined(__GNUWIN32__)
366 strcpy(name
, wxFileNameFromPath(name
));
367 wxStripExtension(name
);
368 wxTheApp
->SetAppName(name
);
371 // Treat strings enclosed in double-quotes as single arguments
373 int len
= cmdLine
.Length();
377 while ((i
< len
) && isspace(cmdLine
.GetChar(i
)))
382 if (cmdLine
.GetChar(i
) == '"') // We found the start of a string
386 while ((i
< len
) && (cmdLine
.GetChar(i
) != '"'))
389 wxString
arg(cmdLine
.Mid(first
, (i
- first
)));
395 i
++; // Skip past 2nd quote
397 else // Unquoted argument
400 while ((i
< len
) && !isspace(cmdLine
.GetChar(i
)))
403 wxString
arg(cmdLine
.Mid(first
, (i
- first
)));
411 wxTheApp
->argv
= new char*[count
+ 1];
412 for (i
= 0; i
< count
; i
++)
414 wxString
arg(args
[i
]);
415 wxTheApp
->argv
[i
] = copystring((const char*)arg
);
417 wxTheApp
->argv
[count
] = NULL
; // argv[] is a NULL-terminated list
418 wxTheApp
->argc
= count
;
421 //// Cleans up any wxWindows internal structures left lying around
423 void wxApp::CleanUp()
426 wxModule::CleanUpModules();
428 #if wxUSE_WX_RESOURCES
429 wxCleanUpResourceSystem();
431 // wxDefaultResourceTable->ClearTable();
434 // Indicate that the cursor can be freed,
435 // so that cursor won't be deleted by deleting
436 // the bitmap list before g_globalCursor goes out
437 // of scope (double deletion of the cursor).
438 wxSetCursor(wxNullCursor
);
439 delete g_globalCursor
;
441 wxDeleteStockObjects() ;
443 // Destroy all GDI lists, etc.
444 wxDeleteStockLists();
446 delete wxTheColourDatabase
;
447 wxTheColourDatabase
= NULL
;
449 wxBitmap::CleanUpHandlers();
454 //// WINDOWS-SPECIFIC CLEANUP
456 wxSetKeyboardHook(FALSE
);
459 if (gs_hRichEdit
!= NULL
)
460 FreeLibrary(gs_hRichEdit
);
467 if (wxSTD_FRAME_ICON
)
468 DestroyIcon(wxSTD_FRAME_ICON
);
469 if (wxSTD_MDICHILDFRAME_ICON
)
470 DestroyIcon(wxSTD_MDICHILDFRAME_ICON
);
471 if (wxSTD_MDIPARENTFRAME_ICON
)
472 DestroyIcon(wxSTD_MDIPARENTFRAME_ICON
);
474 if (wxDEFAULT_FRAME_ICON
)
475 DestroyIcon(wxDEFAULT_FRAME_ICON
);
476 if (wxDEFAULT_MDICHILDFRAME_ICON
)
477 DestroyIcon(wxDEFAULT_MDICHILDFRAME_ICON
);
478 if (wxDEFAULT_MDIPARENTFRAME_ICON
)
479 DestroyIcon(wxDEFAULT_MDIPARENTFRAME_ICON
);
481 if ( wxDisableButtonBrush
)
482 ::DeleteObject( wxDisableButtonBrush
) ;
484 #if defined(WX_DRAG_DROP)
489 Ctl3dUnregister(wxhInstance
);
493 delete wxWinHandleList
;
495 wxClassInfo::CleanUpClasses();
497 // do it as the very last thing because everything else can log messages
498 wxLog::DontCreateOnDemand();
499 delete wxLog::SetActiveTarget(NULL
);
502 #if !defined(_WINDLL) || (defined(_WINDLL) && defined(WXMAKINGDLL))
504 //// Main wxWindows entry point
505 int wxEntry(WXHINSTANCE hInstance
,
506 WXHINSTANCE
WXUNUSED(hPrevInstance
),
511 #ifndef __WXDEBUG__ // take everything into a try-except block in release build
515 wxhInstance
= (HINSTANCE
) hInstance
;
517 if (!wxApp::Initialize())
520 // create the application object or ensure that one already exists
523 // The app may have declared a global application object, but we recommend
524 // the IMPLEMENT_APP macro is used instead, which sets an initializer
525 // function for delayed, dynamic app object construction.
526 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
527 "No initializer - use IMPLEMENT_APP macro." );
529 wxTheApp
= (*wxApp::GetInitializerFunction()) ();
532 wxCHECK_MSG( wxTheApp
, 0, "You have to define an instance of wxApp!" );
534 // save the WinMain() parameters
535 wxTheApp
->ConvertToStandardCommandArgs(lpCmdLine
);
536 wxTheApp
->m_nCmdShow
= nCmdShow
;
538 // GUI-specific initialisation. In fact on Windows we don't have any,
539 // but this call is provided for compatibility across platforms.
540 wxTheApp
->OnInitGui() ;
544 if ( wxTheApp
->OnInit() )
548 retValue
= wxTheApp
->OnRun();
551 //else: app initialization failed, so we skipped OnRun()
553 wxWindow
*topWindow
= wxTheApp
->GetTopWindow();
556 // Forcibly delete the window.
557 if ( topWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
558 topWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
560 topWindow
->Close(TRUE
);
561 wxTheApp
->DeletePendingObjects();
566 wxTheApp
->SetTopWindow(NULL
);
576 #if (WXDEBUG && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
577 // At this point we want to check if there are any memory
578 // blocks that aren't part of the wxDebugContext itself,
579 // as a special case. Then when dumping we need to ignore
580 // wxDebugContext, too.
581 if (wxDebugContext::CountObjectsLeft() > 0)
583 wxTrace("There were memory leaks.\n");
584 wxDebugContext::Dump();
585 wxDebugContext::PrintStatistics();
587 wxDebugContext::SetStream(NULL
, NULL
);
591 #ifndef __WXDEBUG__ // catch exceptions only in release build
593 except ( EXCEPTION_EXECUTE_HANDLER
) {
596 wxTheApp->OnFatalException();
599 ::ExitProcess(3); // the same exit code as abort()
606 //// Entry point for DLLs
608 int wxEntry(WXHINSTANCE hInstance
)
610 wxhInstance
= (HINSTANCE
) hInstance
;
613 // The app may have declared a global application object, but we recommend
614 // the IMPLEMENT_APP macro is used instead, which sets an initializer function
615 // for delayed, dynamic app object construction.
619 if (!wxApp::GetInitializerFunction())
621 MessageBox(NULL
, "No initializer - use IMPLEMENT_APP macro.", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
625 wxTheApp
= (* wxApp::GetInitializerFunction()) ();
629 MessageBox(NULL
, "You have to define an instance of wxApp!", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
634 wxTheApp
->argv
= NULL
;
636 wxTheApp
->OnInitGui();
640 if (wxTheApp
->GetTopWindow() && wxTheApp
->GetTopWindow()->GetHWND()) {
641 wxTheApp
->GetTopWindow()->Show(TRUE
);
648 //// Static member initialization
650 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
657 m_wantDebugOutput
= TRUE
;
662 m_printMode
= wxPRINT_WINDOWS
;
664 m_printMode
= wxPRINT_POSTSCRIPT
;
666 m_exitOnFrameDelete
= TRUE
;
672 // Delete command-line args
674 for (i
= 0; i
< argc
; i
++)
681 bool wxApp::Initialized()
689 #ifdef _WINDLL // Assume initialized if DLL (no way of telling)
695 * Get and process a message, returning FALSE if WM_QUIT
699 bool wxApp::DoMessage()
701 if (!::GetMessage(&s_currentMsg
, (HWND
) NULL
, 0, 0))
706 // Process the message
707 if (!ProcessMessage((WXMSG
*)&s_currentMsg
))
709 ::TranslateMessage(&s_currentMsg
);
710 wxApp::sm_lastMessageTime
= s_currentMsg
.time
; /* MATTHEW: timeStamp impl. */
711 ::DispatchMessage(&s_currentMsg
);
717 * Keep trying to process messages until WM_QUIT
720 * If there are messages to be processed, they will all be
721 * processed and OnIdle will not be called.
722 * When there are no more messages, OnIdle is called.
723 * If OnIdle requests more time,
724 * it will be repeatedly called so long as there are no pending messages.
725 * A 'feature' of this is that once OnIdle has decided that no more processing
726 * is required, then it won't get processing time until further messages
727 * are processed (it'll sit in DoMessage).
730 int wxApp::MainLoop()
735 while (!::PeekMessage(&s_currentMsg
, 0, 0, 0, PM_NOREMOVE
) &&
741 return s_currentMsg
.wParam
;
744 // Returns TRUE if more time is needed.
745 bool wxApp::ProcessIdle()
748 event
.SetEventObject(this);
751 return event
.MoreRequested();
754 void wxApp::ExitMainLoop()
759 bool wxApp::Pending()
761 return (::PeekMessage(&s_currentMsg
, 0, 0, 0, PM_NOREMOVE
) != 0) ;
764 void wxApp::Dispatch()
771 * Give all windows a chance to preprocess
772 * the message. Some may have accelerator tables, or have
775 bool wxApp::ProcessMessage(WXMSG
*Msg
)
777 MSG
*msg
= (MSG
*)Msg
;
781 // Try translations first; find the youngest window with
782 // a translation table.
783 for (hWnd
= msg
->hwnd
; hWnd
!= NULL
; hWnd
= ::GetParent(hWnd
))
785 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
788 if (wnd
->MSWTranslateMessage(Msg
))
793 // Anyone for a non-translation message? Try youngest descendants first.
794 for (hWnd
= msg
->hwnd
; hWnd
!= NULL
; hWnd
= ::GetParent(hWnd
))
796 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
799 if (wnd
->MSWProcessMessage(Msg
))
806 void wxApp::OnIdle(wxIdleEvent
& event
)
808 static bool inOnIdle
= FALSE
;
810 // Avoid recursion (via ProcessEvent default case)
816 // 'Garbage' collection of windows deleted with Close().
817 DeletePendingObjects();
819 // flush the logged messages if any
820 wxLog
*pLog
= wxLog::GetActiveTarget();
821 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
824 // Send OnIdle events to all windows
825 bool needMore
= SendIdleEvents();
826 // bool needMore = FALSE;
829 event
.RequestMore(TRUE
);
834 // Send idle event to all top-level windows
835 bool wxApp::SendIdleEvents()
837 bool needMore
= FALSE
;
838 wxNode
* node
= wxTopLevelWindows
.First();
841 wxWindow
* win
= (wxWindow
*) node
->Data();
842 if (SendIdleEvents(win
))
850 // Send idle event to window and all subwindows
851 bool wxApp::SendIdleEvents(wxWindow
* win
)
853 bool needMore
= FALSE
;
856 event
.SetEventObject(win
);
857 win
->ProcessEvent(event
);
859 if (event
.MoreRequested())
862 wxNode
* node
= win
->GetChildren()->First();
865 wxWindow
* win
= (wxWindow
*) node
->Data();
866 if (SendIdleEvents(win
))
874 void wxApp::DeletePendingObjects()
876 wxNode
*node
= wxPendingDelete
.First();
879 wxObject
*obj
= (wxObject
*)node
->Data();
883 if (wxPendingDelete
.Member(obj
))
886 // Deleting one object may have deleted other pending
887 // objects, so start from beginning of list again.
888 node
= wxPendingDelete
.First();
892 void wxApp::OnEndSession(wxCloseEvent
& event
)
895 GetTopWindow()->Close(TRUE
);
898 // Default behaviour: close the application with prompts. The
899 // user can veto the close, and therefore the end session.
900 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
904 if (!GetTopWindow()->Close(!event
.CanVeto()))
909 wxLog
* wxApp::CreateLogTarget()
914 wxWindow
* wxApp::GetTopWindow() const
918 else if (wxTopLevelWindows
.Number() > 0)
919 return (wxWindow
*) wxTopLevelWindows
.First()->Data();
924 int wxApp::GetComCtl32Version() const
926 // have we loaded COMCTL32 yet?
927 HMODULE theModule
= ::GetModuleHandle("COMCTL32");
930 // if so, then we can check for the version
933 // InitCommonControlsEx is unique to 4.7 and later
934 FARPROC theProc
= ::GetProcAddress(theModule
, "InitCommonControlsEx");
937 { // not found, must be 4.00
942 // The following symbol are unique to 4.71
944 // FlatSB_EnableScrollBar FlatSB_GetScrollInfo FlatSB_GetScrollPos
945 // FlatSB_GetScrollProp FlatSB_GetScrollRange FlatSB_SetScrollInfo
946 // FlatSB_SetScrollPos FlatSB_SetScrollProp FlatSB_SetScrollRange
947 // FlatSB_ShowScrollBar
948 // _DrawIndirectImageList _DuplicateImageList
950 // UninitializeFlatSB
951 // we could check for any of these - I chose DllInstall
952 FARPROC theProc
= ::GetProcAddress(theModule
, "DllInstall");
955 // not found, must be 4.70
959 { // found, must be 4.71
970 FatalAppExit(0, "Fatal error: exiting");
973 // Yield to incoming messages
977 // We want to go back to the main message loop
978 // if we see a WM_QUIT. (?)
979 while (PeekMessage(&msg
, NULL
, 0, 0, PM_NOREMOVE
) && msg
.message
!= WM_QUIT
)
981 if (!wxTheApp
->DoMessage())
988 HINSTANCE
wxGetInstance()
993 // For some reason, with MSVC++ 1.5, WinMain isn't linked in properly
994 // if in a separate file. So include it here to ensure it's linked.
995 #if (defined(_MSC_VER) && !defined(__WIN32__)) || defined(__GNUWIN32__)