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"
39 #include "wx/postscrp.h"
41 #include "wx/module.h"
44 #include "wx/resource.h"
50 #if defined(__WIN95__) && !defined(__GNUWIN32__)
54 // use debug CRT functions for memory leak detections in VC++
55 /* Doesn't work when using the makefiles, for some reason.
56 #if defined(__WXDEBUG__) && defined(_MSC_VER)
61 extern char *wxBuffer
;
62 extern char *wxOsVersion
;
63 extern wxList
*wxWinHandleList
;
64 extern wxList wxPendingDelete
;
65 extern void wxSetKeyboardHook(bool doIt
);
66 extern wxCursor
*g_globalCursor
;
68 HINSTANCE wxhInstance
= 0;
69 static MSG s_currentMsg
;
70 wxApp
*wxTheApp
= NULL
;
72 char wxFrameClassName
[] = "wxFrameClass";
73 char wxMDIFrameClassName
[] = "wxMDIFrameClass";
74 char wxMDIChildFrameClassName
[] = "wxMDIChildFrameClass";
75 char wxPanelClassName
[] = "wxPanelClass";
76 char wxCanvasClassName
[] = "wxCanvasClass";
78 HICON wxSTD_FRAME_ICON
= NULL
;
79 HICON wxSTD_MDICHILDFRAME_ICON
= NULL
;
80 HICON wxSTD_MDIPARENTFRAME_ICON
= NULL
;
82 HICON wxDEFAULT_FRAME_ICON
= NULL
;
83 HICON wxDEFAULT_MDICHILDFRAME_ICON
= NULL
;
84 HICON wxDEFAULT_MDIPARENTFRAME_ICON
= NULL
;
86 HBRUSH wxDisableButtonBrush
= 0;
88 LRESULT APIENTRY
wxWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
90 #if !USE_SHARED_LIBRARY
91 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
92 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
93 EVT_IDLE(wxApp::OnIdle
)
97 long wxApp::sm_lastMessageTime
= 0;
100 static HINSTANCE gs_hRichEdit
= NULL
;
105 bool wxApp::Initialize()
107 wxBuffer
= new char[1500];
109 /* Doesn't work when using the makefiles, for some reason.
110 #if defined(__WXDEBUG__) && defined(_MSC_VER)
111 // do check for memory leaks on program exit
112 // (another useful flag is _CRTDBG_DELAY_FREE_MEM_DF which doesn't free
113 // deallocated memory which may be used to simulate low-memory condition)
114 _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);
115 #endif // debug build under MS VC++
118 #if (WXDEBUG && USE_MEMORY_TRACING) || USE_DEBUG_CONTEXT
120 #if !defined(_WINDLL)
121 streambuf
* sBuf
= new wxDebugStreamBuf
;
123 streambuf
* sBuf
= NULL
;
125 ostream
* oStr
= new ostream(sBuf
) ;
126 wxDebugContext::SetStream(oStr
, sBuf
);
128 #endif // USE_MEMORY_TRACING
130 wxClassInfo::InitializeClasses();
133 wxGetResource("wxWindows", "OsVersion", &wxOsVersion
);
136 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
137 wxTheColourDatabase
->Initialize();
139 wxInitializeStockLists();
140 wxInitializeStockObjects();
143 wxInitializeResourceSystem();
146 // For PostScript printing
148 wxInitializePrintSetupData();
149 wxThePrintPaperDatabase
= new wxPrintPaperDatabase
;
150 wxThePrintPaperDatabase
->CreateDatabase();
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
++;
210 wxSetKeyboardHook(TRUE
);
212 wxModule::RegisterModules();
213 if (!wxModule::InitializeModules())
218 //// RegisterWindowClasses
220 bool wxApp::RegisterWindowClasses()
222 ///////////////////////////////////////////////////////////////////////
223 // Register the frame window class.
224 WNDCLASS wndclass
; // Structure used to register Windows class.
226 wndclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
227 wndclass
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
228 wndclass
.cbClsExtra
= 0;
229 wndclass
.cbWndExtra
= sizeof( DWORD
); // was 4
230 wndclass
.hInstance
= wxhInstance
;
231 wndclass
.hIcon
= NULL
; // wxSTD_FRAME_ICON;
232 wndclass
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
233 wndclass
.hbrBackground
= (HBRUSH
)(COLOR_APPWORKSPACE
+1) ;
234 // wndclass.hbrBackground = GetStockObject( WHITE_BRUSH );
235 wndclass
.lpszMenuName
= NULL
;
236 #ifdef _MULTIPLE_INSTANCES
237 sprintf( wxFrameClassName
,"wxFrameClass%d", wxhInstance
);
239 wndclass
.lpszClassName
= wxFrameClassName
;
241 if (!RegisterClass( &wndclass
))
243 // wxFatalError("Can't register Frame Window class");
246 ///////////////////////////////////////////////////////////////////////
247 // Register the MDI frame window class.
248 WNDCLASS wndclass1
; // Structure used to register Windows class.
250 wndclass1
.style
= CS_HREDRAW
| CS_VREDRAW
;
251 wndclass1
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
252 wndclass1
.cbClsExtra
= 0;
253 wndclass1
.cbWndExtra
= sizeof( DWORD
); // was 4
254 wndclass1
.hInstance
= wxhInstance
;
255 wndclass1
.hIcon
= NULL
; // wxSTD_MDIPARENTFRAME_ICON;
256 wndclass1
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
257 // wndclass1.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1) ;
258 wndclass1
.hbrBackground
= NULL
;
259 wndclass1
.lpszMenuName
= NULL
;
261 wndclass1
.lpszClassName
= wxMDIFrameClassName
;
262 if (!RegisterClass( &wndclass1
))
264 // wxFatalError("Can't register MDI Frame window class");
268 ///////////////////////////////////////////////////////////////////////
269 // Register the MDI child frame window class.
270 WNDCLASS wndclass4
; // Structure used to register Windows class.
272 wndclass4
.style
= CS_HREDRAW
| CS_VREDRAW
;
273 wndclass4
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
274 wndclass4
.cbClsExtra
= 0;
275 wndclass4
.cbWndExtra
= sizeof( DWORD
); // was 4
276 wndclass4
.hInstance
= wxhInstance
;
277 wndclass4
.hIcon
= NULL
; // wxSTD_MDICHILDFRAME_ICON;
278 wndclass4
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
279 // TODO: perhaps this should be NULL so that Windows doesn't
280 // paint the background itself (would OnEraseBackground duplicate
282 wndclass4
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1) ;
283 // wndclass4.hbrBackground = NULL;
284 wndclass4
.lpszMenuName
= NULL
;
285 wndclass4
.lpszClassName
= wxMDIChildFrameClassName
;
287 if (!RegisterClass( &wndclass4
))
289 // wxFatalError("Can't register MDI child frame window class");
293 ///////////////////////////////////////////////////////////////////////
294 // Register the panel window class.
295 WNDCLASS wndclass2
; // Structure used to register Windows class.
296 memset(&wndclass2
, 0, sizeof(WNDCLASS
)); // start with NULL defaults
297 // Use CS_OWNDC to avoid messing about restoring the context
298 // for every graphic operation.
299 wndclass2
.style
= CS_HREDRAW
| CS_VREDRAW
;
300 wndclass2
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
301 wndclass2
.cbClsExtra
= 0;
302 wndclass2
.cbWndExtra
= sizeof( DWORD
); // was 4
303 wndclass2
.hInstance
= wxhInstance
;
304 wndclass2
.hIcon
= NULL
;
305 wndclass2
.hCursor
= NULL
;
306 // wndclass2.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1) ;
307 wndclass2
.hbrBackground
= (HBRUSH
) GetStockObject( LTGRAY_BRUSH
);
308 wndclass2
.lpszMenuName
= NULL
;
309 wndclass2
.lpszClassName
= wxPanelClassName
;
310 if (!RegisterClass( &wndclass2
))
312 // wxFatalError("Can't register Panel Window class");
316 ///////////////////////////////////////////////////////////////////////
317 // Register the canvas and textsubwindow class name
318 WNDCLASS wndclass3
; // Structure used to register Windows class.
319 memset(&wndclass3
, 0, sizeof(WNDCLASS
)); // start with NULL defaults
320 // Use CS_OWNDC to avoid messing about restoring the context
321 // for every graphic operation.
322 // wndclass3.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS ;
324 wndclass3
.style
= CS_HREDRAW
| CS_VREDRAW
| CS_DBLCLKS
;
325 wndclass3
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
326 wndclass3
.cbClsExtra
= 0;
327 wndclass3
.cbWndExtra
= sizeof( DWORD
); // was 4
328 wndclass3
.hInstance
= wxhInstance
;
329 wndclass3
.hIcon
= NULL
;
330 wndclass3
.hCursor
= NULL
;
331 // wndclass3.hbrBackground = (HBRUSH)(COLOR_WINDOW+1) ;
332 wndclass3
.hbrBackground
= NULL
;
333 wndclass3
.lpszMenuName
= NULL
;
334 wndclass3
.lpszClassName
= wxCanvasClassName
;
335 if (!RegisterClass( &wndclass3
))
337 // wxFatalError("Can't register Canvas class");
344 //// Convert Windows to argc, argv style
346 void wxApp::ConvertToStandardCommandArgs(char* lpCmdLine
)
348 // Split command line into tokens, as in usual main(argc, argv)
349 char **command
= new char*[50];
352 char *buf
= new char[strlen(lpCmdLine
) + 1];
354 // Hangs around until end of app. in case
355 // user carries pointers to the tokens
357 /* Model independent strcpy */
359 for (i
= 0; (buf
[i
] = lpCmdLine
[i
]) != 0; i
++)
364 // Get application name
366 ::GetModuleFileName(wxhInstance
, name
, 199);
368 // Is it only 16-bit Borland that already copies the program name
369 // to the first argv index?
370 #if !defined(__GNUWIN32__)
371 // #if ! (defined(__BORLANDC__) && !defined(__WIN32__))
372 command
[count
++] = copystring(name
);
376 strcpy(name
, wxFileNameFromPath(name
));
377 wxStripExtension(name
);
378 wxTheApp
->SetAppName(name
);
380 /* Break up string */
381 // Treat strings enclosed in double-quotes as single arguments
385 while (*str
&& *str
<= ' ') str
++; // skip whitespace
389 command
[count
++] = str
;
390 while (*str
&& *str
!= '"') str
++;
394 command
[count
++] = str
;
395 while (*str
&& *str
> ' ') str
++;
397 if (*str
) *str
++ = '\0';
400 wxTheApp
->argv
= new char*[argc
+1];
401 wxTheApp
->argv
[count
] = NULL
; /* argv[] is NULL terminated list! */
402 wxTheApp
->argc
= count
;
404 for (i
= 0; i
< count
; i
++)
406 wxTheApp
->argv
[i
] = copystring(command
[i
]);
411 //// Cleans up any wxWindows internal structures left lying around
413 void wxApp::CleanUp()
416 wxModule::CleanUpModules();
419 wxCleanUpResourceSystem();
421 // wxDefaultResourceTable->ClearTable();
424 // Indicate that the cursor can be freed,
425 // so that cursor won't be deleted by deleting
426 // the bitmap list before g_globalCursor goes out
427 // of scope (double deletion of the cursor).
428 wxSetCursor(wxNullCursor
);
429 delete g_globalCursor
;
431 wxDeleteStockObjects() ;
433 // Destroy all GDI lists, etc.
434 wxDeleteStockLists();
436 delete wxTheColourDatabase
;
437 wxTheColourDatabase
= NULL
;
440 wxInitializePrintSetupData(FALSE
);
441 delete wxThePrintPaperDatabase
;
442 wxThePrintPaperDatabase
= NULL
;
445 wxBitmap::CleanUpHandlers();
450 //// WINDOWS-SPECIFIC CLEANUP
452 wxSetKeyboardHook(FALSE
);
455 if (gs_hRichEdit
!= NULL
)
456 FreeLibrary(gs_hRichEdit
);
463 if (wxSTD_FRAME_ICON
)
464 DestroyIcon(wxSTD_FRAME_ICON
);
465 if (wxSTD_MDICHILDFRAME_ICON
)
466 DestroyIcon(wxSTD_MDICHILDFRAME_ICON
);
467 if (wxSTD_MDIPARENTFRAME_ICON
)
468 DestroyIcon(wxSTD_MDIPARENTFRAME_ICON
);
470 if (wxDEFAULT_FRAME_ICON
)
471 DestroyIcon(wxDEFAULT_FRAME_ICON
);
472 if (wxDEFAULT_MDICHILDFRAME_ICON
)
473 DestroyIcon(wxDEFAULT_MDICHILDFRAME_ICON
);
474 if (wxDEFAULT_MDIPARENTFRAME_ICON
)
475 DestroyIcon(wxDEFAULT_MDIPARENTFRAME_ICON
);
477 if ( wxDisableButtonBrush
)
478 ::DeleteObject( wxDisableButtonBrush
) ;
480 #if defined(WX_DRAG_DROP)
485 Ctl3dUnregister(wxhInstance
);
489 delete wxWinHandleList
;
491 wxClassInfo::CleanUpClasses();
493 // do it as the very last thing because everything else can log messages
494 wxLog::DontCreateOnDemand();
495 delete wxLog::SetActiveTarget(NULL
);
498 #if !defined(_WINDLL) || (defined(_WINDLL) && defined(WXMAKINGDLL))
500 //// Main wxWindows entry point
502 int wxEntry(WXHINSTANCE hInstance
, WXHINSTANCE
WXUNUSED(hPrevInstance
), char *lpCmdLine
,
503 int nCmdShow
, bool enterLoop
)
505 wxhInstance
= (HINSTANCE
) hInstance
;
507 if (!wxApp::Initialize())
510 // The app may have declared a global application object, but we recommend
511 // the IMPLEMENT_APP macro is used instead, which sets an initializer function
512 // for delayed, dynamic app object construction.
515 if (!wxApp::GetInitializerFunction())
517 MessageBox(NULL
, "No initializer - use IMPLEMENT_APP macro.", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
521 wxTheApp
= (* wxApp::GetInitializerFunction()) ();
525 MessageBox(NULL
, "You have to define an instance of wxApp!", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
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() ;
536 if (!wxTheApp
->OnInit())
538 wxTheApp
->DeletePendingObjects();
553 /* New behaviour - leave it to the app to show the top window
554 if (wxTheApp->GetTopWindow()) {
555 // show the toplevel frame, only if we are not iconized (from MS-Windows)
556 if(wxTheApp->GetShowFrameOnInit() && (nCmdShow!=SW_HIDE)) wxTheApp->GetTopWindow()->Show(TRUE);
560 retValue
= wxTheApp
->OnRun();
562 if (wxTheApp
->GetTopWindow())
564 // Forcibly delete the window.
565 if (wxTheApp
->GetTopWindow()->IsKindOf(CLASSINFO(wxFrame
)) ||
566 wxTheApp
->GetTopWindow()->IsKindOf(CLASSINFO(wxDialog
)))
568 wxTheApp
->GetTopWindow()->Close(TRUE
);
569 wxTheApp
->DeletePendingObjects();
573 delete wxTheApp
->GetTopWindow();
574 wxTheApp
->SetTopWindow(NULL
);
584 #if (WXDEBUG && USE_MEMORY_TRACING) || USE_DEBUG_CONTEXT
585 // At this point we want to check if there are any memory
586 // blocks that aren't part of the wxDebugContext itself,
587 // as a special case. Then when dumping we need to ignore
588 // wxDebugContext, too.
589 if (wxDebugContext::CountObjectsLeft() > 0)
591 wxTrace("There were memory leaks.\n");
592 wxDebugContext::Dump();
593 wxDebugContext::PrintStatistics();
595 wxDebugContext::SetStream(NULL
, NULL
);
603 //// Entry point for DLLs
605 int wxEntry(WXHINSTANCE hInstance
)
607 wxhInstance
= (HINSTANCE
) hInstance
;
610 // The app may have declared a global application object, but we recommend
611 // the IMPLEMENT_APP macro is used instead, which sets an initializer function
612 // for delayed, dynamic app object construction.
616 if (!wxApp::GetInitializerFunction())
618 MessageBox(NULL
, "No initializer - use IMPLEMENT_APP macro.", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
622 wxTheApp
= (* wxApp::GetInitializerFunction()) ();
626 MessageBox(NULL
, "You have to define an instance of wxApp!", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
631 wxTheApp
->argv
= NULL
;
633 wxTheApp
->OnInitGui();
637 if (wxTheApp
->GetTopWindow() && wxTheApp
->GetTopWindow()->GetHWND()) {
638 wxTheApp
->GetTopWindow()->Show(TRUE
);
645 //// Static member initialization
647 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
654 m_wantDebugOutput
= TRUE
;
659 m_printMode
= wxPRINT_WINDOWS
;
661 m_printMode
= wxPRINT_POSTSCRIPT
;
663 m_exitOnFrameDelete
= TRUE
;
669 // Delete command-line args
671 for (i
= 0; i
< argc
; i
++)
678 bool wxApp::Initialized()
686 #ifdef _WINDLL // Assume initialized if DLL (no way of telling)
692 * Get and process a message, returning FALSE if WM_QUIT
696 bool wxApp::DoMessage()
698 if (!::GetMessage(&s_currentMsg
, (HWND
) NULL
, 0, 0))
703 // Process the message
704 if (!ProcessMessage((WXMSG
*)&s_currentMsg
))
706 ::TranslateMessage(&s_currentMsg
);
707 wxApp::sm_lastMessageTime
= s_currentMsg
.time
; /* MATTHEW: timeStamp impl. */
708 ::DispatchMessage(&s_currentMsg
);
714 * Keep trying to process messages until WM_QUIT
717 * If there are messages to be processed, they will all be
718 * processed and OnIdle will not be called.
719 * When there are no more messages, OnIdle is called.
720 * If OnIdle requests more time,
721 * it will be repeatedly called so long as there are no pending messages.
722 * A 'feature' of this is that once OnIdle has decided that no more processing
723 * is required, then it won't get processing time until further messages
724 * are processed (it'll sit in DoMessage).
727 int wxApp::MainLoop()
732 while (!::PeekMessage(&s_currentMsg
, 0, 0, 0, PM_NOREMOVE
) &&
738 return s_currentMsg
.wParam
;
741 // Returns TRUE if more time is needed.
742 bool wxApp::ProcessIdle()
745 event
.SetEventObject(this);
748 return event
.MoreRequested();
751 void wxApp::ExitMainLoop()
756 bool wxApp::Pending()
758 return (::PeekMessage(&s_currentMsg
, 0, 0, 0, PM_NOREMOVE
) != 0) ;
761 void wxApp::Dispatch()
768 * Give all windows a chance to preprocess
769 * the message. Some may have accelerator tables, or have
772 bool wxApp::ProcessMessage(WXMSG
*Msg
)
774 MSG
*msg
= (MSG
*)Msg
;
778 // Try translations first; find the youngest window with
779 // a translation table.
780 for (hWnd
= msg
->hwnd
; hWnd
!= NULL
; hWnd
= ::GetParent(hWnd
))
782 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
785 if (wnd
->MSWTranslateMessage(Msg
))
790 // Anyone for a non-translation message? Try youngest descendants first.
791 for (hWnd
= msg
->hwnd
; hWnd
!= NULL
; hWnd
= ::GetParent(hWnd
))
793 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
796 if (wnd
->MSWProcessMessage(Msg
))
803 void wxApp::OnIdle(wxIdleEvent
& event
)
805 static bool inOnIdle
= FALSE
;
807 // Avoid recursion (via ProcessEvent default case)
813 // 'Garbage' collection of windows deleted with Close().
814 DeletePendingObjects();
816 // flush the logged messages if any
817 wxLog
*pLog
= wxLog::GetActiveTarget();
818 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
821 // Send OnIdle events to all windows
822 bool needMore
= SendIdleEvents();
823 // bool needMore = FALSE;
826 event
.RequestMore(TRUE
);
831 // Send idle event to all top-level windows
832 bool wxApp::SendIdleEvents()
834 bool needMore
= FALSE
;
835 wxNode
* node
= wxTopLevelWindows
.First();
838 wxWindow
* win
= (wxWindow
*) node
->Data();
839 if (SendIdleEvents(win
))
847 // Send idle event to window and all subwindows
848 bool wxApp::SendIdleEvents(wxWindow
* win
)
850 bool needMore
= FALSE
;
853 event
.SetEventObject(win
);
854 win
->ProcessEvent(event
);
856 if (event
.MoreRequested())
859 wxNode
* node
= win
->GetChildren()->First();
862 wxWindow
* win
= (wxWindow
*) node
->Data();
863 if (SendIdleEvents(win
))
871 void wxApp::DeletePendingObjects()
873 wxNode
*node
= wxPendingDelete
.First();
876 wxObject
*obj
= (wxObject
*)node
->Data();
880 if (wxPendingDelete
.Member(obj
))
883 // Deleting one object may have deleted other pending
884 // objects, so start from beginning of list again.
885 node
= wxPendingDelete
.First();
889 wxLog
* wxApp::CreateLogTarget()
894 wxWindow
* wxApp::GetTopWindow() const
898 else if (wxTopLevelWindows
.Number() > 0)
899 return (wxWindow
*) wxTopLevelWindows
.First()->Data();
904 int wxApp::GetComCtl32Version() const
906 // have we loaded COMCTL32 yet?
907 HMODULE theModule
= ::GetModuleHandle("COMCTL32");
910 // if so, then we can check for the version
913 // InitCommonControlsEx is unique to 4.7 and later
914 FARPROC theProc
= ::GetProcAddress(theModule
, "InitCommonControlsEx");
917 { // not found, must be 4.00
922 // The following symbol are unique to 4.71
924 // FlatSB_EnableScrollBar FlatSB_GetScrollInfo FlatSB_GetScrollPos
925 // FlatSB_GetScrollProp FlatSB_GetScrollRange FlatSB_SetScrollInfo
926 // FlatSB_SetScrollPos FlatSB_SetScrollProp FlatSB_SetScrollRange
927 // FlatSB_ShowScrollBar
928 // _DrawIndirectImageList _DuplicateImageList
930 // UninitializeFlatSB
931 // we could check for any of these - I chose DllInstall
932 FARPROC theProc
= ::GetProcAddress(theModule
, "DllInstall");
935 // not found, must be 4.70
939 { // found, must be 4.71
950 FatalAppExit(0, "Fatal error: exiting");
953 // Yield to incoming messages
957 // We want to go back to the main message loop
958 // if we see a WM_QUIT. (?)
959 while (PeekMessage(&msg
, NULL
, 0, 0, PM_NOREMOVE
) && msg
.message
!= WM_QUIT
)
961 if (!wxTheApp
->DoMessage())
968 HINSTANCE
wxGetInstance()
973 // For some reason, with MSVC++ 1.5, WinMain isn't linked in properly
974 // if in a separate file. So include it here to ensure it's linked.
975 #if (defined(_MSC_VER) && !defined(__WIN32__)) || defined(__GNUWIN32__)