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 /* THIS CRAPS OUT in VC++ 5.
57 #if defined(__WXDEBUG__) && defined(_MSC_VER)
62 extern char *wxBuffer
;
63 extern char *wxOsVersion
;
64 extern wxList
*wxWinHandleList
;
65 extern wxList wxPendingDelete
;
66 extern void wxSetKeyboardHook(bool doIt
);
67 extern wxCursor
*g_globalCursor
;
69 HINSTANCE wxhInstance
= 0;
70 static MSG s_currentMsg
;
71 wxApp
*wxTheApp
= NULL
;
73 char wxFrameClassName
[] = "wxFrameClass";
74 char wxMDIFrameClassName
[] = "wxMDIFrameClass";
75 char wxMDIChildFrameClassName
[] = "wxMDIChildFrameClass";
76 char wxPanelClassName
[] = "wxPanelClass";
77 char wxCanvasClassName
[] = "wxCanvasClass";
79 HICON wxSTD_FRAME_ICON
= NULL
;
80 HICON wxSTD_MDICHILDFRAME_ICON
= NULL
;
81 HICON wxSTD_MDIPARENTFRAME_ICON
= NULL
;
83 HICON wxDEFAULT_FRAME_ICON
= NULL
;
84 HICON wxDEFAULT_MDICHILDFRAME_ICON
= NULL
;
85 HICON wxDEFAULT_MDIPARENTFRAME_ICON
= NULL
;
87 HBRUSH wxDisableButtonBrush
= 0;
89 LRESULT APIENTRY
wxWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
91 #if !USE_SHARED_LIBRARY
92 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
93 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
94 EVT_IDLE(wxApp::OnIdle
)
98 long wxApp::sm_lastMessageTime
= 0;
101 static HINSTANCE gs_hRichEdit
= NULL
;
104 bool wxApp::Initialize(WXHINSTANCE instance
)
106 HINSTANCE hInstance
= (HINSTANCE
) instance
;
110 #if defined(__WIN95__)
111 InitCommonControls();
112 gs_hRichEdit
= LoadLibrary("RICHED32.DLL");
114 if (gs_hRichEdit
== NULL
)
116 wxMessageBox("Could not initialise Rich Edit DLL");
120 #if defined(WX_DRAG_DROP)
121 // we need to initialize OLE library
122 if ( FAILED(::OleInitialize(NULL
)) )
123 wxFatalError(_("Cannot initialize OLE"));
127 if (!Ctl3dRegister(hInstance
))
128 wxFatalError("Cannot register CTL3D");
130 Ctl3dAutoSubclass(hInstance
);
133 wxSTD_FRAME_ICON
= LoadIcon(hInstance
, "wxSTD_FRAME");
134 wxSTD_MDIPARENTFRAME_ICON
= LoadIcon(hInstance
, "wxSTD_MDIPARENTFRAME");
135 wxSTD_MDICHILDFRAME_ICON
= LoadIcon(hInstance
, "wxSTD_MDICHILDFRAME");
137 wxDEFAULT_FRAME_ICON
= LoadIcon(hInstance
, "wxDEFAULT_FRAME");
138 wxDEFAULT_MDIPARENTFRAME_ICON
= LoadIcon(hInstance
, "wxDEFAULT_MDIPARENTFRAME");
139 wxDEFAULT_MDICHILDFRAME_ICON
= LoadIcon(hInstance
, "wxDEFAULT_MDICHILDFRAME");
141 RegisterWindowClasses();
143 // Create the brush for disabling bitmap buttons
146 lb
.lbStyle
= BS_PATTERN
;
147 lb
.lbHatch
= (int)LoadBitmap( hInstance
, "wxDISABLE_BUTTON_BITMAP" ) ;
148 wxDisableButtonBrush
= ::CreateBrushIndirect( & lb
) ;
149 ::DeleteObject( (HGDIOBJ
)lb
.lbHatch
) ;
155 wxWinHandleList
= new wxList(wxKEY_INTEGER
);
157 // This is to foil optimizations in Visual C++ that
158 // throw out dummy.obj.
159 #if (_MSC_VER >= 800) && !defined(WXMAKINGDLL)
160 extern char wxDummyChar
;
161 if (wxDummyChar
) wxDummyChar
++;
163 wxSetKeyboardHook(TRUE
);
165 wxModule::RegisterModules();
166 if (!wxModule::InitializeModules())
171 bool wxApp::RegisterWindowClasses()
173 ///////////////////////////////////////////////////////////////////////
174 // Register the frame window class.
175 WNDCLASS wndclass
; // Structure used to register Windows class.
177 wndclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
178 wndclass
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
179 wndclass
.cbClsExtra
= 0;
180 wndclass
.cbWndExtra
= sizeof( DWORD
); // was 4
181 wndclass
.hInstance
= wxhInstance
;
182 wndclass
.hIcon
= NULL
; // wxSTD_FRAME_ICON;
183 wndclass
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
184 wndclass
.hbrBackground
= (HBRUSH
)(COLOR_APPWORKSPACE
+1) ;
185 // wndclass.hbrBackground = GetStockObject( WHITE_BRUSH );
186 wndclass
.lpszMenuName
= NULL
;
187 #ifdef _MULTIPLE_INSTANCES
188 sprintf( wxFrameClassName
,"wxFrameClass%d", hInstance
);
190 wndclass
.lpszClassName
= wxFrameClassName
;
192 if (!RegisterClass( &wndclass
))
194 // wxFatalError("Can't register Frame Window class");
197 ///////////////////////////////////////////////////////////////////////
198 // Register the MDI frame window class.
199 WNDCLASS wndclass1
; // Structure used to register Windows class.
201 wndclass1
.style
= CS_HREDRAW
| CS_VREDRAW
;
202 wndclass1
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
203 wndclass1
.cbClsExtra
= 0;
204 wndclass1
.cbWndExtra
= sizeof( DWORD
); // was 4
205 wndclass1
.hInstance
= wxhInstance
;
206 wndclass1
.hIcon
= NULL
; // wxSTD_MDIPARENTFRAME_ICON;
207 wndclass1
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
208 // wndclass1.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1) ;
209 wndclass1
.hbrBackground
= NULL
;
210 wndclass1
.lpszMenuName
= NULL
;
212 wndclass1
.lpszClassName
= wxMDIFrameClassName
;
213 if (!RegisterClass( &wndclass1
))
215 // wxFatalError("Can't register MDI Frame window class");
219 ///////////////////////////////////////////////////////////////////////
220 // Register the MDI child frame window class.
221 WNDCLASS wndclass4
; // Structure used to register Windows class.
223 wndclass4
.style
= CS_HREDRAW
| CS_VREDRAW
;
224 wndclass4
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
225 wndclass4
.cbClsExtra
= 0;
226 wndclass4
.cbWndExtra
= sizeof( DWORD
); // was 4
227 wndclass4
.hInstance
= wxhInstance
;
228 wndclass4
.hIcon
= NULL
; // wxSTD_MDICHILDFRAME_ICON;
229 wndclass4
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
230 // TODO: perhaps this should be NULL so that Windows doesn't
231 // paint the background itself (would OnEraseBackground duplicate
233 wndclass4
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1) ;
234 // wndclass4.hbrBackground = NULL;
235 wndclass4
.lpszMenuName
= NULL
;
236 wndclass4
.lpszClassName
= wxMDIChildFrameClassName
;
238 if (!RegisterClass( &wndclass4
))
240 // wxFatalError("Can't register MDI child frame window class");
244 ///////////////////////////////////////////////////////////////////////
245 // Register the panel window class.
246 WNDCLASS wndclass2
; // Structure used to register Windows class.
247 memset(&wndclass2
, 0, sizeof(WNDCLASS
)); // start with NULL defaults
248 // Use CS_OWNDC to avoid messing about restoring the context
249 // for every graphic operation.
250 wndclass2
.style
= CS_HREDRAW
| CS_VREDRAW
;
251 wndclass2
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
252 wndclass2
.cbClsExtra
= 0;
253 wndclass2
.cbWndExtra
= sizeof( DWORD
); // was 4
254 wndclass2
.hInstance
= wxhInstance
;
255 wndclass2
.hIcon
= NULL
;
256 wndclass2
.hCursor
= NULL
;
257 // wndclass2.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1) ;
258 wndclass2
.hbrBackground
= (HBRUSH
) GetStockObject( LTGRAY_BRUSH
);
259 wndclass2
.lpszMenuName
= NULL
;
260 wndclass2
.lpszClassName
= wxPanelClassName
;
261 if (!RegisterClass( &wndclass2
))
263 // wxFatalError("Can't register Panel Window class");
267 ///////////////////////////////////////////////////////////////////////
268 // Register the canvas and textsubwindow class name
269 WNDCLASS wndclass3
; // Structure used to register Windows class.
270 memset(&wndclass3
, 0, sizeof(WNDCLASS
)); // start with NULL defaults
271 // Use CS_OWNDC to avoid messing about restoring the context
272 // for every graphic operation.
273 // wndclass3.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS ;
275 wndclass3
.style
= CS_HREDRAW
| CS_VREDRAW
| CS_DBLCLKS
;
276 wndclass3
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
277 wndclass3
.cbClsExtra
= 0;
278 wndclass3
.cbWndExtra
= sizeof( DWORD
); // was 4
279 wndclass3
.hInstance
= wxhInstance
;
280 wndclass3
.hIcon
= NULL
;
281 wndclass3
.hCursor
= NULL
;
282 // wndclass3.hbrBackground = (HBRUSH)(COLOR_WINDOW+1) ;
283 wndclass3
.hbrBackground
= NULL
;
284 wndclass3
.lpszMenuName
= NULL
;
285 wndclass3
.lpszClassName
= wxCanvasClassName
;
286 if (!RegisterClass( &wndclass3
))
288 // wxFatalError("Can't register Canvas class");
295 // Cleans up any wxWindows internal structures left lying around
296 void wxApp::CleanUp()
298 wxModule::CleanUpModules();
302 wxSetKeyboardHook(FALSE
);
305 if (gs_hRichEdit
!= NULL
)
306 FreeLibrary(gs_hRichEdit
);
313 if (wxSTD_FRAME_ICON
)
314 DestroyIcon(wxSTD_FRAME_ICON
);
315 if (wxSTD_MDICHILDFRAME_ICON
)
316 DestroyIcon(wxSTD_MDICHILDFRAME_ICON
);
317 if (wxSTD_MDIPARENTFRAME_ICON
)
318 DestroyIcon(wxSTD_MDIPARENTFRAME_ICON
);
320 if (wxDEFAULT_FRAME_ICON
)
321 DestroyIcon(wxDEFAULT_FRAME_ICON
);
322 if (wxDEFAULT_MDICHILDFRAME_ICON
)
323 DestroyIcon(wxDEFAULT_MDICHILDFRAME_ICON
);
324 if (wxDEFAULT_MDIPARENTFRAME_ICON
)
325 DestroyIcon(wxDEFAULT_MDIPARENTFRAME_ICON
);
327 if ( wxDisableButtonBrush
)
328 ::DeleteObject( wxDisableButtonBrush
) ;
330 #if defined(WX_DRAG_DROP)
335 Ctl3dUnregister(wxhInstance
);
339 delete wxWinHandleList
;
341 // do it as the very last thing because everything else can log messages
342 wxLog::DontCreateOnDemand();
343 delete wxLog::SetActiveTarget(NULL
);
346 void wxApp::CommonInit()
349 wxBuffer
= new char[1500];
351 wxBuffer
= new char[BUFSIZ
+ 512];
354 wxClassInfo::InitializeClasses();
357 wxGetResource("wxWindows", "OsVersion", &wxOsVersion
);
360 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
361 wxTheColourDatabase
->Initialize();
363 wxInitializeStockLists();
364 wxInitializeStockObjects();
367 wxInitializeResourceSystem();
370 // For PostScript printing
372 wxInitializePrintSetupData();
373 wxThePrintPaperDatabase
= new wxPrintPaperDatabase
;
374 wxThePrintPaperDatabase
->CreateDatabase();
377 wxBitmap::InitStandardHandlers();
379 g_globalCursor
= new wxCursor
;
382 void wxApp::CommonCleanUp()
385 wxCleanUpResourceSystem();
387 // wxDefaultResourceTable->ClearTable();
390 // Indicate that the cursor can be freed,
391 // so that cursor won't be deleted by deleting
392 // the bitmap list before g_globalCursor goes out
393 // of scope (double deletion of the cursor).
394 wxSetCursor(wxNullCursor
);
395 delete g_globalCursor
;
397 wxDeleteStockObjects() ;
399 // Destroy all GDI lists, etc.
400 wxDeleteStockLists();
402 delete wxTheColourDatabase
;
403 wxTheColourDatabase
= NULL
;
406 wxInitializePrintSetupData(FALSE
);
407 delete wxThePrintPaperDatabase
;
408 wxThePrintPaperDatabase
= NULL
;
411 wxBitmap::CleanUpHandlers();
417 #if !defined(_WINDLL) || (defined(_WINDLL) && defined(WXMAKINGDLL))
419 // Main wxWindows entry point
421 int wxEntry(WXHINSTANCE hInstance
, WXHINSTANCE
WXUNUSED(hPrevInstance
), char *m_lpCmdLine
,
422 int nCmdShow
, bool enterLoop
)
424 wxhInstance
= (HINSTANCE
) hInstance
;
426 /* No, sorry, whatever this is, forget it. Doesn't work with VC++ 5.
428 #if defined(__WXDEBUG__) && defined(_MSC_VER)
429 // do check for memory leaks on program exit
430 // (another useful flag is _CRTDBG_DELAY_FREE_MEM_DF which doesn't free
431 // deallocated memory which may be used to simulate low-memory condition)
432 _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);
433 #endif // debug build under MS VC++
436 #if (WXDEBUG && USE_MEMORY_TRACING) || USE_DEBUG_CONTEXT
438 #if !defined(_WINDLL)
439 streambuf
* sBuf
= new wxDebugStreamBuf
;
441 streambuf
* sBuf
= NULL
;
443 ostream
* oStr
= new ostream(sBuf
) ;
444 wxDebugContext::SetStream(oStr
, sBuf
);
446 #endif // USE_MEMORY_TRACING
448 if (!wxApp::Initialize((WXHINSTANCE
) wxhInstance
))
451 // The app may have declared a global application object, but we recommend
452 // the IMPLEMENT_APP macro is used instead, which sets an initializer function
453 // for delayed, dynamic app object construction.
456 if (!wxApp::GetInitializerFunction())
458 MessageBox(NULL
, "No initializer - use IMPLEMENT_APP macro.", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
462 wxTheApp
= (* wxApp::GetInitializerFunction()) ();
466 MessageBox(NULL
, "You have to define an instance of wxApp!", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
470 // Split command line into tokens, as in usual main(argc, argv)
471 char **command
= new char*[50];
474 char *buf
= new char[strlen(m_lpCmdLine
) + 1];
476 // Hangs around until end of app. in case
477 // user carries pointers to the tokens
479 /* Model independent strcpy */
481 for (i
= 0; (buf
[i
] = m_lpCmdLine
[i
]) != 0; i
++)
486 // Get application name
488 ::GetModuleFileName(wxhInstance
, name
, 199);
490 // Is it only 16-bit Borland that already copies the program name
491 // to the first argv index?
492 #if !defined(__GNUWIN32__)
493 // #if ! (defined(__BORLANDC__) && !defined(__WIN32__))
494 command
[count
++] = copystring(name
);
498 strcpy(name
, wxFileNameFromPath(name
));
499 wxStripExtension(name
);
500 wxTheApp
->SetAppName(name
);
502 /* Break up string */
503 // Treat strings enclosed in double-quotes as single arguments
507 while (*str
&& *str
<= ' ') str
++; // skip whitespace
511 command
[count
++] = str
;
512 while (*str
&& *str
!= '"') str
++;
516 command
[count
++] = str
;
517 while (*str
&& *str
> ' ') str
++;
519 if (*str
) *str
++ = '\0';
521 command
[count
] = NULL
; /* argv[] is NULL terminated list! */
523 wxTheApp
->argc
= count
;
524 wxTheApp
->argv
= command
;
525 wxTheApp
->m_nCmdShow
= nCmdShow
;
527 // GUI-specific initialisation. In fact on Windows we don't have any,
528 // but this call is provided for compatibility across platforms.
529 wxTheApp
->OnInitGui() ;
531 if (!wxTheApp
->OnInit())
533 wxTheApp
->DeletePendingObjects();
542 // TODO: This should really be cleaned up in ~wxApp
543 delete [] command
[0] ;
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
);
585 delete [] command
[0] ;
588 #if (WXDEBUG && USE_MEMORY_TRACING) || USE_DEBUG_CONTEXT
589 // At this point we want to check if there are any memory
590 // blocks that aren't part of the wxDebugContext itself,
591 // as a special case. Then when dumping we need to ignore
592 // wxDebugContext, too.
593 if (wxDebugContext::CountObjectsLeft() > 0)
595 wxTrace("There were memory leaks.\n");
596 wxDebugContext::Dump();
597 wxDebugContext::PrintStatistics();
599 wxDebugContext::SetStream(NULL
, NULL
);
607 int wxEntry(WXHINSTANCE hInstance
)
609 wxhInstance
= (HINSTANCE
) hInstance
;
610 wxApp::Initialize((WXHINSTANCE
) wxhInstance
);
612 // The app may have declared a global application object, but we recommend
613 // the IMPLEMENT_APP macro is used instead, which sets an initializer function
614 // for delayed, dynamic app object construction.
618 if (!wxApp::GetInitializerFunction())
620 MessageBox(NULL
, "No initializer - use IMPLEMENT_APP macro.", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
624 wxTheApp
= (* wxApp::GetInitializerFunction()) ();
628 MessageBox(NULL
, "You have to define an instance of wxApp!", "wxWindows Error", MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
633 wxTheApp
->argv
= NULL
;
635 wxTheApp
->OnInitGui();
639 if (wxTheApp
->GetTopWindow() && wxTheApp
->GetTopWindow()->GetHWND()) {
640 wxTheApp
->GetTopWindow()->Show(TRUE
);
647 // Static member initialization
648 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
654 // work_proc = NULL ;
656 // m_resourceCollection = TRUE;
657 // m_pendingCleanup = FALSE;
658 m_wantDebugOutput
= TRUE
;
663 m_printMode
= wxPRINT_WINDOWS
;
665 m_printMode
= wxPRINT_POSTSCRIPT
;
667 m_exitOnFrameDelete
= TRUE
;
671 bool wxApp::Initialized()
679 #ifdef _WINDLL // Assume initialized if DLL (no way of telling)
685 * Get and process a message, returning FALSE if WM_QUIT
689 bool wxApp::DoMessage()
691 if (!::GetMessage(&s_currentMsg
, (HWND
) NULL
, 0, 0))
696 // Process the message
697 if (!ProcessMessage((WXMSG
*)&s_currentMsg
))
699 ::TranslateMessage(&s_currentMsg
);
700 wxApp::sm_lastMessageTime
= s_currentMsg
.time
; /* MATTHEW: timeStamp impl. */
701 ::DispatchMessage(&s_currentMsg
);
707 * Keep trying to process messages until WM_QUIT
710 * If there are messages to be processed, they will all be
711 * processed and OnIdle will not be called.
712 * When there are no more messages, OnIdle is called.
713 * If OnIdle requests more time,
714 * it will be repeatedly called so long as there are no pending messages.
715 * A 'feature' of this is that once OnIdle has decided that no more processing
716 * is required, then it won't get processing time until further messages
717 * are processed (it'll sit in DoMessage).
720 int wxApp::MainLoop()
725 while (!::PeekMessage(&s_currentMsg
, 0, 0, 0, PM_NOREMOVE
) &&
731 return s_currentMsg
.wParam
;
734 // Returns TRUE if more time is needed.
735 bool wxApp::ProcessIdle()
738 event
.SetEventObject(this);
741 return event
.MoreRequested();
744 void wxApp::ExitMainLoop()
749 bool wxApp::Pending()
751 return (::PeekMessage(&s_currentMsg
, 0, 0, 0, PM_NOREMOVE
) != 0) ;
754 void wxApp::Dispatch()
761 * Give all windows a chance to preprocess
762 * the message. Some may have accelerator tables, or have
765 bool wxApp::ProcessMessage(WXMSG
*Msg
)
767 MSG
*msg
= (MSG
*)Msg
;
771 // Try translations first; find the youngest window with
772 // a translation table.
773 for (hWnd
= msg
->hwnd
; hWnd
!= NULL
; hWnd
= ::GetParent(hWnd
))
775 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
778 if (wnd
->MSWTranslateMessage(Msg
))
783 // Anyone for a non-translation message? Try youngest descendants first.
784 for (hWnd
= msg
->hwnd
; hWnd
!= NULL
; hWnd
= ::GetParent(hWnd
))
786 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
789 if (wnd
->MSWProcessMessage(Msg
))
796 void wxApp::OnIdle(wxIdleEvent
& event
)
798 static bool inOnIdle
= FALSE
;
800 // Avoid recursion (via ProcessEvent default case)
806 // 'Garbage' collection of windows deleted with Close().
807 DeletePendingObjects();
809 // flush the logged messages if any
810 wxLog
*pLog
= wxLog::GetActiveTarget();
811 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
814 // Send OnIdle events to all windows
815 bool needMore
= SendIdleEvents();
816 // bool needMore = FALSE;
819 event
.RequestMore(TRUE
);
824 // Send idle event to all top-level windows
825 bool wxApp::SendIdleEvents()
827 bool needMore
= FALSE
;
828 wxNode
* node
= wxTopLevelWindows
.First();
831 wxWindow
* win
= (wxWindow
*) node
->Data();
832 if (SendIdleEvents(win
))
840 // Send idle event to window and all subwindows
841 bool wxApp::SendIdleEvents(wxWindow
* win
)
843 bool needMore
= FALSE
;
846 event
.SetEventObject(win
);
847 win
->ProcessEvent(event
);
849 if (event
.MoreRequested())
852 wxNode
* node
= win
->GetChildren()->First();
855 wxWindow
* win
= (wxWindow
*) node
->Data();
856 if (SendIdleEvents(win
))
864 void wxApp::DeletePendingObjects()
866 wxNode
*node
= wxPendingDelete
.First();
869 wxObject
*obj
= (wxObject
*)node
->Data();
873 if (wxPendingDelete
.Member(obj
))
876 // Deleting one object may have deleted other pending
877 // objects, so start from beginning of list again.
878 node
= wxPendingDelete
.First();
883 // Free up font objects that are not being used at present.
884 bool wxApp::DoResourceCleanup()
886 // wxDebugMsg("ResourceCleanup\n");
890 wxNode *node = wxTheFontList->First();
893 wxGDIObject *obj = (wxGDIObject *)node->Data();
894 if ((obj->GetResourceHandle() != 0) && (obj->GetResourceUsage() == 0))
896 // wxDebugMsg("Freeing font %ld (GDI object %d)\n", (long)obj, (int)obj->GetResourceHandle());
904 wxNode *node = wxThePenList->First();
907 wxGDIObject *obj = (wxGDIObject *)node->Data();
908 if ((obj->GetResourceHandle() != 0) && (obj->GetResourceUsage() == 0))
910 // wxDebugMsg("Freeing pen %ld (GDI object %d)\n", (long)obj, (int)obj->GetResourceHandle());
918 wxNode *node = wxTheBrushList->First();
921 wxGDIObject *obj = (wxGDIObject *)node->Data();
922 if ((obj->GetResourceHandle() != 0) && (obj->GetResourceUsage() == 0))
924 // wxDebugMsg("Freeing brush %ld (GDI object %d)\n", (long)obj, (int)obj->GetResourceHandle());
931 SetPendingCleanup(FALSE);
936 wxLog
* wxApp::CreateLogTarget()
941 wxWindow
* wxApp::GetTopWindow() const
945 else if (wxTopLevelWindows
.Number() > 0)
946 return (wxWindow
*) wxTopLevelWindows
.First()->Data();
951 int wxApp::GetComCtl32Version() const
953 // have we loaded COMCTL32 yet?
954 HMODULE theModule
= ::GetModuleHandle("COMCTL32");
957 // if so, then we can check for the version
960 // InitCommonControlsEx is unique to 4.7 and later
961 FARPROC theProc
= ::GetProcAddress(theModule
, "InitCommonControlsEx");
964 { // not found, must be 4.00
969 // The following symbol are unique to 4.71
971 // FlatSB_EnableScrollBar FlatSB_GetScrollInfo FlatSB_GetScrollPos
972 // FlatSB_GetScrollProp FlatSB_GetScrollRange FlatSB_SetScrollInfo
973 // FlatSB_SetScrollPos FlatSB_SetScrollProp FlatSB_SetScrollRange
974 // FlatSB_ShowScrollBar
975 // _DrawIndirectImageList _DuplicateImageList
977 // UninitializeFlatSB
978 // we could check for any of these - I chose DllInstall
979 FARPROC theProc
= ::GetProcAddress(theModule
, "DllInstall");
982 // not found, must be 4.70
986 { // found, must be 4.71
997 FatalAppExit(0, "Fatal error: exiting");
1000 // Yield to incoming messages
1004 // We want to go back to the main message loop
1005 // if we see a WM_QUIT. (?)
1006 while (PeekMessage(&msg
, NULL
, 0, 0, PM_NOREMOVE
) && msg
.message
!= WM_QUIT
)
1008 if (!wxTheApp
->DoMessage())
1015 HINSTANCE
wxGetInstance()
1020 // For some reason, with MSVC++ 1.5, WinMain isn't linked in properly
1021 // if in a separate file. So include it here to ensure it's linked.
1022 #if (defined(_MSC_VER) && !defined(__WIN32__)) || defined(__GNUWIN32__)
1026 #undef IN_WX_MAIN_CPP