]> git.saurik.com Git - wxWidgets.git/blame - docs/doxygen/overviews/app.h
Revert "Make wxMSW stack walking methods work with Unicode identifiers."
[wxWidgets.git] / docs / doxygen / overviews / app.h
CommitLineData
15b6757b 1/////////////////////////////////////////////////////////////////////////////
e0a47918 2// Name: app.h
15b6757b
FM
3// Purpose: topic overview
4// Author: wxWidgets team
526954c5 5// Licence: wxWindows licence
15b6757b
FM
6/////////////////////////////////////////////////////////////////////////////
7
880efa2a 8/**
36c9828f 9
032e27aa 10@page overview_app wxApp Overview
36c9828f 11
e7054054 12@tableofcontents
98ba1eee 13
032e27aa
BP
14A wxWidgets application does not have a @e main procedure; the equivalent is
15the wxApp::OnInit member defined for a class derived from wxApp.
16
17@e OnInit will usually create a top window as a bare minimum. Unlike in earlier
18versions of wxWidgets, OnInit does not return a frame. Instead it returns a
19boolean value which indicates whether processing should continue (@true) or not
18f42b94 20(@false).
032e27aa
BP
21
22Note that the program's command line arguments, represented by @e argc and
23@e argv, are available from within wxApp member functions.
24
25An application closes by destroying all windows. Because all frames must be
26destroyed for the application to exit, it is advisable to use parent frames
27wherever possible when creating new frames, so that deleting the top level
28frame will automatically delete child frames. The alternative is to explicitly
29delete child frames in the top-level frame's wxCloseEvent handler.
30
31In emergencies the wxExit function can be called to kill the application
32however normally the application shuts down automatically, see
33@ref overview_app_shutdown.
34
35An example of defining an application follows:
36
37@code
38class DerivedApp : public wxApp
39{
40public:
41 virtual bool OnInit();
42};
43
44IMPLEMENT_APP(DerivedApp)
45
46bool DerivedApp::OnInit()
47{
48 wxFrame *the_frame = new wxFrame(NULL, ID_MYFRAME, argv[0]);
49 ...
50 the_frame->Show(true);
032e27aa
BP
51
52 return true;
53}
54@endcode
55
56Note the use of IMPLEMENT_APP(appClass), which allows wxWidgets to dynamically
57create an instance of the application object at the appropriate point in
58wxWidgets initialization. Previous versions of wxWidgets used to rely on the
59creation of a global application object, but this is no longer recommended,
60because required global initialization may not have been performed at
61application object construction time.
62
63You can also use DECLARE_APP(appClass) in a header file to declare the wxGetApp
64function which returns a reference to the application object. Otherwise you can
65only use the global @c wxTheApp pointer which is of type @c wxApp*.
66
67
e7054054 68
032e27aa
BP
69@section overview_app_shutdown Application Shutdown
70
71The application normally shuts down when the last of its top level windows is
72closed. This is normally the expected behaviour and means that it is enough to
73call wxWindow::Close() in response to the "Exit" menu command if your program
74has a single top level window. If this behaviour is not desirable
75wxApp::SetExitOnFrameDelete can be called to change it.
76
77Note that such logic doesn't apply for the windows shown before the program
78enters the main loop: in other words, you can safely show a dialog from
79wxApp::OnInit and not be afraid that your application terminates when this
80dialog -- which is the last top level window for the moment -- is closed.
81
82Another aspect of the application shutdown is wxApp::OnExit which is called
83when the application exits but @e before wxWidgets cleans up its internal
84structures. You should delete all wxWidgets object that you created by the time
85OnExit finishes.
86
87In particular, do @b not destroy them from application class' destructor! For
88example, this code may crash:
89
90@code
91class MyApp : public wxApp
92{
93public:
94 wxCHMHelpController m_helpCtrl;
95 ...
96};
97@endcode
98
99The reason for that is that @c m_helpCtrl is a member object and is thus
100destroyed from MyApp destructor. But MyApp object is deleted after wxWidgets
101structures that wxCHMHelpController depends on were uninitialized! The solution
102is to destroy HelpCtrl in @e OnExit:
103
104@code
105class MyApp : public wxApp
106{
107public:
108 wxCHMHelpController *m_helpCtrl;
109 ...
110};
111
112bool MyApp::OnInit()
113{
114 ...
115 m_helpCtrl = new wxCHMHelpController;
116 ...
117}
118
119int MyApp::OnExit()
120{
121 delete m_helpCtrl;
122 return 0;
123}
124@endcode
36c9828f 125
e0a47918 126*/