wxWidgets/docs/latex/wx/tapp.tex
Karsten Ballüder a660d684ed I've now added the documentation files.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
1998-05-20 14:25:30 +00:00

57 lines
2.1 KiB
TeX

\section{wxApp overview}\label{wxappoverview}
Classes: \helpref{wxApp}{wxapp}
A wxWindows application does not have a {\it main} procedure; the equivalent is the
\rtfsp\helpref{OnInit}{wxapponinit} member defined for a class derived from wxApp.\rtfsp
\rtfsp{\it OnInit} will usually create a top window as a bare minimum.
Unlike in earlier versions of wxWindows, OnInit does not return a frame. Instead it
returns a boolean value which indicates whether processing should continue (TRUE) or not (FALSE).
You call \helpref{wxApp::SetTopWindow}{wxappsettopwindow} to let wxWindows know
about the top window.
Note that the program's command line arguments, represented by {\it
argc} and {\it argv}, are available from within wxApp member functions.
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 \helpref{wxWindow::OnCloseWindow}{wxwindowonclosewindow}\rtfsp
handler.
In emergencies the \helpref{wxExit}{wxexit} function can be called to kill the
application.
An example of defining an application follows:
\begin{verbatim}
class DerivedApp: public wxApp
{
public:
bool OnInit(void);
};
IMPLEMENT_APP(DerivedApp)
bool DerivedApp::OnInit(void)
{
wxFrame *the_frame = new wxFrame(NULL, argv[0]);
...
SetTopWindow(the_frame);
return TRUE;
}
\end{verbatim}
Note the use of IMPLEMENT\_APP(appClass), which allows wxWindows to dynamically create an instance of the application object
at the appropriate point in wxWindows initialization. Previous versions of wxWindows 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.
You can also use DECLARE\_APP(appClass) in a header file to declare the wxGetApp function which returns
a reference to the application object.