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 #define IN_WX_MAIN_CPP
18 #include "wx/wxprec.h"
20 #if defined(__BORLANDC__)
28 #include "wx/gdicmn.h"
31 #include "wx/cursor.h"
33 #include "wx/palette.h"
35 #include "wx/dialog.h"
36 #include "wx/msgdlg.h"
39 #include "wx/msw/private.h"
40 #include "wx/postscrp.h"
42 #include "wx/module.h"
45 #include "wx/resource.h"
51 #if defined(__WIN95__) && !defined(__GNUWIN32__)
55 // use debug CRT functions for memory leak detections in VC++
56 #if defined(__WXDEBUG__) && defined(_MSC_VER)
60 extern char *wxBuffer
;
61 extern char *wxOsVersion
;
62 extern wxList
*wxWinHandleList
;
63 extern wxList wxPendingDelete
;
64 extern void wxSetKeyboardHook(bool doIt
);
65 extern wxCursor
*g_globalCursor
;
67 HINSTANCE wxhInstance
= 0;
68 static MSG s_currentMsg
;
69 wxApp
*wxTheApp
= NULL
;
71 char wxFrameClassName
[] = "wxFrameClass";
72 char wxMDIFrameClassName
[] = "wxMDIFrameClass";
73 char wxMDIChildFrameClassName
[] = "wxMDIChildFrameClass";
74 char wxPanelClassName
[] = "wxPanelClass";
75 char wxCanvasClassName
[] = "wxCanvasClass";
77 HICON wxSTD_FRAME_ICON
= NULL
;
78 HICON wxSTD_MDICHILDFRAME_ICON
= NULL
;
79 HICON wxSTD_MDIPARENTFRAME_ICON
= NULL
;
81 HICON wxDEFAULT_FRAME_ICON
= NULL
;
82 HICON wxDEFAULT_MDICHILDFRAME_ICON
= NULL
;
83 HICON wxDEFAULT_MDIPARENTFRAME_ICON
= NULL
;
85 HBRUSH wxDisableButtonBrush
= 0;
87 LRESULT APIENTRY
wxWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
89 #if !USE_SHARED_LIBRARY
90 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
91 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
92 EVT_IDLE(wxApp::OnIdle
)
96 long wxApp::sm_lastMessageTime
= 0;
99 static HINSTANCE gs_hRichEdit
= NULL
;
102 bool wxApp::Initialize(WXHINSTANCE instance
)
104 HINSTANCE hInstance
= (HINSTANCE
) instance
;
108 #if defined(__WIN95__)
109 InitCommonControls();
110 gs_hRichEdit
= LoadLibrary("RICHED32.DLL");
112 if (gs_hRichEdit
== NULL
)
114 wxMessageBox("Could not initialise Rich Edit DLL");
118 #if defined(WX_DRAG_DROP)
119 // we need to initialize OLE library
120 if ( FAILED(::OleInitialize(NULL
)) )
121 wxFatalError(_("Cannot initialize OLE"));
125 if (!Ctl3dRegister(hInstance
))
126 wxFatalError("Cannot register CTL3D");
128 Ctl3dAutoSubclass(hInstance
);
131 wxSTD_FRAME_ICON
= LoadIcon(hInstance
, "wxSTD_FRAME");
132 wxSTD_MDIPARENTFRAME_ICON
= LoadIcon(hInstance
, "wxSTD_MDIPARENTFRAME");
133 wxSTD_MDICHILDFRAME_ICON
= LoadIcon(hInstance
, "wxSTD_MDICHILDFRAME");
135 wxDEFAULT_FRAME_ICON
= LoadIcon(hInstance
, "wxDEFAULT_FRAME");
136 wxDEFAULT_MDIPARENTFRAME_ICON
= LoadIcon(hInstance
, "wxDEFAULT_MDIPARENTFRAME");
137 wxDEFAULT_MDICHILDFRAME_ICON
= LoadIcon(hInstance
, "wxDEFAULT_MDICHILDFRAME");
139 RegisterWindowClasses();
141 // Create the brush for disabling bitmap buttons
144 lb
.lbStyle
= BS_PATTERN
;
145 lb
.lbHatch
= (int)LoadBitmap( hInstance
, "wxDISABLE_BUTTON_BITMAP" ) ;
146 wxDisableButtonBrush
= ::CreateBrushIndirect( & lb
) ;
147 ::DeleteObject( (HGDIOBJ
)lb
.lbHatch
) ;
153 wxWinHandleList
= new wxList(wxKEY_INTEGER
);
155 // This is to foil optimizations in Visual C++ that
156 // throw out dummy.obj.
157 #if (_MSC_VER >= 800) && !defined(WXMAKINGDLL)
158 extern char wxDummyChar
;
159 if (wxDummyChar
) wxDummyChar
++;
161 wxSetKeyboardHook(TRUE
);
163 wxModule::RegisterModules();
164 if (!wxModule::InitializeModules())
169 bool wxApp::RegisterWindowClasses()
171 ///////////////////////////////////////////////////////////////////////
172 // Register the frame window class.
173 WNDCLASS wndclass
; // Structure used to register Windows class.
175 wndclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
176 wndclass
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
177 wndclass
.cbClsExtra
= 0;
178 wndclass
.cbWndExtra
= sizeof( DWORD
); // was 4
179 wndclass
.hInstance
= wxhInstance
;
180 wndclass
.hIcon
= NULL
; // wxSTD_FRAME_ICON;
181 wndclass
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
182 wndclass
.hbrBackground
= (HBRUSH
)(COLOR_APPWORKSPACE
+1) ;
183 // wndclass.hbrBackground = GetStockObject( WHITE_BRUSH );
184 wndclass
.lpszMenuName
= NULL
;
185 #ifdef _MULTIPLE_INSTANCES
186 sprintf( wxFrameClassName
,"wxFrameClass%d", hInstance
);
188 wndclass
.lpszClassName
= wxFrameClassName
;
190 if (!RegisterClass( &wndclass
))
192 // wxFatalError("Can't register Frame Window class");
195 ///////////////////////////////////////////////////////////////////////
196 // Register the MDI frame window class.
197 WNDCLASS wndclass1
; // Structure used to register Windows class.
199 wndclass1
.style
= CS_HREDRAW
| CS_VREDRAW
;
200 wndclass1
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
201 wndclass1
.cbClsExtra
= 0;
202 wndclass1
.cbWndExtra
= sizeof( DWORD
); // was 4
203 wndclass1
.hInstance
= wxhInstance
;
204 wndclass1
.hIcon
= NULL
; // wxSTD_MDIPARENTFRAME_ICON;
205 wndclass1
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
206 // wndclass1.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1) ;
207 wndclass1
.hbrBackground
= NULL
;
208 wndclass1
.lpszMenuName
= NULL
;
210 wndclass1
.lpszClassName
= wxMDIFrameClassName
;
211 if (!RegisterClass( &wndclass1
))
213 // wxFatalError("Can't register MDI Frame window class");
217 ///////////////////////////////////////////////////////////////////////
218 // Register the MDI child frame window class.
219 WNDCLASS wndclass4
; // Structure used to register Windows class.
221 wndclass4
.style
= CS_HREDRAW
| CS_VREDRAW
;
222 wndclass4
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
223 wndclass4
.cbClsExtra
= 0;
224 wndclass4
.cbWndExtra
= sizeof( DWORD
); // was 4
225 wndclass4
.hInstance
= wxhInstance
;
226 wndclass4
.hIcon
= NULL
; // wxSTD_MDICHILDFRAME_ICON;
227 wndclass4
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
228 // TODO: perhaps this should be NULL so that Windows doesn't
229 // paint the background itself (would OnEraseBackground duplicate
231 wndclass4
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1) ;
232 // wndclass4.hbrBackground = NULL;
233 wndclass4
.lpszMenuName
= NULL
;
234 wndclass4
.lpszClassName
= wxMDIChildFrameClassName
;
236 if (!RegisterClass( &wndclass4
))
238 // wxFatalError("Can't register MDI child frame window class");
242 ///////////////////////////////////////////////////////////////////////
243 // Register the panel window class.
244 WNDCLASS wndclass2
; // Structure used to register Windows class.
245 memset(&wndclass2
, 0, sizeof(WNDCLASS
)); // start with NULL defaults
246 // Use CS_OWNDC to avoid messing about restoring the context
247 // for every graphic operation.
248 wndclass2
.style
= CS_HREDRAW
| CS_VREDRAW
;
249 wndclass2
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
250 wndclass2
.cbClsExtra
= 0;
251 wndclass2
.cbWndExtra
= sizeof( DWORD
); // was 4
252 wndclass2
.hInstance
= wxhInstance
;
253 wndclass2
.hIcon
= NULL
;
254 wndclass2
.hCursor
= NULL
;
255 // wndclass2.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1) ;
256 wndclass2
.hbrBackground
= (HBRUSH
) GetStockObject( LTGRAY_BRUSH
);
257 wndclass2
.lpszMenuName
= NULL
;
258 wndclass2
.lpszClassName
= wxPanelClassName
;
259 if (!RegisterClass( &wndclass2
))
261 // wxFatalError("Can't register Panel Window class");
265 ///////////////////////////////////////////////////////////////////////
266 // Register the canvas and textsubwindow class name
267 WNDCLASS wndclass3
; // Structure used to register Windows class.
268 memset(&wndclass3
, 0, sizeof(WNDCLASS
)); // start with NULL defaults
269 // Use CS_OWNDC to avoid messing about restoring the context
270 // for every graphic operation.
271 // wndclass3.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS ;
273 wndclass3
.style
= CS_HREDRAW
| CS_VREDRAW
| CS_DBLCLKS
;
274 wndclass3
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
275 wndclass3
.cbClsExtra
= 0;
276 wndclass3
.cbWndExtra
= sizeof( DWORD
); // was 4
277 wndclass3
.hInstance
= wxhInstance
;
278 wndclass3
.hIcon
= NULL
;
279 wndclass3
.hCursor
= NULL
;
280 // wndclass3.hbrBackground = (HBRUSH)(COLOR_WINDOW+1) ;
281 wndclass3
.hbrBackground
= NULL
;
282 wndclass3
.lpszMenuName
= NULL
;
283 wndclass3
.lpszClassName
= wxCanvasClassName
;
284 if (!RegisterClass( &wndclass3
))
286 // wxFatalError("Can't register Canvas class");
293 // Cleans up any wxWindows internal structures left lying around
294 void wxApp::CleanUp()
296 wxModule::CleanUpModules();
300 wxSetKeyboardHook(FALSE
);
303 if (gs_hRichEdit
!= NULL
)
304 FreeLibrary(gs_hRichEdit
);
311 if (wxSTD_FRAME_ICON
)
312 DestroyIcon(wxSTD_FRAME_ICON
);
313 if (wxSTD_MDICHILDFRAME_ICON
)
314 DestroyIcon(wxSTD_MDICHILDFRAME_ICON
);
315 if (wxSTD_MDIPARENTFRAME_ICON
)
316 DestroyIcon(wxSTD_MDIPARENTFRAME_ICON
);
318 if (wxDEFAULT_FRAME_ICON
)
319 DestroyIcon(wxDEFAULT_FRAME_ICON
);
320 if (wxDEFAULT_MDICHILDFRAME_ICON
)
321 DestroyIcon(wxDEFAULT_MDICHILDFRAME_ICON
);
322 if (wxDEFAULT_MDIPARENTFRAME_ICON
)
323 DestroyIcon(wxDEFAULT_MDIPARENTFRAME_ICON
);
325 if ( wxDisableButtonBrush
)
326 ::DeleteObject( wxDisableButtonBrush
) ;
328 #if defined(WX_DRAG_DROP)
333 Ctl3dUnregister(wxhInstance
);
337 delete wxWinHandleList
;
339 // do it as the very last thing because everything else can log messages
340 wxLog::DontCreateOnDemand();
341 delete wxLog::SetActiveTarget(NULL
);
344 void wxApp::CommonInit()
347 wxBuffer
= new char[1500];
349 wxBuffer
= new char[BUFSIZ
+ 512];
352 wxClassInfo::InitializeClasses();
355 wxGetResource("wxWindows", "OsVersion", &wxOsVersion
);
358 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
359 wxTheColourDatabase
->Initialize();
361 wxInitializeStockLists();
362 wxInitializeStockObjects();
365 wxInitializeResourceSystem();
368 // For PostScript printing
370 wxInitializePrintSetupData();
371 wxThePrintPaperDatabase
= new wxPrintPaperDatabase
;
372 wxThePrintPaperDatabase
->CreateDatabase();
375 wxBitmap::InitStandardHandlers();
377 g_globalCursor
= new wxCursor
;
380 void wxApp::CommonCleanUp()
383 wxCleanUpResourceSystem();
385 // wxDefaultResourceTable->ClearTable();
387 // Indicate that the cursor can be freed,
388 // so that cursor won't be deleted by deleting
389 // the bitmap list before g_globalCursor goes out
390 // of scope (double deletion of the cursor).
391 wxSetCursor(wxNullCursor
);
392 delete g_globalCursor
;
394 wxDeleteStockObjects() ;
396 // Destroy all GDI lists, etc.
397 delete wxTheBrushList
;
398 wxTheBrushList
= NULL
;
403 delete wxTheFontList
;
404 wxTheFontList
= NULL
;
406 delete wxTheBitmapList
;
407 wxTheBitmapList
= NULL
;
409 delete wxTheColourDatabase
;
410 wxTheColourDatabase
= NULL
;
413 wxInitializePrintSetupData(FALSE
);
414 delete wxThePrintPaperDatabase
;
415 wxThePrintPaperDatabase
= NULL
;
418 wxBitmap::CleanUpHandlers();
424 #if !defined(_WINDLL) || (defined(_WINDLL) && defined(WXMAKINGDLL))
426 // Main wxWindows entry point
428 int wxEntry(WXHINSTANCE hInstance
, WXHINSTANCE
WXUNUSED(hPrevInstance
), char *m_lpCmdLine
,
429 int nCmdShow
, bool enterLoop
)
431 wxhInstance
= (HINSTANCE
) hInstance
;
433 #if defined(__WXDEBUG__) && defined(_MSC_VER)
434 // do check for memory leaks on program exit
435 // (another useful flag is _CRTDBG_DELAY_FREE_MEM_DF which doesn't free
436 // deallocated memory which may be used to simulate low-memory condition)
437 _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG
) | _CRTDBG_LEAK_CHECK_DF
);
438 #endif // debug build under MS VC++
440 #if (WXDEBUG && USE_MEMORY_TRACING) || USE_DEBUG_CONTEXT
442 #if !defined(_WINDLL)
443 streambuf
* sBuf
= new wxDebugStreamBuf
;
445 streambuf
* sBuf
= NULL
;
447 ostream
* oStr
= new ostream(sBuf
) ;
448 wxDebugContext::SetStream(oStr
, sBuf
);
450 #endif // USE_MEMORY_TRACING
452 if (!wxApp::Initialize((WXHINSTANCE
) wxhInstance
))
455 // The app may have declared a global application object, but we recommend
456 // the IMPLEMENT_APP macro is used instead, which sets an initializer function
457 // for delayed, dynamic app object construction.
460 if (!wxApp::GetInitializerFunction())
462 MessageBox(NULL
, "No initializer - use IMPLEMENT_APP macro.", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
466 wxTheApp
= (* wxApp::GetInitializerFunction()) ();
470 MessageBox(NULL
, "You have to define an instance of wxApp!", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
474 // Split command line into tokens, as in usual main(argc, argv)
475 char **command
= new char*[50];
478 char *buf
= new char[strlen(m_lpCmdLine
) + 1];
480 // Hangs around until end of app. in case
481 // user carries pointers to the tokens
483 /* Model independent strcpy */
485 for (i
= 0; (buf
[i
] = m_lpCmdLine
[i
]) != 0; i
++)
490 // Get application name
492 ::GetModuleFileName(wxhInstance
, name
, 199);
494 // Is it only 16-bit Borland that already copies the program name
495 // to the first argv index?
496 #if !defined(__GNUWIN32__)
497 // #if ! (defined(__BORLANDC__) && !defined(__WIN32__))
498 command
[count
++] = copystring(name
);
502 strcpy(name
, wxFileNameFromPath(name
));
503 wxStripExtension(name
);
504 wxTheApp
->SetAppName(name
);
506 /* Break up string */
507 // Treat strings enclosed in double-quotes as single arguments
511 while (*str
&& *str
<= ' ') str
++; // skip whitespace
515 command
[count
++] = str
;
516 while (*str
&& *str
!= '"') str
++;
520 command
[count
++] = str
;
521 while (*str
&& *str
> ' ') str
++;
523 if (*str
) *str
++ = '\0';
525 command
[count
] = NULL
; /* argv[] is NULL terminated list! */
527 wxTheApp
->argc
= count
;
528 wxTheApp
->argv
= command
;
529 wxTheApp
->m_nCmdShow
= nCmdShow
;
531 // GUI-specific initialisation. In fact on Windows we don't have any,
532 // but this call is provided for compatibility across platforms.
533 wxTheApp
->OnInitGui() ;
535 if (!wxTheApp
->OnInit())
537 wxTheApp
->DeletePendingObjects();
546 // TODO: This should really be cleaned up in ~wxApp
547 delete [] command
[0] ;
557 /* New behaviour - leave it to the app to show the top window
558 if (wxTheApp->GetTopWindow()) {
559 // show the toplevel frame, only if we are not iconized (from MS-Windows)
560 if(wxTheApp->GetShowFrameOnInit() && (nCmdShow!=SW_HIDE)) wxTheApp->GetTopWindow()->Show(TRUE);
564 retValue
= wxTheApp
->OnRun();
566 if (wxTheApp
->GetTopWindow())
568 // Forcibly delete the window.
569 if (wxTheApp
->GetTopWindow()->IsKindOf(CLASSINFO(wxFrame
)) ||
570 wxTheApp
->GetTopWindow()->IsKindOf(CLASSINFO(wxDialog
)))
572 wxTheApp
->GetTopWindow()->Close(TRUE
);
573 wxTheApp
->DeletePendingObjects();
577 delete wxTheApp
->GetTopWindow();
578 wxTheApp
->SetTopWindow(NULL
);
589 delete [] command
[0] ;
592 #if (WXDEBUG && USE_MEMORY_TRACING) || USE_DEBUG_CONTEXT
593 // At this point we want to check if there are any memory
594 // blocks that aren't part of the wxDebugContext itself,
595 // as a special case. Then when dumping we need to ignore
596 // wxDebugContext, too.
597 if (wxDebugContext::CountObjectsLeft() > 0)
599 wxTrace("There were memory leaks.\n");
600 wxDebugContext::Dump();
601 wxDebugContext::PrintStatistics();
603 wxDebugContext::SetStream(NULL
, NULL
);
611 int wxEntry(WXHINSTANCE hInstance
)
613 wxhInstance
= (HINSTANCE
) hInstance
;
614 wxApp::Initialize((WXHINSTANCE
) wxhInstance
);
616 // The app may have declared a global application object, but we recommend
617 // the IMPLEMENT_APP macro is used instead, which sets an initializer function
618 // for delayed, dynamic app object construction.
622 if (!wxApp::GetInitializerFunction())
624 MessageBox(NULL
, "No initializer - use IMPLEMENT_APP macro.", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
628 wxTheApp
= (* wxApp::GetInitializerFunction()) ();
632 MessageBox(NULL
, "You have to define an instance of wxApp!", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
637 wxTheApp
->argv
= NULL
;
639 wxTheApp
->OnInitGui();
643 if (wxTheApp
->GetTopWindow() && wxTheApp
->GetTopWindow()->GetHWND()) {
644 wxTheApp
->GetTopWindow()->Show(TRUE
);
651 // Static member initialization
652 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
658 // work_proc = NULL ;
660 // m_resourceCollection = TRUE;
661 // m_pendingCleanup = FALSE;
662 m_wantDebugOutput
= TRUE
;
667 m_printMode
= wxPRINT_WINDOWS
;
669 m_printMode
= wxPRINT_POSTSCRIPT
;
671 m_exitOnFrameDelete
= TRUE
;
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();
887 // Free up font objects that are not being used at present.
888 bool wxApp::DoResourceCleanup()
890 // wxDebugMsg("ResourceCleanup\n");
894 wxNode *node = wxTheFontList->First();
897 wxGDIObject *obj = (wxGDIObject *)node->Data();
898 if ((obj->GetResourceHandle() != 0) && (obj->GetResourceUsage() == 0))
900 // wxDebugMsg("Freeing font %ld (GDI object %d)\n", (long)obj, (int)obj->GetResourceHandle());
908 wxNode *node = wxThePenList->First();
911 wxGDIObject *obj = (wxGDIObject *)node->Data();
912 if ((obj->GetResourceHandle() != 0) && (obj->GetResourceUsage() == 0))
914 // wxDebugMsg("Freeing pen %ld (GDI object %d)\n", (long)obj, (int)obj->GetResourceHandle());
922 wxNode *node = wxTheBrushList->First();
925 wxGDIObject *obj = (wxGDIObject *)node->Data();
926 if ((obj->GetResourceHandle() != 0) && (obj->GetResourceUsage() == 0))
928 // wxDebugMsg("Freeing brush %ld (GDI object %d)\n", (long)obj, (int)obj->GetResourceHandle());
935 SetPendingCleanup(FALSE);
940 wxLog
* wxApp::CreateLogTarget()
945 wxWindow
* wxApp::GetTopWindow() const
949 else if (wxTopLevelWindows
.Number() > 0)
950 return (wxWindow
*) wxTopLevelWindows
.First()->Data();
955 int wxApp::GetComCtl32Version() const
957 // have we loaded COMCTL32 yet?
958 HMODULE theModule
= ::GetModuleHandle("COMCTL32");
961 // if so, then we can check for the version
964 // InitCommonControlsEx is unique to 4.7 and later
965 FARPROC theProc
= ::GetProcAddress(theModule
, "InitCommonControlsEx");
968 { // not found, must be 4.00
973 // The following symbol are unique to 4.71
975 // FlatSB_EnableScrollBar FlatSB_GetScrollInfo FlatSB_GetScrollPos
976 // FlatSB_GetScrollProp FlatSB_GetScrollRange FlatSB_SetScrollInfo
977 // FlatSB_SetScrollPos FlatSB_SetScrollProp FlatSB_SetScrollRange
978 // FlatSB_ShowScrollBar
979 // _DrawIndirectImageList _DuplicateImageList
981 // UninitializeFlatSB
982 // we could check for any of these - I chose DllInstall
983 FARPROC theProc
= ::GetProcAddress(theModule
, "DllInstall");
986 // not found, must be 4.70
990 { // found, must be 4.71
1001 FatalAppExit(0, "Fatal error: exiting");
1004 // Yield to incoming messages
1008 // We want to go back to the main message loop
1009 // if we see a WM_QUIT. (?)
1010 while (PeekMessage(&msg
, NULL
, 0, 0, PM_NOREMOVE
) && msg
.message
!= WM_QUIT
)
1012 if (!wxTheApp
->DoMessage())
1019 HINSTANCE
wxGetInstance()
1024 // For some reason, with MSVC++ 1.5, WinMain isn't linked in properly
1025 // if in a separate file. So include it here to ensure it's linked.
1026 #if (defined(_MSC_VER) && !defined(__WIN32__)) || defined(__GNUWIN32__)
1030 #undef IN_WX_MAIN_CPP