1 \section{\class{wxApp
}}\label{wxapp
}
3 The
{\bf wxApp
} class represents the application itself. It is used
6 \begin{itemize
}\itemsep=
0pt
7 \item set and get application-wide properties;
8 \item implement the windowing system message or event loop;
9 \item initiate application processing via
\helpref{wxApp::OnInit
}{wxapponinit
};
10 \item allow default processing of events not handled by other
11 objects in the application.
14 You should use the macro IMPLEMENT
\_APP(appClass) in your application implementation
15 file to tell wxWidgets how to create an instance of your application class.
17 Use DECLARE
\_APP(appClass) in a header file if you want the wxGetApp function (which returns
18 a reference to your application object) to be visible to other files.
20 \wxheading{Derived from
}
22 \helpref{wxEvtHandler
}{wxevthandler
}\\
23 \helpref{wxObject
}{wxobject
}
25 \wxheading{Include files
}
31 \helpref{wxApp overview
}{wxappoverview
}
33 \latexignore{\rtfignore{\wxheading{Members
}}}
36 \membersection{wxApp::wxApp
}\label{wxappctor
}
40 Constructor. Called implicitly with a definition of a wxApp object.
43 \membersection{wxApp::
\destruct{wxApp
}}\label{wxappdtor
}
45 \func{}{\destruct{wxApp
}}{\void}
47 Destructor. Will be called implicitly on program exit if the wxApp
48 object is created on the stack.
51 \membersection{wxApp::argc
}\label{wxappargc
}
55 Number of command line arguments (after environment-specific processing).
58 \membersection{wxApp::argv
}\label{wxappargv
}
60 \member{char **
}{argv
}
62 Command line arguments (after environment-specific processing).
65 \membersection{wxApp::CreateLogTarget
}\label{wxappcreatelogtarget
}
67 \func{virtual wxLog*
}{CreateLogTarget
}{\void}
69 Creates a wxLog class for the application to use for logging errors. The default
70 implementation returns a new wxLogGui class.
74 \helpref{wxLog
}{wxlog
}
77 \membersection{wxApp::Dispatch
}\label{wxappdispatch
}
79 \func{virtual void
}{Dispatch
}{\void}
81 Dispatches the next event in the windowing system event queue.
83 This can be used for programming event loops, e.g.
92 \helpref{wxApp::Pending
}{wxapppending
}
95 \membersection{wxApp::ExitMainLoop
}\label{wxappexitmainloop
}
97 \func{virtual void
}{ExitMainLoop
}{\void}
99 Call this to explicitly exit the main message (event) loop.
100 You should normally exit the main loop (and the application) by deleting
104 \membersection{wxApp::FilterEvent
}\label{wxappfilterevent
}
106 \func{int
}{FilterEvent
}{\param{wxEvent\&
}{event
}}
108 This function is called before processing any event and allows the application
109 to preempt the processing of some events. If this method returns $-
1$ the event
110 is processed normally, otherwise either
{\tt true
} or
{\tt false
} should be
111 returned and the event processing stops immediately considering that the event
112 had been already processed (for the former return value) or that it is not
113 going to be processed at all (for the latter one).
116 \membersection{wxApp::GetAppName
}\label{wxappgetappname
}
118 \constfunc{wxString
}{GetAppName
}{\void}
120 Returns the application name.
124 wxWidgets sets this to a reasonable default before
125 calling
\helpref{wxApp::OnInit
}{wxapponinit
}, but the application can reset it at will.
128 \membersection{wxApp::GetClassName
}\label{wxappgetclassname
}
130 \constfunc{wxString
}{GetClassName
}{\void}
132 Gets the class name of the application. The class name may be used in a platform specific
133 manner to refer to the application.
137 \helpref{wxApp::SetClassName
}{wxappsetclassname
}
140 \membersection{wxApp::GetExitOnFrameDelete
}\label{wxappgetexitonframedelete
}
142 \constfunc{bool
}{GetExitOnFrameDelete
}{\void}
144 Returns true if the application will exit when the top-level window is deleted, false
149 \helpref{wxApp::SetExitOnFrameDelete
}{wxappsetexitonframedelete
},\\
150 \helpref{wxApp shutdown overview
}{wxappshutdownoverview
}
153 \membersection{wxApp::GetInstance
}\label{wxappgetinstance
}
155 \func{static wxAppConsole *
}{GetInstance
}{\void}
157 Returns the one and only global application object.
158 Usually
\texttt{wxTheApp
} is usead instead.
162 \helpref{wxApp::SetInstance
}{wxappsetinstance
}
165 \membersection{wxApp::GetTopWindow
}\label{wxappgettopwindow
}
167 \constfunc{virtual wxWindow *
}{GetTopWindow
}{\void}
169 Returns a pointer to the top window.
173 If the top window hasn't been set using
\helpref{wxApp::SetTopWindow
}{wxappsettopwindow
}, this
174 function will find the first top-level window (frame or dialog) and return that.
178 \helpref{SetTopWindow
}{wxappsettopwindow
}
181 \membersection{wxApp::GetUseBestVisual
}\label{wxappgetusebestvisual
}
183 \constfunc{bool
}{GetUseBestVisual
}{\void}
185 Returns true if the application will use the best visual on systems that support
186 different visuals, false otherwise.
190 \helpref{SetUseBestVisual
}{wxappsetusebestvisual
}
193 \membersection{wxApp::GetVendorName
}\label{wxappgetvendorname
}
195 \constfunc{wxString
}{GetVendorName
}{\void}
197 Returns the application's vendor name.
200 \membersection{wxApp::IsActive
}\label{wxappisactive
}
202 \constfunc{bool
}{IsActive
}{\void}
204 Returns
\true if the application is active, i.e. if one of its windows is
205 currently in the foreground. If this function returns
\false and you need to
206 attract users attention to the application, you may use
207 \helpref{wxTopLevelWindow::RequestUserAttention
}{wxtoplevelwindowrequestuserattention
}
211 \membersection{wxApp::IsMainLoopRunning
}\label{wxappismainlooprunning
}
213 \func{static bool
}{IsMainLoopRunning
}{\void}
215 Returns
\true if the main event loop is currently running, i.e. if the
216 application is inside
\helpref{OnRun
}{wxapponrun
}.
218 This can be useful to test whether the events can be dispatched. For example,
219 if this function returns
\false, non-blocking sockets cannot be used because
220 the events from them would never be processed.
223 \membersection{wxApp::MainLoop
}\label{wxappmainloop
}
225 \func{virtual int
}{MainLoop
}{\void}
227 Called by wxWidgets on creation of the application. Override this if you wish
228 to provide your own (environment-dependent) main loop.
230 \wxheading{Return value
}
232 Returns
0 under X, and the wParam of the WM
\_QUIT message under Windows.
234 %% VZ: OnXXX() functions should *not* be documented
236 %%\membersection{wxApp::OnActivate}\label{wxapponactivate}
238 %%\func{void}{OnActivate}{\param{wxActivateEvent\& }{event}}
240 %%Provide this member function to know whether the application is being
241 %%activated or deactivated (Windows only).
243 %%\wxheading{See also}
245 %%\helpref{wxWindow::OnActivate}{wxwindowonactivate}, \helpref{wxActivateEvent}{wxactivateevent}
247 %%\membersection{wxApp::OnCharHook}\label{wxapponcharhook}
249 %%\func{void}{OnCharHook}{\param{wxKeyEvent\&}{ event}}
251 %%This event handler function is called (under Windows only) to allow the window to intercept keyboard events
252 %%before they are processed by child windows.
254 %%\wxheading{Parameters}
256 %%\docparam{event}{The keypress event.}
258 %%\wxheading{Remarks}
260 %%Use the wxEVT\_CHAR\_HOOK macro in your event table.
262 %%If you use this member, you can selectively consume keypress events by calling\rtfsp
263 %%\helpref{wxEvent::Skip}{wxeventskip} for characters the application is not interested in.
265 %%\wxheading{See also}
267 %%\helpref{wxKeyEvent}{wxkeyevent}, \helpref{wxWindow::OnChar}{wxwindowonchar},\rtfsp
268 %%\helpref{wxWindow::OnCharHook}{wxwindowoncharhook}, \helpref{wxDialog::OnCharHook}{wxdialogoncharhook}
271 \membersection{wxApp::OnAssert
}\label{wxapponassert
}
273 \func{void
}{OnAssert
}{\param{const wxChar
}{*file
},
\param{int
}{line
},
\param{const wxChar
}{*cond
},
\param{const wxChar
}{*msg
}}
275 This function is called when an assert failure occurs, i.e. the condition
276 specified in
\helpref{wxASSERT
}{wxassert
} macro evaluated to
{\tt false
}.
277 It is only called in debug mode (when
{\tt \_\_WXDEBUG\_\_} is defined) as
278 asserts are not left in the release code at all.
280 The base class version show the default assert failure dialog box proposing to
281 the user to stop the program, continue or ignore all subsequent asserts.
283 \wxheading{Parameters
}
285 \docparam{file
}{the name of the source file where the assert occured
}
287 \docparam{line
}{the line number in this file where the assert occured
}
289 \docparam{cond
}{the condition of the failed assert in string form
}
291 \docparam{msg
}{the message specified as argument to
292 \helpref{wxASSERT
\_MSG}{wxassertmsg
} or
\helpref{wxFAIL
\_MSG}{wxfailmsg
}, will
293 be
{\tt NULL
} if just
\helpref{wxASSERT
}{wxassert
} or
\helpref{wxFAIL
}{wxfail
}
297 \membersection{wxApp::OnCmdLineError
}\label{wxapponcmdlineerror
}
299 \func{bool
}{OnCmdLineError
}{\param{wxCmdLineParser\&
}{parser
}}
301 Called when command line parsing fails (i.e. an incorrect command line option
302 was specified by the user). The default behaviour is to show the program usage
303 text and abort the program.
305 Return
{\tt true
} to continue normal execution or
{\tt false
} to return
306 {\tt false
} from
\helpref{OnInit
}{wxapponinit
} thus terminating the program.
310 \helpref{OnInitCmdLine
}{wxapponinitcmdline
}
313 \membersection{wxApp::OnCmdLineHelp
}\label{wxapponcmdlinehelp
}
315 \func{bool
}{OnCmdLineHelp
}{\param{wxCmdLineParser\&
}{parser
}}
317 Called when the help option (
{\tt --help
}) was specified on the command line.
318 The default behaviour is to show the program usage text and abort the program.
320 Return
{\tt true
} to continue normal execution or
{\tt false
} to return
321 {\tt false
} from
\helpref{OnInit
}{wxapponinit
} thus terminating the program.
325 \helpref{OnInitCmdLine
}{wxapponinitcmdline
}
328 \membersection{wxApp::OnCmdLineParsed
}\label{wxapponcmdlineparsed
}
330 \func{bool
}{OnCmdLineParsed
}{\param{wxCmdLineParser\&
}{parser
}}
332 Called after the command line had been successfully parsed. You may override
333 this method to test for the values of the various parameters which could be
334 set from the command line.
336 Don't forget to call the base class version unless you want to suppress
337 processing of the standard command line options.
339 Return
{\tt true
} to continue normal execution or
{\tt false
} to return
340 {\tt false
} from
\helpref{OnInit
}{wxapponinit
} thus terminating the program.
344 \helpref{OnInitCmdLine
}{wxapponinitcmdline
}
347 \membersection{wxApp::OnExceptionInMainLoop
}\label{wxapponexceptioninmainloop
}
349 \func{virtual bool
}{OnExceptionInMainLoop
}{\void}
351 This function is called if an unhandled exception occurs inside the main
352 application event loop. It can return
\true to ignore the exception and to
353 continue running the loop or
\false to exit the loop and terminate the
354 program. In the latter case it can also use C++
\texttt{throw
} keyword to
355 rethrow the current exception.
357 The default behaviour of this function is the latter in all ports except under
358 Windows where a dialog is shown to the user which allows him to choose between
359 the different options. You may override this function in your class to do
360 something more appropriate.
362 Finally note that if the exception is rethrown from here, it can be caught in
363 \helpref{OnUnhandledException
}{wxapponunhandledexception
}.
366 \membersection{wxApp::OnExit
}\label{wxapponexit
}
368 \func{virtual int
}{OnExit
}{\void}
370 Override this member function for any processing which needs to be
371 done as the application is about to exit. OnExit is called after
372 destroying all application windows and controls, but before
373 wxWidgets cleanup. Note that it is not called at all if
374 \helpref{OnInit
}{wxapponinit
} failed.
376 The return value of this function is currently ignored, return the same value
377 as returned by the base class method if you override it.
380 \membersection{wxApp::OnFatalException
}\label{wxapponfatalexception
}
382 \func{void
}{OnFatalException
}{\void}
384 This function may be called if something fatal happens: an unhandled
385 exception under Win32 or a a fatal signal under Unix, for example. However,
386 this will not happen by default: you have to explicitly call
387 \helpref{wxHandleFatalExceptions
}{wxhandlefatalexceptions
} to enable this.
389 Generally speaking, this function should only show a message to the user and
390 return. You may attempt to save unsaved data but this is not guaranteed to
391 work and, in fact, probably won't.
395 \helpref{wxHandleFatalExceptions
}{wxhandlefatalexceptions
}
397 %% VZ: the wxApp event handler are private and should not be documented here!
399 %%\membersection{wxApp::OnIdle}\label{wxapponidle}
401 %%\func{void}{OnIdle}{\param{wxIdleEvent\& }{event}}
403 %%Override this member function for any processing which needs to be done
404 %%when the application is idle. You should call wxApp::OnIdle from your own function,
405 %%since this forwards OnIdle events to windows and also performs garbage collection for
406 %%windows whose destruction has been delayed.
408 %%wxWidgets' strategy for OnIdle processing is as follows. After pending user interface events for an
409 %%application have all been processed, wxWidgets sends an OnIdle event to the application object. wxApp::OnIdle itself
410 %%sends an OnIdle event to each application window, allowing windows to do idle processing such as updating
411 %%their appearance. If either wxApp::OnIdle or a window OnIdle function requested more time, by
412 %%calling \helpref{wxIdleEvent::RequestMore}{wxidleeventrequestmore}, wxWidgets will send another OnIdle
413 %%event to the application object. This will occur in a loop until either a user event is found to be
414 %%pending, or OnIdle requests no more time. Then all pending user events are processed until the system
415 %%goes idle again, when OnIdle is called, and so on.
417 %%\wxheading{See also}
419 %%\helpref{wxWindow::OnIdle}{wxwindowonidle}, \helpref{wxIdleEvent}{wxidleevent},\rtfsp
420 %%\helpref{wxWindow::SendIdleEvents}{wxappsendidleevents}
422 %%\membersection{wxApp::OnEndSession}\label{wxapponendsession}
424 %%\func{void}{OnEndSession}{\param{wxCloseEvent\& }{event}}
426 %%This is an event handler function called when the operating system or GUI session is
427 %%about to close down. The application has a chance to silently save information,
428 %%and can optionally close itself.
430 %%Use the EVT\_END\_SESSION event table macro to handle query end session events.
432 %%The default handler calls \helpref{wxWindow::Close}{wxwindowclose} with a true argument
433 %%(forcing the application to close itself silently).
435 %%\wxheading{Remarks}
437 %%Under X, OnEndSession is called in response to the `die' event.
439 %%Under Windows, OnEndSession is called in response to the WM\_ENDSESSION message.
441 %%\wxheading{See also}
443 %%\helpref{wxWindow::Close}{wxwindowclose},\rtfsp
444 %%\helpref{wxWindow::OnCloseWindow}{wxwindowonclosewindow},\rtfsp
445 %%\helpref{wxCloseEvent}{wxcloseevent},\rtfsp
448 \membersection{wxApp::OnInit
}\label{wxapponinit
}
450 \func{bool
}{OnInit
}{\void}
452 This must be provided by the application, and will usually create the
453 application's main window, optionally calling
454 \helpref{wxApp::SetTopWindow
}{wxappsettopwindow
}. You may use
455 \helpref{OnExit
}{wxapponexit
} to clean up anything initialized here, provided
456 that the function returns
\true.
458 Notice that if you want to to use the command line processing provided by
459 wxWidgets you have to call the base class version in the derived class
462 Return
\true to continue processing,
\false to exit the application
466 \membersection{wxApp::OnInitCmdLine
}\label{wxapponinitcmdline
}
468 \func{void
}{OnInitCmdLine
}{\param{wxCmdLineParser\&
}{parser
}}
470 Called from
\helpref{OnInit
}{wxapponinit
} and may be used to initialize the
471 parser with the command line options for this application. The base class
472 versions adds support for a few standard options only.
474 \membersection{wxApp::OnRun
}\label{wxapponrun
}
476 \func{virtual int
}{OnRun
}{\void}
478 This virtual function is where the execution of a program written in wxWidgets
479 starts. The default implementation just enters the main loop and starts
480 handling the events until it terminates, either because
481 \helpref{ExitMainLoop
}{wxappexitmainloop
} has been explicitly called or because
482 the last frame has been deleted and
483 \helpref{GetExitOnFrameDelete
}{wxappgetexitonframedelete
} flag is
\true (this
486 The return value of this function becomes the exit code of the program, so it
487 should return $
0$ in case of successful termination.
490 \membersection{wxApp::OnUnhandledException
}\label{wxapponunhandledexception
}
492 \func{virtual void
}{OnUnhandledException
}{\void}
494 This function is called when an unhandled C++ exception occurs inside
495 \helpref{OnRun()
}{wxapponrun
} (the exceptions which occur during the program
496 startup and shutdown might not be caught at all).
497 Note that the exception type is lost by now, so if you want to really handle
498 the exception you should override
\helpref{OnRun()
}{wxapponrun
} and put a
499 try/catch clause around the call to the base class version there.
502 \membersection{wxApp::ProcessMessage
}\label{wxappprocessmessage
}
504 \func{bool
}{ProcessMessage
}{\param{WXMSG *
}{msg
}}
506 Windows-only function for processing a message. This function
507 is called from the main message loop, checking for windows that
508 may wish to process it. The function returns true if the message
509 was processed, false otherwise. If you use wxWidgets with another class
510 library with its own message loop, you should make sure that this
511 function is called to allow wxWidgets to receive messages. For example,
512 to allow co-existence with the Microsoft Foundation Classes, override
513 the PreTranslateMessage function:
516 // Provide wxWidgets message loop compatibility
517 BOOL CTheApp::PreTranslateMessage(MSG *msg)
519 if (wxTheApp && wxTheApp->ProcessMessage((WXMSW *)msg))
522 return CWinApp::PreTranslateMessage(msg);
527 \membersection{wxApp::Pending
}\label{wxapppending
}
529 \func{virtual bool
}{Pending
}{\void}
531 Returns true if unprocessed events are in the window system event queue.
535 \helpref{wxApp::Dispatch
}{wxappdispatch
}
538 \membersection{wxApp::SendIdleEvents
}\label{wxappsendidleevents
}
540 \func{bool
}{SendIdleEvents
}{\param{wxWindow*
}{ win
},
\param{wxIdleEvent\&
}{event
}}
542 Sends idle events to a window and its children.
544 Please note that this function is internal to wxWidgets and shouldn't be used
549 These functions poll the top-level windows, and their children, for idle event processing.
550 If true is returned, more OnIdle processing is requested by one or more window.
554 \helpref{wxIdleEvent
}{wxidleevent
}
557 \membersection{wxApp::SetAppName
}\label{wxappsetappname
}
559 \func{void
}{SetAppName
}{\param{const wxString\&
}{name
}}
561 Sets the name of the application. The name may be used in dialogs
562 (for example by the
document/view framework). A default name is set by
567 \helpref{wxApp::GetAppName
}{wxappgetappname
}
570 \membersection{wxApp::SetClassName
}\label{wxappsetclassname
}
572 \func{void
}{SetClassName
}{\param{const wxString\&
}{name
}}
574 Sets the class name of the application. This may be used in a platform specific
575 manner to refer to the application.
579 \helpref{wxApp::GetClassName
}{wxappgetclassname
}
582 \membersection{wxApp::SetExitOnFrameDelete
}\label{wxappsetexitonframedelete
}
584 \func{void
}{SetExitOnFrameDelete
}{\param{bool
}{ flag
}}
586 Allows the programmer to specify whether the application will exit when the
587 top-level frame is deleted.
589 \wxheading{Parameters
}
591 \docparam{flag
}{If true (the default), the application will exit when the top-level frame is
592 deleted. If false, the application will continue to run.
}
596 \helpref{wxApp::GetExitOnFrameDelete
}{wxappgetexitonframedelete
},\\
597 \helpref{wxApp shutdown overview
}{wxappshutdownoverview
}
600 \membersection{wxApp::SetInstance
}\label{wxappsetinstance
}
602 \func{static void
}{SetInstance
}{\param{wxAppConsole*
}{app
}}
604 Allows external code to modify global
\texttt{wxTheApp
}, but you should really
605 know what you're doing if you call it.
607 \wxheading{Parameters
}
609 \docparam{app
}{Replacement for the global application object.
}
613 \helpref{wxApp::GetInstance
}{wxappgetinstance
}
616 \membersection{wxApp::SetTopWindow
}\label{wxappsettopwindow
}
618 \func{void
}{SetTopWindow
}{\param{wxWindow*
}{window
}}
620 Sets the `top' window. You can call this from within
\helpref{wxApp::OnInit
}{wxapponinit
} to
621 let wxWidgets know which is the main window. You don't have to set the top window;
622 it is only a convenience so that (for example) certain dialogs without parents can use a
623 specific window as the top window. If no top window is specified by the application,
624 wxWidgets just uses the first frame or dialog in its top-level window list, when it
625 needs to use the top window.
627 \wxheading{Parameters
}
629 \docparam{window
}{The new top window.
}
633 \helpref{wxApp::GetTopWindow
}{wxappgettopwindow
},
\helpref{wxApp::OnInit
}{wxapponinit
}
637 \membersection{wxApp::SetVendorName
}\label{wxappsetvendorname
}
639 \func{void
}{SetVendorName
}{\param{const wxString\&
}{name
}}
641 Sets the name of application's vendor. The name will be used
642 in registry access. A default name is set by
647 \helpref{wxApp::GetVendorName
}{wxappgetvendorname
}
650 \membersection{wxApp::SetUseBestVisual
}\label{wxappsetusebestvisual
}
652 \func{void
}{SetUseBestVisual
}{\param{bool
}{ flag
}}
654 Allows the programmer to specify whether the application will use the best visual
655 on systems that support several visual on the same display. This is typically the
656 case under Solaris and IRIX, where the default visual is only
8-bit whereas certain
657 applications are supposed to run in TrueColour mode.
659 Note that this function has to be called in the constructor of the
{\tt wxApp
}
660 instance and won't have any effect when called later on.
662 This function currently only has effect under GTK.
664 \wxheading{Parameters
}
666 \docparam{flag
}{If true, the app will use the best visual.
}
669 \membersection{wxApp::HandleEvent
}\label{wxapphandleevent
}
671 \constfunc{virtual void
}{HandleEvent
}{\param{wxEvtHandler
}{ *handler
},
\param{wxEventFunction
}{ func
},
\param{wxEvent\&
}{event
}}
673 This function simply invokes the given method
\arg{func
} of the specified
674 event handler
\arg{handler
} with the
\arg{event
} as parameter. It exists solely
675 to allow to catch the C++ exceptions which could be thrown by all event
676 handlers in the application in one place: if you want to do this, override this
677 function in your wxApp-derived class and add try/catch clause(s) to it.
680 \membersection{wxApp::Yield
}\label{wxappyield
}
682 \func{bool
}{Yield
}{\param{bool
}{ onlyIfNeeded = false
}}
684 Yields control to pending messages in the windowing system. This can be useful, for example, when a
685 time-consuming process writes to a text window. Without an occasional
686 yield, the text window will not be updated properly, and on systems with
687 cooperative multitasking, such as Windows
3.1 other processes will not respond.
689 Caution should be exercised, however, since yielding may allow the
690 user to perform actions which are not compatible with the current task.
691 Disabling menu items or whole menus during processing can avoid unwanted
692 reentrance of code: see
\helpref{::wxSafeYield
}{wxsafeyield
} for a better
695 Note that Yield() will not flush the message logs. This is intentional as
696 calling Yield() is usually done to quickly update the screen and popping up a
697 message box dialog may be undesirable. If you do wish to flush the log
698 messages immediately (otherwise it will be done during the next idle loop
699 iteration), call
\helpref{wxLog::FlushActive
}{wxlogflushactive
}.
701 Calling Yield() recursively is normally an error and an assert failure is
702 raised in debug build if such situation is detected. However if the the
703 {\it onlyIfNeeded
} parameter is
{\tt true
}, the method will just silently
704 return
{\tt false
} instead.