1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
21 #pragma implementation "app.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
27 #if defined(__BORLANDC__)
35 #include "wx/gdicmn.h"
38 #include "wx/cursor.h"
40 #include "wx/palette.h"
42 #include "wx/dialog.h"
43 #include "wx/msgdlg.h"
45 #include "wx/dynarray.h"
46 # include "wx/wxchar.h"
51 #include "wx/module.h"
53 #include "wx/msw/private.h"
56 #include "wx/thread.h"
58 // define the array of MSG strutures
59 WX_DECLARE_OBJARRAY(MSG
, wxMsgArray
);
61 #include "wx/arrimpl.cpp"
63 WX_DEFINE_OBJARRAY(wxMsgArray
);
64 #endif // wxUSE_THREADS
66 #if wxUSE_WX_RESOURCES
67 #include "wx/resource.h"
70 // OLE is used for drag-and-drop, clipboard, OLE Automation...
71 #if defined(__GNUWIN32__) || defined(__SC__) || defined(__SALFORDC__)
75 #endif // broken compilers
84 #if (defined(__WIN95__) && !defined(__GNUWIN32__)) || defined(__TWIN32__)
88 #include "wx/msw/msvcrt.h"
90 // ---------------------------------------------------------------------------
92 // ---------------------------------------------------------------------------
94 extern wxChar
*wxBuffer
;
95 extern wxChar
*wxOsVersion
;
96 extern wxList
*wxWinHandleList
;
97 extern wxList WXDLLEXPORT wxPendingDelete
;
99 extern wxList
*wxPendingEvents
;
100 extern wxCriticalSection
*wxPendingEventsLocker
;
102 extern void wxSetKeyboardHook(bool doIt
);
103 extern wxCursor
*g_globalCursor
;
105 HINSTANCE wxhInstance
= 0;
107 wxApp
*wxTheApp
= NULL
;
109 // FIXME why not const? and not static?
110 wxChar wxFrameClassName
[] = _T("wxFrameClass");
111 wxChar wxMDIFrameClassName
[] = _T("wxMDIFrameClass");
112 wxChar wxMDIChildFrameClassName
[] = _T("wxMDIChildFrameClass");
113 wxChar wxPanelClassName
[] = _T("wxPanelClass");
114 wxChar wxCanvasClassName
[] = _T("wxCanvasClass");
116 HICON wxSTD_FRAME_ICON
= (HICON
) NULL
;
117 HICON wxSTD_MDICHILDFRAME_ICON
= (HICON
) NULL
;
118 HICON wxSTD_MDIPARENTFRAME_ICON
= (HICON
) NULL
;
120 HICON wxDEFAULT_FRAME_ICON
= (HICON
) NULL
;
121 HICON wxDEFAULT_MDICHILDFRAME_ICON
= (HICON
) NULL
;
122 HICON wxDEFAULT_MDIPARENTFRAME_ICON
= (HICON
) NULL
;
124 HBRUSH wxDisableButtonBrush
= (HBRUSH
) 0;
126 LRESULT APIENTRY
wxWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
128 #if defined(__WIN95__) && !defined(__TWIN32__)
129 #define wxUSE_RICHEDIT 1
131 #define wxUSE_RICHEDIT 0
135 static HINSTANCE gs_hRichEdit
= (HINSTANCE
) NULL
;
138 // ===========================================================================
140 // ===========================================================================
142 // ---------------------------------------------------------------------------
144 // ---------------------------------------------------------------------------
146 #if !USE_SHARED_LIBRARY
147 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
149 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
150 EVT_IDLE(wxApp::OnIdle
)
151 EVT_END_SESSION(wxApp::OnEndSession
)
152 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
)
157 bool wxApp::Initialize()
159 // Some people may wish to use this, but
160 // probably it shouldn't be here by default.
162 // wxRedirectIOToConsole();
165 wxBuffer
= new wxChar
[1500]; // FIXME
167 wxClassInfo::InitializeClasses();
170 wxGetResource(_T("wxWindows"), _T("OsVersion"), &wxOsVersion
);
173 // I'm annoyed ... I don't know where to put this and I don't want to
174 // create a module for that as it's part of the core.
176 wxPendingEvents
= new wxList();
177 wxPendingEventsLocker
= new wxCriticalSection();
180 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
181 wxTheColourDatabase
->Initialize();
183 wxInitializeStockLists();
184 wxInitializeStockObjects();
186 #if wxUSE_WX_RESOURCES
187 wxInitializeResourceSystem();
190 wxBitmap::InitStandardHandlers();
192 #if defined(__WIN95__)
193 InitCommonControls();
196 gs_hRichEdit
= LoadLibrary(_T("RICHED32.DLL"));
198 if (gs_hRichEdit
== (HINSTANCE
) NULL
)
200 wxLogError(_("Could not initialise Rich Edit DLL"));
202 #endif // wxUSE_RICHEDIT
206 // for OLE, enlarge message queue to be as large as possible
208 while (!SetMessageQueue(iMsg
) && (iMsg
-= 8));
211 // we need to initialize OLE library
212 if ( FAILED(::OleInitialize(NULL
)) )
213 wxLogError(_("Cannot initialize OLE"));
217 if (!Ctl3dRegister(wxhInstance
))
218 wxLogError(_T("Cannot register CTL3D"));
220 Ctl3dAutoSubclass(wxhInstance
);
223 g_globalCursor
= new wxCursor
;
225 wxSTD_FRAME_ICON
= LoadIcon(wxhInstance
, _T("wxSTD_FRAME"));
226 wxSTD_MDIPARENTFRAME_ICON
= LoadIcon(wxhInstance
, _T("wxSTD_MDIPARENTFRAME"));
227 wxSTD_MDICHILDFRAME_ICON
= LoadIcon(wxhInstance
, _T("wxSTD_MDICHILDFRAME"));
229 wxDEFAULT_FRAME_ICON
= LoadIcon(wxhInstance
, _T("wxDEFAULT_FRAME"));
230 wxDEFAULT_MDIPARENTFRAME_ICON
= LoadIcon(wxhInstance
, _T("wxDEFAULT_MDIPARENTFRAME"));
231 wxDEFAULT_MDICHILDFRAME_ICON
= LoadIcon(wxhInstance
, _T("wxDEFAULT_MDICHILDFRAME"));
233 RegisterWindowClasses();
235 // Create the brush for disabling bitmap buttons
238 lb
.lbStyle
= BS_PATTERN
;
239 lb
.lbHatch
= (int)LoadBitmap( wxhInstance
, _T("wxDISABLE_BUTTON_BITMAP") );
242 wxDisableButtonBrush
= ::CreateBrushIndirect( & lb
);
243 ::DeleteObject( (HGDIOBJ
)lb
.lbHatch
);
245 //else: wxWindows resources are probably not linked in
251 wxWinHandleList
= new wxList(wxKEY_INTEGER
);
253 // This is to foil optimizations in Visual C++ that throw out dummy.obj.
254 // PLEASE DO NOT ALTER THIS.
255 #if defined(__VISUALC__) && !defined(WXMAKINGDLL)
256 extern char wxDummyChar
;
257 if (wxDummyChar
) wxDummyChar
++;
260 wxSetKeyboardHook(TRUE
);
262 wxModule::RegisterModules();
263 if (!wxModule::InitializeModules())
268 // ---------------------------------------------------------------------------
269 // RegisterWindowClasses
270 // ---------------------------------------------------------------------------
272 bool wxApp::RegisterWindowClasses()
276 // the fields which are common to all classes
277 wndclass
.style
= CS_HREDRAW
| CS_VREDRAW
| CS_DBLCLKS
;
278 wndclass
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
279 wndclass
.cbClsExtra
= 0;
280 wndclass
.cbWndExtra
= sizeof( DWORD
); // what is this DWORD used for?
281 wndclass
.hInstance
= wxhInstance
;
282 wndclass
.hIcon
= (HICON
) NULL
;
283 wndclass
.hCursor
= ::LoadCursor((HINSTANCE
)NULL
, IDC_ARROW
);
284 wndclass
.lpszMenuName
= NULL
;
286 // Register the frame window class.
287 wndclass
.hbrBackground
= (HBRUSH
)(COLOR_APPWORKSPACE
+ 1);
288 #ifdef _MULTIPLE_INSTANCES
289 sprintf( wxFrameClassName
,"wxFrameClass%d", wxhInstance
);
291 wndclass
.lpszClassName
= wxFrameClassName
;
293 if ( !RegisterClass(&wndclass
) )
295 wxLogLastError("RegisterClass(frame)");
300 // Register the MDI frame window class.
301 wndclass
.hbrBackground
= (HBRUSH
)NULL
; // paint MDI frame ourselves
302 wndclass
.lpszClassName
= wxMDIFrameClassName
;
304 if ( !RegisterClass(&wndclass
) )
306 wxLogLastError("RegisterClass(MDI parent)");
311 // Register the MDI child frame window class.
312 wndclass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
313 wndclass
.lpszClassName
= wxMDIChildFrameClassName
;
315 if ( !RegisterClass(&wndclass
) )
317 wxLogLastError("RegisterClass(MDI child)");
322 // Register the panel window class.
323 wndclass
.hbrBackground
= (HBRUSH
) GetStockObject( LTGRAY_BRUSH
);
324 wndclass
.lpszClassName
= wxPanelClassName
;
326 if ( !RegisterClass(&wndclass
) )
328 wxLogLastError("RegisterClass(panel)");
333 // Register the canvas and textsubwindow class name
334 wndclass
.hbrBackground
= (HBRUSH
)NULL
;
335 wndclass
.lpszClassName
= wxCanvasClassName
;
337 if ( !RegisterClass(&wndclass
) )
339 wxLogLastError("RegisterClass(canvas)");
347 // ---------------------------------------------------------------------------
348 // Convert Windows to argc, argv style
349 // ---------------------------------------------------------------------------
351 void wxApp::ConvertToStandardCommandArgs(char* lpCmdLine
)
355 wxString
cmdLine(lpCmdLine
);
358 // Get application name
359 wxChar name
[260]; // 260 is MAX_PATH value from windef.h
360 ::GetModuleFileName(wxhInstance
, name
, WXSIZEOF(name
));
365 wxStrcpy(name
, wxFileNameFromPath(name
));
366 wxStripExtension(name
);
367 wxTheApp
->SetAppName(name
);
370 // Treat strings enclosed in double-quotes as single arguments
372 int len
= cmdLine
.Length();
376 while ((i
< len
) && wxIsspace(cmdLine
.GetChar(i
)))
381 if (cmdLine
.GetChar(i
) == _T('"')) // We found the start of a string
385 while ((i
< len
) && (cmdLine
.GetChar(i
) != _T('"')))
388 wxString
arg(cmdLine
.Mid(first
, (i
- first
)));
394 i
++; // Skip past 2nd quote
396 else // Unquoted argument
399 while ((i
< len
) && !wxIsspace(cmdLine
.GetChar(i
)))
402 wxString
arg(cmdLine
.Mid(first
, (i
- first
)));
410 wxTheApp
->argv
= new wxChar
*[count
+ 1];
411 for (i
= 0; i
< count
; i
++)
413 wxString
arg(args
[i
]);
414 wxTheApp
->argv
[i
] = copystring((const wxChar
*)arg
);
416 wxTheApp
->argv
[count
] = NULL
; // argv[] is a NULL-terminated list
417 wxTheApp
->argc
= count
;
420 //// Cleans up any wxWindows internal structures left lying around
422 void wxApp::CleanUp()
427 // flush the logged messages if any and install a 'safer' log target: the
428 // default one (wxLogGui) can't be used after the resources are freed just
429 // below and the user suppliedo ne might be even more unsafe (using any
430 // wxWindows GUI function is unsafe starting from now)
431 wxLog::DontCreateOnDemand();
433 // this will flush the old messages if any
434 delete wxLog::SetActiveTarget(new wxLogStderr
);
437 // One last chance for pending objects to be cleaned up
438 wxTheApp
->DeletePendingObjects();
440 wxModule::CleanUpModules();
442 #if wxUSE_WX_RESOURCES
443 wxCleanUpResourceSystem();
445 // wxDefaultResourceTable->ClearTable();
448 // Indicate that the cursor can be freed, so that cursor won't be deleted
449 // by deleting the bitmap list before g_globalCursor goes out of scope
450 // (double deletion of the cursor).
451 wxSetCursor(wxNullCursor
);
452 delete g_globalCursor
;
453 g_globalCursor
= NULL
;
455 wxDeleteStockObjects();
457 // Destroy all GDI lists, etc.
458 wxDeleteStockLists();
460 delete wxTheColourDatabase
;
461 wxTheColourDatabase
= NULL
;
463 wxBitmap::CleanUpHandlers();
468 //// WINDOWS-SPECIFIC CLEANUP
470 wxSetKeyboardHook(FALSE
);
475 if (gs_hRichEdit
!= (HINSTANCE
) NULL
)
476 FreeLibrary(gs_hRichEdit
);
485 if (wxSTD_FRAME_ICON
)
486 DestroyIcon(wxSTD_FRAME_ICON
);
487 if (wxSTD_MDICHILDFRAME_ICON
)
488 DestroyIcon(wxSTD_MDICHILDFRAME_ICON
);
489 if (wxSTD_MDIPARENTFRAME_ICON
)
490 DestroyIcon(wxSTD_MDIPARENTFRAME_ICON
);
492 if (wxDEFAULT_FRAME_ICON
)
493 DestroyIcon(wxDEFAULT_FRAME_ICON
);
494 if (wxDEFAULT_MDICHILDFRAME_ICON
)
495 DestroyIcon(wxDEFAULT_MDICHILDFRAME_ICON
);
496 if (wxDEFAULT_MDIPARENTFRAME_ICON
)
497 DestroyIcon(wxDEFAULT_MDIPARENTFRAME_ICON
);
499 if ( wxDisableButtonBrush
)
500 ::DeleteObject( wxDisableButtonBrush
);
507 Ctl3dUnregister(wxhInstance
);
511 delete wxWinHandleList
;
513 // GL: I'm annoyed ... I don't know where to put this and I don't want to
514 // create a module for that as it's part of the core.
516 delete wxPendingEvents
;
517 delete wxPendingEventsLocker
;
518 // If we don't do the following, we get an apparent memory leak.
519 ((wxEvtHandler
&) wxDefaultValidator
).ClearEventLocker();
522 wxClassInfo::CleanUpClasses();
527 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
528 // At this point we want to check if there are any memory
529 // blocks that aren't part of the wxDebugContext itself,
530 // as a special case. Then when dumping we need to ignore
531 // wxDebugContext, too.
532 if (wxDebugContext::CountObjectsLeft(TRUE
) > 0)
534 wxLogDebug(_T("There were memory leaks."));
535 wxDebugContext::Dump();
536 wxDebugContext::PrintStatistics();
538 // wxDebugContext::SetStream(NULL, NULL);
542 // do it as the very last thing because everything else can log messages
543 delete wxLog::SetActiveTarget(NULL
);
547 #if !defined(_WINDLL) || (defined(_WINDLL) && defined(WXMAKINGDLL))
549 // temporarily disable this warning which would be generated in release builds
552 #pragma warning(disable: 4715) // not all control paths return a value
555 //// Main wxWindows entry point
556 int wxEntry(WXHINSTANCE hInstance
,
557 WXHINSTANCE
WXUNUSED(hPrevInstance
),
562 // do check for memory leaks on program exit
563 // (another useful flag is _CRTDBG_DELAY_FREE_MEM_DF which doesn't free
564 // deallocated memory which may be used to simulate low-memory condition)
565 wxCrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF
);
567 // take everything into a try-except block in release build
568 // FIXME other compilers must support Win32 SEH (structured exception
569 // handling) too, just find the appropriate keyword in their docs!
570 // Please note that it's _not_ the same as C++ exceptions!
571 #if !defined(__WXDEBUG__) && defined(__VISUALC__)
572 #define CATCH_PROGRAM_EXCEPTIONS
576 #undef CATCH_PROGRAM_EXCEPTIONS
579 wxhInstance
= (HINSTANCE
) hInstance
;
581 if (!wxApp::Initialize())
584 // create the application object or ensure that one already exists
587 // The app may have declared a global application object, but we recommend
588 // the IMPLEMENT_APP macro is used instead, which sets an initializer
589 // function for delayed, dynamic app object construction.
590 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
591 _T("No initializer - use IMPLEMENT_APP macro.") );
593 wxTheApp
= (*wxApp::GetInitializerFunction()) ();
596 wxCHECK_MSG( wxTheApp
, 0, _T("You have to define an instance of wxApp!") );
598 // save the WinMain() parameters
599 wxTheApp
->ConvertToStandardCommandArgs(lpCmdLine
);
600 wxTheApp
->m_nCmdShow
= nCmdShow
;
602 // GUI-specific initialisation. In fact on Windows we don't have any,
603 // but this call is provided for compatibility across platforms.
604 wxTheApp
->OnInitGui();
608 if ( wxTheApp
->OnInit() )
612 retValue
= wxTheApp
->OnRun();
615 // We want to initialize, but not run or exit immediately.
618 //else: app initialization failed, so we skipped OnRun()
620 wxWindow
*topWindow
= wxTheApp
->GetTopWindow();
623 // Forcibly delete the window.
624 if ( topWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
625 topWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
627 topWindow
->Close(TRUE
);
628 wxTheApp
->DeletePendingObjects();
633 wxTheApp
->SetTopWindow(NULL
);
643 #ifdef CATCH_PROGRAM_EXCEPTIONS
645 __except ( EXCEPTION_EXECUTE_HANDLER
) {
648 wxTheApp->OnFatalException();
651 // using wxLog would be unsafe here
653 _("Unrecoverable program error detected: "
654 " the application will terminate."),
656 MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
658 ::ExitProcess(3); // the same exit code as abort()
662 #endif // CATCH_PROGRAM_EXCEPTIONS
665 // restore warning state
667 #pragma warning(default: 4715) // not all control paths return a value
672 //// Entry point for DLLs
674 int wxEntry(WXHINSTANCE hInstance
)
676 wxhInstance
= (HINSTANCE
) hInstance
;
679 // The app may have declared a global application object, but we recommend
680 // the IMPLEMENT_APP macro is used instead, which sets an initializer function
681 // for delayed, dynamic app object construction.
684 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
685 "No initializer - use IMPLEMENT_APP macro." );
687 wxTheApp
= (* wxApp::GetInitializerFunction()) ();
690 wxCHECK_MSG( wxTheApp
, 0, "You have to define an instance of wxApp!" );
693 wxTheApp
->argv
= NULL
;
695 wxTheApp
->OnInitGui();
699 wxWindow
*topWindow
= wxTheApp
->GetTopWindow();
700 if ( topWindow
&& topWindow
->GetHWND())
702 topWindow
->Show(TRUE
);
709 //// Static member initialization
711 wxAppInitializerFunction
wxAppBase::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
717 m_wantDebugOutput
= TRUE
;
721 m_printMode
= wxPRINT_WINDOWS
;
722 m_exitOnFrameDelete
= TRUE
;
728 // Delete command-line args
730 for (i
= 0; i
< argc
; i
++)
737 bool wxApp::Initialized()
745 #ifdef _WINDLL // Assume initialized if DLL (no way of telling)
751 * Get and process a message, returning FALSE if WM_QUIT
752 * received (and also set the flag telling the app to exit the main loop)
755 bool wxApp::DoMessage()
757 BOOL rc
= ::GetMessage(&s_currentMsg
, (HWND
) NULL
, 0, 0);
767 // should never happen, but let's test for it nevertheless
768 wxLogLastError("GetMessage");
773 wxASSERT_MSG( wxThread::IsMain(),
774 _T("only the main thread can process Windows messages") );
776 static bool s_hadGuiLock
= TRUE
;
777 static wxMsgArray s_aSavedMessages
;
779 // if a secondary thread owns is doing GUI calls, save all messages for
780 // later processing - we can't process them right now because it will
781 // lead to recursive library calls (and we're not reentrant)
782 if ( !wxGuiOwnedByMainThread() )
784 s_hadGuiLock
= FALSE
;
786 // leave out WM_COMMAND messages: too dangerous, sometimes
787 // the message will be processed twice
788 if ( !wxIsWaitingForThread() ||
789 s_currentMsg
.message
!= WM_COMMAND
)
791 s_aSavedMessages
.Add(s_currentMsg
);
798 // have we just regained the GUI lock? if so, post all of the saved
801 // FIXME of course, it's not _exactly_ the same as processing the
802 // messages normally - expect some things to break...
807 size_t count
= s_aSavedMessages
.Count();
808 for ( size_t n
= 0; n
< count
; n
++ )
810 MSG
& msg
= s_aSavedMessages
[n
];
812 if ( !ProcessMessage((WXMSG
*)&msg
) )
814 ::TranslateMessage(&msg
);
815 ::DispatchMessage(&msg
);
819 s_aSavedMessages
.Empty();
822 #endif // wxUSE_THREADS
824 // Process the message
825 if ( !ProcessMessage((WXMSG
*)&s_currentMsg
) )
827 ::TranslateMessage(&s_currentMsg
);
828 ::DispatchMessage(&s_currentMsg
);
836 * Keep trying to process messages until WM_QUIT
839 * If there are messages to be processed, they will all be
840 * processed and OnIdle will not be called.
841 * When there are no more messages, OnIdle is called.
842 * If OnIdle requests more time,
843 * it will be repeatedly called so long as there are no pending messages.
844 * A 'feature' of this is that once OnIdle has decided that no more processing
845 * is required, then it won't get processing time until further messages
846 * are processed (it'll sit in DoMessage).
849 int wxApp::MainLoop()
853 while ( m_keepGoing
)
856 wxMutexGuiLeaveOrEnter();
857 #endif // wxUSE_THREADS
859 while ( !::PeekMessage(&s_currentMsg
, 0, 0, 0, PM_NOREMOVE
) &&
868 return s_currentMsg
.wParam
;
871 // Returns TRUE if more time is needed.
872 bool wxApp::ProcessIdle()
875 event
.SetEventObject(this);
878 return event
.MoreRequested();
882 void wxApp::ProcessPendingEvents()
884 wxNode
*node
= wxPendingEvents
->First();
885 wxCriticalSectionLocker
locker(*wxPendingEventsLocker
);
889 wxEvtHandler
*handler
= (wxEvtHandler
*)node
->Data();
891 handler
->ProcessPendingEvents();
894 node
= wxPendingEvents
->First();
900 void wxApp::ExitMainLoop()
905 bool wxApp::Pending()
907 return (::PeekMessage(&s_currentMsg
, 0, 0, 0, PM_NOREMOVE
) != 0);
910 void wxApp::Dispatch()
916 * Give all windows a chance to preprocess
917 * the message. Some may have accelerator tables, or have
921 bool wxApp::ProcessMessage(WXMSG
*wxmsg
)
923 MSG
*msg
= (MSG
*)wxmsg
;
924 HWND hWnd
= msg
->hwnd
;
925 wxWindow
*wndThis
= wxFindWinFromHandle((WXHWND
)hWnd
), *wnd
;
927 // for some composite controls (like a combobox), wndThis might be NULL
928 // because the subcontrol is not a wxWindow, but only the control itself
929 // is - try to catch this case
930 while ( hWnd
&& !wndThis
)
932 hWnd
= ::GetParent(hWnd
);
933 wndThis
= wxFindWinFromHandle((WXHWND
)hWnd
);
936 // Try translations first; find the youngest window with
937 // a translation table.
938 for ( wnd
= wndThis
; wnd
; wnd
= wnd
->GetParent() )
940 if ( wnd
->MSWTranslateMessage(wxmsg
) )
944 // Anyone for a non-translation message? Try youngest descendants first.
945 for ( wnd
= wndThis
; wnd
; wnd
= wnd
->GetParent() )
947 if ( wnd
->MSWProcessMessage(wxmsg
) )
954 void wxApp::OnIdle(wxIdleEvent
& event
)
956 static bool s_inOnIdle
= FALSE
;
958 // Avoid recursion (via ProcessEvent default case)
964 // 'Garbage' collection of windows deleted with Close().
965 DeletePendingObjects();
968 // flush the logged messages if any
969 wxLog
*pLog
= wxLog::GetActiveTarget();
970 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
974 // Send OnIdle events to all windows
975 if ( SendIdleEvents() )
977 // SendIdleEvents() returns TRUE if at least one window requested more
979 event
.RequestMore(TRUE
);
982 // If they are pending events, we must process them.
984 ProcessPendingEvents();
989 // Send idle event to all top-level windows
990 bool wxApp::SendIdleEvents()
992 bool needMore
= FALSE
;
994 wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
997 wxWindow
* win
= node
->GetData();
998 if (SendIdleEvents(win
))
1000 node
= node
->GetNext();
1006 // Send idle event to window and all subwindows
1007 bool wxApp::SendIdleEvents(wxWindow
* win
)
1009 bool needMore
= FALSE
;
1012 event
.SetEventObject(win
);
1013 win
->GetEventHandler()->ProcessEvent(event
);
1015 if (event
.MoreRequested())
1018 wxNode
* node
= win
->GetChildren().First();
1021 wxWindow
* win
= (wxWindow
*) node
->Data();
1022 if (SendIdleEvents(win
))
1025 node
= node
->Next();
1030 void wxApp::DeletePendingObjects()
1032 wxNode
*node
= wxPendingDelete
.First();
1035 wxObject
*obj
= (wxObject
*)node
->Data();
1039 if (wxPendingDelete
.Member(obj
))
1042 // Deleting one object may have deleted other pending
1043 // objects, so start from beginning of list again.
1044 node
= wxPendingDelete
.First();
1048 void wxApp::OnEndSession(wxCloseEvent
& WXUNUSED(event
))
1051 GetTopWindow()->Close(TRUE
);
1054 // Default behaviour: close the application with prompts. The
1055 // user can veto the close, and therefore the end session.
1056 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
1060 if (!GetTopWindow()->Close(!event
.CanVeto()))
1065 int wxApp::GetComCtl32Version() const
1067 // have we loaded COMCTL32 yet?
1068 HMODULE theModule
= ::GetModuleHandle(_T("COMCTL32"));
1071 // if so, then we can check for the version
1074 // InitCommonControlsEx is unique to 4.7 and later
1075 FARPROC theProc
= ::GetProcAddress(theModule
, "InitCommonControlsEx");
1078 { // not found, must be 4.00
1083 // The following symbol are unique to 4.71
1085 // FlatSB_EnableScrollBar FlatSB_GetScrollInfo FlatSB_GetScrollPos
1086 // FlatSB_GetScrollProp FlatSB_GetScrollRange FlatSB_SetScrollInfo
1087 // FlatSB_SetScrollPos FlatSB_SetScrollProp FlatSB_SetScrollRange
1088 // FlatSB_ShowScrollBar
1089 // _DrawIndirectImageList _DuplicateImageList
1091 // UninitializeFlatSB
1092 // we could check for any of these - I chose DllInstall
1093 FARPROC theProc
= ::GetProcAddress(theModule
, "DllInstall");
1096 // not found, must be 4.70
1100 { // found, must be 4.71
1110 wxLogError(_("Fatal error: exiting"));
1115 // Yield to incoming messages
1119 // We want to go back to the main message loop
1120 // if we see a WM_QUIT. (?)
1122 while (PeekMessage(&msg
, (HWND
)NULL
, 0, 0, PM_NOREMOVE
) && msg
.message
!= WM_QUIT
)
1124 while (PeekMessage(&msg
, NULL
, 0, 0, PM_NOREMOVE
) && msg
.message
!= WM_QUIT
)
1127 if ( !wxTheApp
->DoMessage() )
1130 // If they are pending events, we must process them.
1132 wxTheApp
->ProcessPendingEvents();
1139 wxApp::GetStdIcon(int which
) const
1143 case wxICON_INFORMATION
:
1144 return wxIcon("wxICON_INFO");
1146 case wxICON_QUESTION
:
1147 return wxIcon("wxICON_QUESTION");
1149 case wxICON_EXCLAMATION
:
1150 return wxIcon("wxICON_WARNING");
1153 wxFAIL_MSG(_T("requested non existent standard icon"));
1154 // still fall through
1157 return wxIcon("wxICON_ERROR");
1162 HINSTANCE
wxGetInstance()
1167 void wxSetInstance(HINSTANCE hInst
)
1169 wxhInstance
= hInst
;
1172 // For some reason, with MSVC++ 1.5, WinMain isn't linked in properly
1173 // if in a separate file. So include it here to ensure it's linked.
1174 #if (defined(__VISUALC__) && !defined(__WIN32__)) || (defined(__GNUWIN32__) && !defined(__TWIN32__))