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"
43 #include "wx/thread.h"
46 #if wxUSE_WX_RESOURCES
47 #include "wx/resource.h"
50 // To UG: there's no point in putting this #if here
51 // if you don't do the same for the Ole calls further down.
52 // Also, OLE is used not just for drag and drop (it's used by automatn.cpp).
53 // #if wxUSE_DRAG_AND_DROP
62 #if defined(__WIN95__) && !defined(__GNUWIN32__)
66 // use debug CRT functions for memory leak detections in VC++ if we're not
67 // using wxWindows own methods
68 #if defined(__WXDEBUG__) && defined(_MSC_VER) && !wxUSE_GLOBAL_MEMORY_OPERATORS && !defined(__NO_VC_CRTDBG__)
69 #define wxUSE_VC_CRTDBG
71 #undef wxUSE_VC_CRTDBG
74 #ifdef wxUSE_VC_CRTDBG
75 // VC++ uses this macro as debug/release mode indicator
80 /* Need to undef new if including crtdbg.h */
87 #if defined(__WXDEBUG__) && wxUSE_GLOBAL_MEMORY_OPERATORS && wxUSE_DEBUG_NEW_ALWAYS
88 #define new new(__FILE__,__LINE__)
93 extern char *wxBuffer
;
94 extern char *wxOsVersion
;
95 extern wxList
*wxWinHandleList
;
96 extern wxList wxPendingDelete
;
97 extern void wxSetKeyboardHook(bool doIt
);
98 extern wxCursor
*g_globalCursor
;
100 HINSTANCE wxhInstance
= 0;
101 static MSG s_currentMsg
;
102 wxApp
*wxTheApp
= NULL
;
104 // @@ why not const? and not static?
105 char wxFrameClassName
[] = "wxFrameClass";
106 char wxMDIFrameClassName
[] = "wxMDIFrameClass";
107 char wxMDIChildFrameClassName
[] = "wxMDIChildFrameClass";
108 char wxPanelClassName
[] = "wxPanelClass";
109 char wxCanvasClassName
[] = "wxCanvasClass";
111 HICON wxSTD_FRAME_ICON
= NULL
;
112 HICON wxSTD_MDICHILDFRAME_ICON
= NULL
;
113 HICON wxSTD_MDIPARENTFRAME_ICON
= NULL
;
115 HICON wxDEFAULT_FRAME_ICON
= NULL
;
116 HICON wxDEFAULT_MDICHILDFRAME_ICON
= NULL
;
117 HICON wxDEFAULT_MDIPARENTFRAME_ICON
= NULL
;
119 HBRUSH wxDisableButtonBrush
= 0;
121 LRESULT APIENTRY
wxWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
123 #if !USE_SHARED_LIBRARY
124 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
126 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
127 EVT_IDLE(wxApp::OnIdle
)
128 EVT_END_SESSION(wxApp::OnEndSession
)
129 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
)
133 long wxApp::sm_lastMessageTime
= 0;
136 static HINSTANCE gs_hRichEdit
= NULL
;
141 bool wxApp::Initialize()
143 // Some people may wish to use this, but
144 // probably it shouldn't be here by default.
146 // wxRedirectIOToConsole();
149 wxBuffer
= new char[1500];
151 #ifdef wxUSE_VC_CRTDBG
152 // do check for memory leaks on program exit
153 // (another useful flag is _CRTDBG_DELAY_FREE_MEM_DF which doesn't free
154 // deallocated memory which may be used to simulate low-memory condition)
155 _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG
) | _CRTDBG_LEAK_CHECK_DF
);
156 #endif // debug build under MS VC++
158 wxClassInfo::InitializeClasses();
161 wxGetResource("wxWindows", "OsVersion", &wxOsVersion
);
164 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
165 wxTheColourDatabase
->Initialize();
167 wxInitializeStockLists();
168 wxInitializeStockObjects();
170 #if wxUSE_WX_RESOURCES
171 wxInitializeResourceSystem();
174 wxBitmap::InitStandardHandlers();
176 #if defined(__WIN95__)
177 InitCommonControls();
178 gs_hRichEdit
= LoadLibrary("RICHED32.DLL");
180 if (gs_hRichEdit
== NULL
)
182 wxMessageBox("Could not initialise Rich Edit DLL");
188 // for OLE, enlarge message queue to be as large as possible
189 while (!SetMessageQueue(iMsg
) && (iMsg
-= 8));
193 dwOleVer = CoBuildVersion();
195 // check the OLE library version
196 if (rmm != HIWORD(dwOleVer))
198 wxMessageBox("Incorrect version of OLE libraries.");
204 // we need to initialize OLE library
205 if ( FAILED(::OleInitialize(NULL
)) )
206 wxFatalError(_("Cannot initialize OLE"));
210 if (!Ctl3dRegister(wxhInstance
))
211 wxFatalError("Cannot register CTL3D");
213 Ctl3dAutoSubclass(wxhInstance
);
216 g_globalCursor
= new wxCursor
;
218 wxSTD_FRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_FRAME");
219 wxSTD_MDIPARENTFRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_MDIPARENTFRAME");
220 wxSTD_MDICHILDFRAME_ICON
= LoadIcon(wxhInstance
, "wxSTD_MDICHILDFRAME");
222 wxDEFAULT_FRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_FRAME");
223 wxDEFAULT_MDIPARENTFRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_MDIPARENTFRAME");
224 wxDEFAULT_MDICHILDFRAME_ICON
= LoadIcon(wxhInstance
, "wxDEFAULT_MDICHILDFRAME");
226 RegisterWindowClasses();
228 // Create the brush for disabling bitmap buttons
231 lb
.lbStyle
= BS_PATTERN
;
232 lb
.lbHatch
= (int)LoadBitmap( wxhInstance
, "wxDISABLE_BUTTON_BITMAP" ) ;
233 wxDisableButtonBrush
= ::CreateBrushIndirect( & lb
) ;
234 ::DeleteObject( (HGDIOBJ
)lb
.lbHatch
) ;
240 wxWinHandleList
= new wxList(wxKEY_INTEGER
);
242 // This is to foil optimizations in Visual C++ that
243 // throw out dummy.obj.
244 #if (_MSC_VER >= 800) && !defined(WXMAKINGDLL)
245 extern char wxDummyChar
;
246 if (wxDummyChar
) wxDummyChar
++;
249 wxSetKeyboardHook(TRUE
);
251 wxModule::RegisterModules();
252 if (!wxModule::InitializeModules())
257 //// RegisterWindowClasses
259 bool wxApp::RegisterWindowClasses()
261 ///////////////////////////////////////////////////////////////////////
262 // Register the frame window class.
263 WNDCLASS wndclass
; // Structure used to register Windows class.
265 wndclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
266 wndclass
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
267 wndclass
.cbClsExtra
= 0;
268 wndclass
.cbWndExtra
= sizeof( DWORD
); // was 4
269 wndclass
.hInstance
= wxhInstance
;
270 wndclass
.hIcon
= NULL
; // wxSTD_FRAME_ICON;
271 wndclass
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
272 wndclass
.hbrBackground
= (HBRUSH
)(COLOR_APPWORKSPACE
+1) ;
273 // wndclass.hbrBackground = GetStockObject( WHITE_BRUSH );
274 wndclass
.lpszMenuName
= NULL
;
275 #ifdef _MULTIPLE_INSTANCES
276 sprintf( wxFrameClassName
,"wxFrameClass%d", wxhInstance
);
278 wndclass
.lpszClassName
= wxFrameClassName
;
280 if (!RegisterClass( &wndclass
))
282 // wxFatalError("Can't register Frame Window class");
285 ///////////////////////////////////////////////////////////////////////
286 // Register the MDI frame window class.
287 WNDCLASS wndclass1
; // Structure used to register Windows class.
289 wndclass1
.style
= CS_HREDRAW
| CS_VREDRAW
;
290 wndclass1
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
291 wndclass1
.cbClsExtra
= 0;
292 wndclass1
.cbWndExtra
= sizeof( DWORD
); // was 4
293 wndclass1
.hInstance
= wxhInstance
;
294 wndclass1
.hIcon
= NULL
; // wxSTD_MDIPARENTFRAME_ICON;
295 wndclass1
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
296 // wndclass1.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1) ;
297 wndclass1
.hbrBackground
= NULL
;
298 wndclass1
.lpszMenuName
= NULL
;
300 wndclass1
.lpszClassName
= wxMDIFrameClassName
;
301 if (!RegisterClass( &wndclass1
))
303 // wxFatalError("Can't register MDI Frame window class");
307 ///////////////////////////////////////////////////////////////////////
308 // Register the MDI child frame window class.
309 WNDCLASS wndclass4
; // Structure used to register Windows class.
311 wndclass4
.style
= CS_HREDRAW
| CS_VREDRAW
;
312 wndclass4
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
313 wndclass4
.cbClsExtra
= 0;
314 wndclass4
.cbWndExtra
= sizeof( DWORD
); // was 4
315 wndclass4
.hInstance
= wxhInstance
;
316 wndclass4
.hIcon
= NULL
; // wxSTD_MDICHILDFRAME_ICON;
317 wndclass4
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
318 // TODO: perhaps this should be NULL so that Windows doesn't
319 // paint the background itself (would OnEraseBackground duplicate
321 wndclass4
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1) ;
322 // wndclass4.hbrBackground = NULL;
323 wndclass4
.lpszMenuName
= NULL
;
324 wndclass4
.lpszClassName
= wxMDIChildFrameClassName
;
326 if (!RegisterClass( &wndclass4
))
328 // wxFatalError("Can't register MDI child frame window class");
332 ///////////////////////////////////////////////////////////////////////
333 // Register the panel window class.
334 WNDCLASS wndclass2
; // Structure used to register Windows class.
335 memset(&wndclass2
, 0, sizeof(WNDCLASS
)); // start with NULL defaults
336 // Use CS_OWNDC to avoid messing about restoring the context
337 // for every graphic operation.
338 wndclass2
.style
= CS_HREDRAW
| CS_VREDRAW
;
339 wndclass2
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
340 wndclass2
.cbClsExtra
= 0;
341 wndclass2
.cbWndExtra
= sizeof( DWORD
); // was 4
342 wndclass2
.hInstance
= wxhInstance
;
343 wndclass2
.hIcon
= NULL
;
344 wndclass2
.hCursor
= NULL
;
345 // wndclass2.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1) ;
346 wndclass2
.hbrBackground
= (HBRUSH
) GetStockObject( LTGRAY_BRUSH
);
347 wndclass2
.lpszMenuName
= NULL
;
348 wndclass2
.lpszClassName
= wxPanelClassName
;
349 if (!RegisterClass( &wndclass2
))
351 // wxFatalError("Can't register Panel Window class");
355 ///////////////////////////////////////////////////////////////////////
356 // Register the canvas and textsubwindow class name
357 WNDCLASS wndclass3
; // Structure used to register Windows class.
358 memset(&wndclass3
, 0, sizeof(WNDCLASS
)); // start with NULL defaults
359 // Use CS_OWNDC to avoid messing about restoring the context
360 // for every graphic operation.
361 // wndclass3.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS ;
363 wndclass3
.style
= CS_HREDRAW
| CS_VREDRAW
| CS_DBLCLKS
;
364 wndclass3
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
365 wndclass3
.cbClsExtra
= 0;
366 wndclass3
.cbWndExtra
= sizeof( DWORD
); // was 4
367 wndclass3
.hInstance
= wxhInstance
;
368 wndclass3
.hIcon
= NULL
;
369 wndclass3
.hCursor
= NULL
;
370 // wndclass3.hbrBackground = (HBRUSH)(COLOR_WINDOW+1) ;
371 wndclass3
.hbrBackground
= NULL
;
372 wndclass3
.lpszMenuName
= NULL
;
373 wndclass3
.lpszClassName
= wxCanvasClassName
;
374 if (!RegisterClass( &wndclass3
))
376 // wxFatalError("Can't register Canvas class");
383 //// Convert Windows to argc, argv style
385 void wxApp::ConvertToStandardCommandArgs(char* lpCmdLine
)
389 wxString
cmdLine(lpCmdLine
);
392 // Get application name
393 char name
[260]; // 260 is MAX_PATH value from windef.h
394 ::GetModuleFileName(wxhInstance
, name
, WXSIZEOF(name
));
396 // GNUWIN32 already fills in the first arg with the application name.
397 #if !defined(__GNUWIN32__)
402 strcpy(name
, wxFileNameFromPath(name
));
403 wxStripExtension(name
);
404 wxTheApp
->SetAppName(name
);
407 // Treat strings enclosed in double-quotes as single arguments
409 int len
= cmdLine
.Length();
413 while ((i
< len
) && isspace(cmdLine
.GetChar(i
)))
418 if (cmdLine
.GetChar(i
) == '"') // We found the start of a string
422 while ((i
< len
) && (cmdLine
.GetChar(i
) != '"'))
425 wxString
arg(cmdLine
.Mid(first
, (i
- first
)));
431 i
++; // Skip past 2nd quote
433 else // Unquoted argument
436 while ((i
< len
) && !isspace(cmdLine
.GetChar(i
)))
439 wxString
arg(cmdLine
.Mid(first
, (i
- first
)));
447 wxTheApp
->argv
= new char*[count
+ 1];
448 for (i
= 0; i
< count
; i
++)
450 wxString
arg(args
[i
]);
451 wxTheApp
->argv
[i
] = copystring((const char*)arg
);
453 wxTheApp
->argv
[count
] = NULL
; // argv[] is a NULL-terminated list
454 wxTheApp
->argc
= count
;
457 //// Cleans up any wxWindows internal structures left lying around
459 void wxApp::CleanUp()
462 wxModule::CleanUpModules();
464 #if wxUSE_WX_RESOURCES
465 wxCleanUpResourceSystem();
467 // wxDefaultResourceTable->ClearTable();
470 // Indicate that the cursor can be freed,
471 // so that cursor won't be deleted by deleting
472 // the bitmap list before g_globalCursor goes out
473 // of scope (double deletion of the cursor).
474 wxSetCursor(wxNullCursor
);
475 delete g_globalCursor
;
477 wxDeleteStockObjects() ;
479 // Destroy all GDI lists, etc.
480 wxDeleteStockLists();
482 delete wxTheColourDatabase
;
483 wxTheColourDatabase
= NULL
;
485 wxBitmap::CleanUpHandlers();
490 //// WINDOWS-SPECIFIC CLEANUP
492 wxSetKeyboardHook(FALSE
);
495 if (gs_hRichEdit
!= NULL
)
496 FreeLibrary(gs_hRichEdit
);
503 if (wxSTD_FRAME_ICON
)
504 DestroyIcon(wxSTD_FRAME_ICON
);
505 if (wxSTD_MDICHILDFRAME_ICON
)
506 DestroyIcon(wxSTD_MDICHILDFRAME_ICON
);
507 if (wxSTD_MDIPARENTFRAME_ICON
)
508 DestroyIcon(wxSTD_MDIPARENTFRAME_ICON
);
510 if (wxDEFAULT_FRAME_ICON
)
511 DestroyIcon(wxDEFAULT_FRAME_ICON
);
512 if (wxDEFAULT_MDICHILDFRAME_ICON
)
513 DestroyIcon(wxDEFAULT_MDICHILDFRAME_ICON
);
514 if (wxDEFAULT_MDIPARENTFRAME_ICON
)
515 DestroyIcon(wxDEFAULT_MDIPARENTFRAME_ICON
);
517 if ( wxDisableButtonBrush
)
518 ::DeleteObject( wxDisableButtonBrush
) ;
525 Ctl3dUnregister(wxhInstance
);
529 delete wxWinHandleList
;
531 wxClassInfo::CleanUpClasses();
536 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
537 // At this point we want to check if there are any memory
538 // blocks that aren't part of the wxDebugContext itself,
539 // as a special case. Then when dumping we need to ignore
540 // wxDebugContext, too.
541 if (wxDebugContext::CountObjectsLeft() > 0)
543 wxLogDebug("There were memory leaks.");
544 wxDebugContext::Dump();
545 wxDebugContext::PrintStatistics();
547 // wxDebugContext::SetStream(NULL, NULL);
550 // do it as the very last thing because everything else can log messages
551 wxLog::DontCreateOnDemand();
552 delete wxLog::SetActiveTarget(NULL
);
555 #if !defined(_WINDLL) || (defined(_WINDLL) && defined(WXMAKINGDLL))
557 //// Main wxWindows entry point
558 int wxEntry(WXHINSTANCE hInstance
,
559 WXHINSTANCE
WXUNUSED(hPrevInstance
),
564 #if !defined(__WXDEBUG__) && !defined(__BORLANDC__) // take everything into a try-except block in release build
568 wxhInstance
= (HINSTANCE
) hInstance
;
570 if (!wxApp::Initialize())
573 // create the application object or ensure that one already exists
576 // The app may have declared a global application object, but we recommend
577 // the IMPLEMENT_APP macro is used instead, which sets an initializer
578 // function for delayed, dynamic app object construction.
579 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
580 "No initializer - use IMPLEMENT_APP macro." );
582 wxTheApp
= (*wxApp::GetInitializerFunction()) ();
585 wxCHECK_MSG( wxTheApp
, 0, "You have to define an instance of wxApp!" );
587 // save the WinMain() parameters
588 wxTheApp
->ConvertToStandardCommandArgs(lpCmdLine
);
589 wxTheApp
->m_nCmdShow
= nCmdShow
;
591 // GUI-specific initialisation. In fact on Windows we don't have any,
592 // but this call is provided for compatibility across platforms.
593 wxTheApp
->OnInitGui() ;
597 if ( wxTheApp
->OnInit() )
601 retValue
= wxTheApp
->OnRun();
604 //else: app initialization failed, so we skipped OnRun()
606 wxWindow
*topWindow
= wxTheApp
->GetTopWindow();
609 // Forcibly delete the window.
610 if ( topWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
611 topWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
613 topWindow
->Close(TRUE
);
614 wxTheApp
->DeletePendingObjects();
619 wxTheApp
->SetTopWindow(NULL
);
625 // flush the logged messages if any
626 wxLog
*pLog
= wxLog::GetActiveTarget();
627 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
634 #if !defined(__WXDEBUG__) && !defined(__BORLANDC__) // catch exceptions only in release build
636 except ( EXCEPTION_EXECUTE_HANDLER
) {
639 wxTheApp->OnFatalException();
642 ::ExitProcess(3); // the same exit code as abort()
649 //// Entry point for DLLs
651 int wxEntry(WXHINSTANCE hInstance
)
653 wxhInstance
= (HINSTANCE
) hInstance
;
656 // The app may have declared a global application object, but we recommend
657 // the IMPLEMENT_APP macro is used instead, which sets an initializer function
658 // for delayed, dynamic app object construction.
662 if (!wxApp::GetInitializerFunction())
664 MessageBox(NULL
, "No initializer - use IMPLEMENT_APP macro.", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
668 wxTheApp
= (* wxApp::GetInitializerFunction()) ();
672 MessageBox(NULL
, "You have to define an instance of wxApp!", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
677 wxTheApp
->argv
= NULL
;
679 wxTheApp
->OnInitGui();
683 if (wxTheApp
->GetTopWindow() && wxTheApp
->GetTopWindow()->GetHWND()) {
684 wxTheApp
->GetTopWindow()->Show(TRUE
);
691 //// Static member initialization
693 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
700 m_wantDebugOutput
= TRUE
;
705 m_printMode
= wxPRINT_WINDOWS
;
707 m_printMode
= wxPRINT_POSTSCRIPT
;
709 m_exitOnFrameDelete
= TRUE
;
715 // Delete command-line args
717 for (i
= 0; i
< argc
; i
++)
724 bool wxApp::Initialized()
732 #ifdef _WINDLL // Assume initialized if DLL (no way of telling)
738 * Get and process a message, returning FALSE if WM_QUIT
742 bool wxApp::DoMessage()
744 if (!::GetMessage(&s_currentMsg
, (HWND
) NULL
, 0, 0))
749 // Process the message
750 if (!ProcessMessage((WXMSG
*)&s_currentMsg
))
752 ::TranslateMessage(&s_currentMsg
);
753 wxApp::sm_lastMessageTime
= s_currentMsg
.time
; /* MATTHEW: timeStamp impl. */
754 ::DispatchMessage(&s_currentMsg
);
760 * Keep trying to process messages until WM_QUIT
763 * If there are messages to be processed, they will all be
764 * processed and OnIdle will not be called.
765 * When there are no more messages, OnIdle is called.
766 * If OnIdle requests more time,
767 * it will be repeatedly called so long as there are no pending messages.
768 * A 'feature' of this is that once OnIdle has decided that no more processing
769 * is required, then it won't get processing time until further messages
770 * are processed (it'll sit in DoMessage).
773 int wxApp::MainLoop()
778 while (!::PeekMessage(&s_currentMsg
, 0, 0, 0, PM_NOREMOVE
) &&
784 return s_currentMsg
.wParam
;
787 // Returns TRUE if more time is needed.
788 bool wxApp::ProcessIdle()
791 event
.SetEventObject(this);
794 return event
.MoreRequested();
797 void wxApp::ExitMainLoop()
802 bool wxApp::Pending()
804 return (::PeekMessage(&s_currentMsg
, 0, 0, 0, PM_NOREMOVE
) != 0) ;
807 void wxApp::Dispatch()
814 * Give all windows a chance to preprocess
815 * the message. Some may have accelerator tables, or have
818 bool wxApp::ProcessMessage(WXMSG
*Msg
)
820 MSG
*msg
= (MSG
*)Msg
;
824 // Try translations first; find the youngest window with
825 // a translation table.
826 for (hWnd
= msg
->hwnd
; hWnd
!= NULL
; hWnd
= ::GetParent(hWnd
))
828 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
831 if (wnd
->MSWTranslateMessage(Msg
))
836 // Anyone for a non-translation message? Try youngest descendants first.
837 for (hWnd
= msg
->hwnd
; hWnd
!= NULL
; hWnd
= ::GetParent(hWnd
))
839 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
842 if (wnd
->MSWProcessMessage(Msg
))
849 void wxApp::OnIdle(wxIdleEvent
& event
)
851 static bool s_inOnIdle
= FALSE
;
853 // Avoid recursion (via ProcessEvent default case)
859 // 'Garbage' collection of windows deleted with Close().
860 DeletePendingObjects();
862 // flush the logged messages if any
863 wxLog
*pLog
= wxLog::GetActiveTarget();
864 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
867 // Send OnIdle events to all windows
868 if ( SendIdleEvents() )
870 // SendIdleEvents() returns TRUE if at least one window requested more
872 event
.RequestMore(TRUE
);
875 // give a chance to all other threads to perform GUI calls
884 // Send idle event to all top-level windows
885 bool wxApp::SendIdleEvents()
887 bool needMore
= FALSE
;
888 wxNode
* node
= wxTopLevelWindows
.First();
891 wxWindow
* win
= (wxWindow
*) node
->Data();
892 if (SendIdleEvents(win
))
901 // Send idle event to window and all subwindows
902 bool wxApp::SendIdleEvents(wxWindow
* win
)
904 bool needMore
= FALSE
;
907 event
.SetEventObject(win
);
908 win
->GetEventHandler()->ProcessEvent(event
);
910 if (event
.MoreRequested())
913 wxNode
* node
= win
->GetChildren().First();
916 wxWindow
* win
= (wxWindow
*) node
->Data();
917 if (SendIdleEvents(win
))
925 void wxApp::DeletePendingObjects()
927 wxNode
*node
= wxPendingDelete
.First();
930 wxObject
*obj
= (wxObject
*)node
->Data();
934 if (wxPendingDelete
.Member(obj
))
937 // Deleting one object may have deleted other pending
938 // objects, so start from beginning of list again.
939 node
= wxPendingDelete
.First();
943 void wxApp::OnEndSession(wxCloseEvent
& event
)
946 GetTopWindow()->Close(TRUE
);
949 // Default behaviour: close the application with prompts. The
950 // user can veto the close, and therefore the end session.
951 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
955 if (!GetTopWindow()->Close(!event
.CanVeto()))
960 wxLog
* wxApp::CreateLogTarget()
965 wxWindow
* wxApp::GetTopWindow() const
969 else if (wxTopLevelWindows
.Number() > 0)
970 return (wxWindow
*) wxTopLevelWindows
.First()->Data();
975 int wxApp::GetComCtl32Version() const
977 // have we loaded COMCTL32 yet?
978 HMODULE theModule
= ::GetModuleHandle("COMCTL32");
981 // if so, then we can check for the version
984 // InitCommonControlsEx is unique to 4.7 and later
985 FARPROC theProc
= ::GetProcAddress(theModule
, "InitCommonControlsEx");
988 { // not found, must be 4.00
993 // The following symbol are unique to 4.71
995 // FlatSB_EnableScrollBar FlatSB_GetScrollInfo FlatSB_GetScrollPos
996 // FlatSB_GetScrollProp FlatSB_GetScrollRange FlatSB_SetScrollInfo
997 // FlatSB_SetScrollPos FlatSB_SetScrollProp FlatSB_SetScrollRange
998 // FlatSB_ShowScrollBar
999 // _DrawIndirectImageList _DuplicateImageList
1001 // UninitializeFlatSB
1002 // we could check for any of these - I chose DllInstall
1003 FARPROC theProc
= ::GetProcAddress(theModule
, "DllInstall");
1006 // not found, must be 4.70
1010 { // found, must be 4.71
1021 FatalAppExit(0, "Fatal error: exiting");
1024 // Yield to incoming messages
1028 // We want to go back to the main message loop
1029 // if we see a WM_QUIT. (?)
1030 while (PeekMessage(&msg
, NULL
, 0, 0, PM_NOREMOVE
) && msg
.message
!= WM_QUIT
)
1032 if (!wxTheApp
->DoMessage())
1039 HINSTANCE
wxGetInstance()
1044 // For some reason, with MSVC++ 1.5, WinMain isn't linked in properly
1045 // if in a separate file. So include it here to ensure it's linked.
1046 #if (defined(_MSC_VER) && !defined(__WIN32__)) || defined(__GNUWIN32__)