File: overview_app.html

package info (click to toggle)
wxpython3.0 3.0.2.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 482,760 kB
  • ctags: 518,293
  • sloc: cpp: 2,127,226; python: 294,045; makefile: 51,942; ansic: 19,033; sh: 3,013; xml: 1,629; perl: 17
file content (122 lines) | stat: -rw-r--r-- 10,536 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>wxWidgets: wxApp Overview</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="extra_stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="page_container">
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0" style="width: 100%;">
 <tbody>
 <tr>
  <td id="projectlogo">
    <a href="http://www.wxwidgets.org/" target="_new">
      <img alt="wxWidgets" src="logo.png"/>
    </a>
  </td>
  <td style="padding-left: 0.5em; text-align: right;">
   <span id="projectnumber">Version: 3.0.2</span>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- Generated by Doxygen 1.8.2 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Categories</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="index.html">Documentation</a></li><li class="navelem"><a class="el" href="page_topics.html">Programming Guides</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title"><a class="el" href="classwx_app.html" title="The wxApp class represents the application itself when wxUSE_GUI=1.">wxApp</a> Overview </div>  </div>
</div><!--header-->
<div class="contents">
<div class="toc"><h3>Table of Contents</h3>
<ul><li class="level1"><a href="#overview_app_shutdown">Application Shutdown</a></li>
</ul>
</div>
<div class="textblock"><p>A wxWidgets application does not have a <em>main</em> procedure; the equivalent is the <a class="el" href="classwx_app_console.html#a99953775a2fd83fa2456e390779afe15" title="This must be provided by the application, and will usually create the application&#39;s main window...">wxApp::OnInit</a> member defined for a class derived from <a class="el" href="classwx_app.html" title="The wxApp class represents the application itself when wxUSE_GUI=1.">wxApp</a>.</p>
<p><em>OnInit</em> will usually create a top window as a bare minimum. Unlike in earlier versions of wxWidgets, OnInit does not return a frame. Instead it returns a boolean value which indicates whether processing should continue (<span class="literal">true</span>) or not (<span class="literal">false</span>).</p>
<p>Note that the program's command line arguments, represented by <em>argc</em> and <em>argv</em>, are available from within <a class="el" href="classwx_app.html" title="The wxApp class represents the application itself when wxUSE_GUI=1.">wxApp</a> member functions.</p>
<p>An application closes by destroying all windows. Because all frames must be destroyed for the application to exit, it is advisable to use parent frames wherever possible when creating new frames, so that deleting the top level frame will automatically delete child frames. The alternative is to explicitly delete child frames in the top-level frame's <a class="el" href="classwx_close_event.html" title="This event class contains information about window and session close events.">wxCloseEvent</a> handler.</p>
<p>In emergencies the wxExit function can be called to kill the application however normally the application shuts down automatically, see <a class="el" href="overview_app.html#overview_app_shutdown">Application Shutdown</a>.</p>
<p>An example of defining an application follows:</p>
<div class="fragment"><div class="line"><span class="keyword">class </span>DerivedApp : <span class="keyword">public</span> <a class="code" href="classwx_app.html" title="The wxApp class represents the application itself when wxUSE_GUI=1.">wxApp</a></div>
<div class="line">{</div>
<div class="line"><span class="keyword">public</span>:</div>
<div class="line">    <span class="keyword">virtual</span> <span class="keywordtype">bool</span> <a class="code" href="classwx_app_console.html#a99953775a2fd83fa2456e390779afe15" title="This must be provided by the application, and will usually create the application&#39;s main window...">OnInit</a>();</div>
<div class="line">};</div>
<div class="line"></div>
<div class="line">IMPLEMENT_APP(DerivedApp)</div>
<div class="line"></div>
<div class="line">bool DerivedApp::OnInit()</div>
<div class="line">{</div>
<div class="line">    <a class="code" href="classwx_frame.html" title="A frame is a window whose size and position can (usually) be changed by the user.">wxFrame</a> *the_frame = <span class="keyword">new</span> <a class="code" href="classwx_frame.html" title="A frame is a window whose size and position can (usually) be changed by the user.">wxFrame</a>(NULL, ID_MYFRAME, argv[0]);</div>
<div class="line">    ...</div>
<div class="line">    the_frame-&gt;<a class="code" href="classwx_window.html#a7fbc92ce240a8d4f6956b6e0276ef07f" title="Shows or hides the window.">Show</a>(<span class="keyword">true</span>);</div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line">}</div>
</div><!-- fragment --><p>Note the use of IMPLEMENT_APP(appClass), which allows wxWidgets to dynamically create an instance of the application object at the appropriate point in wxWidgets initialization. Previous versions of wxWidgets used to rely on the creation of a global application object, but this is no longer recommended, because required global initialization may not have been performed at application object construction time.</p>
<p>You can also use DECLARE_APP(appClass) in a header file to declare the wxGetApp function which returns a reference to the application object. Otherwise you can only use the global <code>wxTheApp</code> pointer which is of type <code>wxApp*</code>.</p>
<h1><a class="anchor" id="overview_app_shutdown"></a>
Application Shutdown</h1>
<p>The application normally shuts down when the last of its top level windows is closed. This is normally the expected behaviour and means that it is enough to call <a class="el" href="classwx_window.html#a3e44f4a494fc9ef4346c4fba70c8de0c" title="This function simply generates a wxCloseEvent whose handler usually tries to close the window...">wxWindow::Close()</a> in response to the "Exit" menu command if your program has a single top level window. If this behaviour is not desirable <a class="el" href="classwx_app.html#aceb948ece9ba286f738ec3379a18bc52" title="Allows the programmer to specify whether the application will exit when the top-level frame is delete...">wxApp::SetExitOnFrameDelete</a> can be called to change it.</p>
<p>Note that such logic doesn't apply for the windows shown before the program enters the main loop: in other words, you can safely show a dialog from <a class="el" href="classwx_app_console.html#a99953775a2fd83fa2456e390779afe15" title="This must be provided by the application, and will usually create the application&#39;s main window...">wxApp::OnInit</a> and not be afraid that your application terminates when this dialog &ndash; which is the last top level window for the moment &ndash; is closed.</p>
<p>Another aspect of the application shutdown is <a class="el" href="classwx_app_console.html#a5ee60051c92b0b2933258799626a0485" title="Override this member function for any processing which needs to be done as the application is about t...">wxApp::OnExit</a> which is called when the application exits but <em>before</em> wxWidgets cleans up its internal structures. You should delete all wxWidgets object that you created by the time OnExit finishes.</p>
<p>In particular, do <b>not</b> destroy them from application class' destructor! For example, this code may crash:</p>
<div class="fragment"><div class="line"><span class="keyword">class </span>MyApp : <span class="keyword">public</span> <a class="code" href="classwx_app.html" title="The wxApp class represents the application itself when wxUSE_GUI=1.">wxApp</a></div>
<div class="line">{</div>
<div class="line"><span class="keyword">public</span>:</div>
<div class="line">    wxCHMHelpController m_helpCtrl;</div>
<div class="line">    ...</div>
<div class="line">};</div>
</div><!-- fragment --><p>The reason for that is that <code>m_helpCtrl</code> is a member object and is thus destroyed from MyApp destructor. But MyApp object is deleted after wxWidgets structures that wxCHMHelpController depends on were uninitialized! The solution is to destroy HelpCtrl in <em>OnExit:</em> </p>
<div class="fragment"><div class="line"><span class="keyword">class </span>MyApp : <span class="keyword">public</span> <a class="code" href="classwx_app.html" title="The wxApp class represents the application itself when wxUSE_GUI=1.">wxApp</a></div>
<div class="line">{</div>
<div class="line"><span class="keyword">public</span>:</div>
<div class="line">    wxCHMHelpController *m_helpCtrl;</div>
<div class="line">    ...</div>
<div class="line">};</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">bool</span> MyApp::OnInit()</div>
<div class="line">{</div>
<div class="line">    ...</div>
<div class="line">    m_helpCtrl = <span class="keyword">new</span> wxCHMHelpController;</div>
<div class="line">    ...</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> MyApp::OnExit()</div>
<div class="line">{</div>
<div class="line">    <span class="keyword">delete</span> m_helpCtrl;</div>
<div class="line">    <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
</div><!-- fragment --> </div></div><!-- contents -->

<address class="footer">
	<small>
		Generated on Thu Nov 27 2014 13:46:42 for wxWidgets by <a href="http://www.doxygen.org/index.html" target="_new">Doxygen</a> 1.8.2
	</small>
</address>
<script src="wxwidgets.js" type="text/javascript"></script>
</div><!-- #page_container -->
</body>
</html>