| Version: 3.2.8

Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | List of all members
wxAppConsole Class Reference
Class List by Category » Application and Process Management

`#include <wx/app.h>`

Inheritance diagram for wxAppConsole:
[legend]

## Detailed Description

This class is essential for writing console-only or hybrid apps without having to define `wxUSE_GUI=0`.

It is used to:

- set and get application-wide properties (see wxAppConsole::CreateTraits and wxAppConsole::SetXXX functions)
- implement the windowing system message or event loop: events in fact are supported even in console-mode applications (see wxAppConsole::HandleEvent and wxAppConsole::ProcessPendingEvents);
- initiate application processing via wxApp::OnInit;
- allow default processing of events not handled by other objects in the application (see wxAppConsole::FilterEvent)
- implement Apple-specific event handlers (see wxAppConsole::MacXXX functions)

You should use the macro wxIMPLEMENT_APP(appClass) in your application implementation file to tell wxWidgets how to create an instance of your application class.

Use wxDECLARE_APP(appClass) in a header file if you want the wxGetApp() function (which returns a reference to your application object) to be visible to other files.

##

Library: wxBase
Category: Application and Process Management

See also
  wxApp Overview, wxApp, wxAppTraits, wxEventLoopBase

## Public Member Functions
virtual | ~wxAppConsole ()
| Destructor. More...
bool | Yield (bool onlyIfNeeded=false)
| Yields control to pending messages in the event loop. More...
void | SetCLocale ()
| Sets the C locale to the default locale for the current environment. More...
void | SetErrorExitCode (int code)
| Sets the error code to use in case of exit on error. More...
Event-handling
Note that you should look at wxEvtLoopBase for more event-processing documentation.
virtual int | MainLoop ()
| Called by wxWidgets on creation of the application. More...
virtual void | ExitMainLoop ()
| Call this to explicitly exit the main message (event) loop. More...
virtual int | FilterEvent (wxEvent &event)
| Overridden wxEventFilter method. More...
wxEventLoopBase * | GetMainLoop () const
| Returns the main event loop instance, i.e. the event loop which is started by OnRun() and which dispatches all events sent from the native toolkit to the application (except when new event loops are temporarily set-up). More...
virtual void | HandleEvent (wxEvtHandler *handler, wxEventFunction func, wxEvent &event) const
| This function simply invokes the given method func of the specified event handler handler with the event as parameter. More...
virtual bool | UsesEventLoop () const
| Returns true if the application is using an event loop. More...
Pending events
Pending events are handled by wxAppConsole rather than wxEventLoopBase to allow queuing of events even when there's no event loop (e.g. in wxAppConsole::OnInit).
virtual void | ProcessPendingEvents ()
| Process all pending events; it is necessary to call this function to process events posted with wxEvtHandler::QueueEvent or wxEvtHandler::AddPendingEvent. More...
void | DeletePendingEvents ()
| Deletes the pending events of all wxEvtHandlers of this application. More...
bool | HasPendingEvents () const
| Returns true if there are pending events on the internal pending event list. More...
void | SuspendProcessingOfPendingEvents ()
| Temporary suspends processing of the pending events. More...
void | ResumeProcessingOfPendingEvents ()
| Resume processing of the pending events previously stopped because of a call to SuspendProcessingOfPendingEvents(). More...
void | ScheduleForDestruction (wxObject *object)
| Delayed objects destruction. More...
bool | IsScheduledForDestruction (wxObject *object) const
| Check if the object had been scheduled for destruction with ScheduleForDestruction(). More...
Callbacks for application-wide "events"
virtual void | OnAssertFailure (const wxChar *file, int line, const wxChar *func, const wxChar *cond, const wxChar *msg)
| This function is called when an assert failure occurs, i.e. the condition specified in wxASSERT() macro evaluated to false. More...
virtual bool | OnCmdLineError (wxCmdLineParser &parser)
| Called when command line parsing fails (i.e. an incorrect command line option was specified by the user). More...
virtual bool | OnCmdLineHelp (wxCmdLineParser &parser)
| Called when the help option (`--help`) was specified on the command line. More...
virtual bool | OnCmdLineParsed (wxCmdLineParser &parser)
| Called after the command line had been successfully parsed. More...
virtual void | OnEventLoopEnter (wxEventLoopBase *loop)
| Called by wxEventLoopBase::SetActive(): you can override this function and put here the code which needs an active event loop. More...
virtual void | OnEventLoopExit (wxEventLoopBase *loop)
| Called by wxEventLoopBase::OnExit() for each event loop which is exited. More...
virtual int | OnExit ()
| Override this member function for any processing which needs to be done as the application is about to exit. More...
virtual void | OnFatalException ()
| This function may be called if something fatal happens: an unhandled exception under Win32 or a fatal signal under Unix, for example. More...
virtual bool | OnInit ()
| This must be provided by the application, and will usually create the application's main window, optionally calling SetTopWindow(). More...
virtual void | OnInitCmdLine (wxCmdLineParser &parser)
| Called from OnInit() and may be used to initialize the parser with the command line options for this application. More...
virtual int | OnRun ()
| This virtual function is where the execution of a program written in wxWidgets starts. More...
Exceptions support
Methods related to C++ exceptions handling. See also overview_exceptions
virtual bool | OnExceptionInMainLoop ()
| This function is called if an unhandled exception occurs inside the main application event loop. More...
virtual void | OnUnhandledException ()
| This function is called when an unhandled C++ exception occurs in user code called by wxWidgets. More...
virtual bool | StoreCurrentException ()
| Method to store exceptions not handled by OnExceptionInMainLoop(). More...
virtual void | RethrowStoredException ()
| Method to rethrow exceptions stored by StoreCurrentException(). More...
Application information
wxString | GetAppDisplayName () const
| Returns the user-readable application name. More...
wxString | GetAppName () const
| Returns the application name. More...
wxString | GetClassName () const
| Gets the class name of the application. More...
wxAppTraits * | GetTraits ()
| Returns a pointer to the wxAppTraits object for the application. More...
const wxString & | GetVendorDisplayName () const
| Returns the user-readable vendor name. More...
const wxString & | GetVendorName () const
| Returns the application's vendor name. More...
void | SetAppDisplayName (const wxString &name)
| Set the application name to be used in the user-visible places such as window titles. More...
void | SetAppName (const wxString &name)
| Sets the name of the application. More...
void | SetClassName (const wxString &name)
| Sets the class name of the application. More...
void | SetVendorDisplayName (const wxString &name)
| Set the vendor name to be used in the user-visible places. More...
void | SetVendorName (const wxString &name)
| Sets the name of application's vendor. More...
Public Member Functions inherited from wxEvtHandler
| wxEvtHandler ()
| Constructor. More...
virtual | ~wxEvtHandler ()
| Destructor. More...
virtual void | QueueEvent (wxEvent *event)
| Queue event for a later processing. More...
virtual void | AddPendingEvent (const wxEvent &event)
| Post an event to be processed later. More...
template<typename T , typename T1 , ... >
void | CallAfter (void(T::*method)(T1,...), T1 x1,...)
| Asynchronously call the given method. More...
template<typename T >
void | CallAfter (const T &functor)
| Asynchronously call the given functor. More...
virtual bool | ProcessEvent (wxEvent &event)
| Processes an event, searching event tables and calling zero or more suitable event handler function(s). More...
bool | ProcessEventLocally (wxEvent &event)
| Try to process the event in this handler and all those chained to it. More...
bool | SafelyProcessEvent (wxEvent &event)
| Processes an event by calling ProcessEvent() and handles any exceptions that occur in the process. More...
void | ProcessPendingEvents ()
| Processes the pending events previously queued using QueueEvent() or AddPendingEvent(); you must call this function only if you are sure there are pending events for this handler, otherwise a `wxCHECK` will fail. More...
void | DeletePendingEvents ()
| Deletes all events queued on this event handler using QueueEvent() or AddPendingEvent(). More...
void | Connect (int id, int lastId, wxEventType eventType, wxObjectEventFunction function, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL)
| Connects the given function dynamically with the event handler, id and event type. More...
void | Connect (int id, wxEventType eventType, wxObjectEventFunction function, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL)
| See the Connect(int, int, wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info. More...
void | Connect (wxEventType eventType, wxObjectEventFunction function, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL)
| See the Connect(int, int, wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info. More...
bool | Disconnect (wxEventType eventType, wxObjectEventFunction function, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL)
| Disconnects the given function dynamically from the event handler, using the specified parameters as search criteria and returning true if a matching function has been found and removed. More...
bool | Disconnect (int id=wxID_ANY, wxEventType eventType=wxEVT_NULL, wxObjectEventFunction function=NULL, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL)
| See the Disconnect(wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info. More...
bool | Disconnect (int id, int lastId, wxEventType eventType, wxObjectEventFunction function=NULL, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL)
| See the Disconnect(wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info. More...
template<typename EventTag , typename Functor >
void | Bind (const EventTag &eventType, Functor functor, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=NULL)
| Binds the given function, functor or method dynamically with the event. More...
template<typename EventTag , typename Class , typename EventArg , typename EventHandler >
void | Bind (const EventTag &eventType, void(Class::*method)(EventArg &), EventHandler *handler, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=NULL)
| See the Bind<>(const EventTag&, Functor, int, int, wxObject*) overload for more info. More...
template<typename EventTag , typename Functor >
bool | Unbind (const EventTag &eventType, Functor functor, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=NULL)
| Unbinds the given function, functor or method dynamically from the event handler, using the specified parameters as search criteria and returning true if a matching function has been found and removed. More...
template<typename EventTag , typename Class , typename EventArg , typename EventHandler >
bool | Unbind (const EventTag &eventType, void(Class::*method)(EventArg &), EventHandler *handler, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=NULL)
| See the Unbind<>(const EventTag&, Functor, int, int, wxObject*) overload for more info. More...
void * | GetClientData () const
| Returns user-supplied client data. More...
wxClientData * | GetClientObject () const
| Returns a pointer to the user-supplied client data object. More...
void | SetClientData (void *data)
| Sets user-supplied client data. More...
void | SetClientObject (wxClientData *data)
| Set the client data object. More...
bool | GetEvtHandlerEnabled () const
| Returns true if the event handler is enabled, false otherwise. More...
wxEvtHandler * | GetNextHandler () const
| Returns the pointer to the next handler in the chain. More...
wxEvtHandler * | GetPreviousHandler () const
| Returns the pointer to the previous handler in the chain. More...
void | SetEvtHandlerEnabled (bool enabled)
| Enables or disables the event handler. More...
virtual void | SetNextHandler (wxEvtHandler *handler)
| Sets the pointer to the next handler. More...
virtual void | SetPreviousHandler (wxEvtHandler *handler)
| Sets the pointer to the previous handler. More...
void | Unlink ()
| Unlinks this event handler from the chain it's part of (if any); then links the "previous" event handler to the "next" one (so that the chain won't be interrupted). More...
bool | IsUnlinked () const
| Returns true if the next and the previous handler pointers of this event handler instance are NULL. More...
Public Member Functions inherited from wxObject
| wxObject ()
| Default ctor; initializes to NULL the internal reference data. More...
| wxObject (const wxObject &other)
| Copy ctor. More...
virtual | ~wxObject ()
| Destructor. More...
virtual wxClassInfo * | GetClassInfo () const
| This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar). More...
wxObjectRefData * | GetRefData () const
| Returns the wxObject::m_refData pointer, i.e. the data referenced by this object. More...
bool | IsKindOf (const wxClassInfo *info) const
| Determines whether this class is a subclass of (or the same class as) the given class. More...
bool | IsSameAs (const wxObject &obj) const
| Returns true if this object has the same data pointer as obj. More...
void | Ref (const wxObject &clone)
| Makes this object refer to the data in clone. More...
void | SetRefData (wxObjectRefData *data)
| Sets the wxObject::m_refData pointer. More...
void | UnRef ()
| Decrements the reference count in the associated data, and if it is zero, deletes the data. More...
void | UnShare ()
| This is the same of AllocExclusive() but this method is public. More...
void | operator delete (void *buf)
| The delete operator is defined for debugging versions of the library only, when the identifier `__WXDEBUG__` is defined. More...
void * | operator new (size_t size, const wxString &filename=NULL, int lineNum=0)
| The new operator is defined for debugging versions of the library only, when the identifier `__WXDEBUG__` is defined. More...
Public Member Functions inherited from wxEventFilter
| wxEventFilter ()
| Default constructor. More...
virtual | ~wxEventFilter ()
| Destructor. More...

## Static Public Member Functions
static void | SetInstance (wxAppConsole *app)
| Allows external code to modify global wxTheApp, but you should really know what you're doing if you call it. More...
static wxAppConsole * | GetInstance ()
| Returns the one and only global application object. More...
static bool | IsMainLoopRunning ()
| Returns true if the main event loop is currently running, i.e. if the application is inside OnRun(). More...
Static Public Member Functions inherited from wxEvtHandler
static void | AddFilter (wxEventFilter *filter)
| Add an event filter whose FilterEvent() method will be called for each and every event processed by wxWidgets. More...
static void | RemoveFilter (wxEventFilter *filter)
| Remove a filter previously installed with AddFilter(). More...

## Public Attributes
int | argc
| Number of command line arguments (after environment-specific processing). More...
wxChar ** | argv
| Command line arguments (after environment-specific processing). More...

## Protected Member Functions
virtual wxAppTraits * | CreateTraits ()
| Creates the wxAppTraits object when GetTraits() needs it for the first time. More...
Protected Member Functions inherited from wxEvtHandler
virtual bool | TryBefore (wxEvent &event)
| Method called by ProcessEvent() before examining this object event tables. More...
virtual bool | TryAfter (wxEvent &event)
| Method called by ProcessEvent() as last resort. More...
Protected Member Functions inherited from wxObject
void | AllocExclusive ()
| Ensure that this object's data is not shared with any other object. More...
virtual wxObjectRefData * | CreateRefData () const
| Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it. More...
virtual wxObjectRefData * | CloneRefData (const wxObjectRefData *data) const
| Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data. More...

## Additional Inherited Members
Public Types inherited from wxEventFilter
enum | { Event_Skip = -1 , Event_Ignore = 0 , Event_Processed = 1 }
| Possible return values for FilterEvent(). More...
Protected Attributes inherited from wxObject
wxObjectRefData * | m_refData
| Pointer to an object which is the object's reference-counted data. More...

## Constructor & Destructor Documentation

## ◆ ~wxAppConsole()

virtual wxAppConsole::~wxAppConsole | ( |  | ) |
| virtual

Destructor.

## Member Function Documentation

## ◆ CreateTraits()

virtual wxAppTraits* wxAppConsole::CreateTraits | ( |  | ) |
| protected virtual

Creates the wxAppTraits object when GetTraits() needs it for the first time.

See also
  wxAppTraits

## ◆ DeletePendingEvents()

void wxAppConsole::DeletePendingEvents | ( |  | ) |

Deletes the pending events of all wxEvtHandlers of this application.

See wxEvtHandler::DeletePendingEvents() for warnings about deleting the pending events.

## ◆ ExitMainLoop()

virtual void wxAppConsole::ExitMainLoop | ( |  | ) |
| virtual

Call this to explicitly exit the main message (event) loop.

You should normally exit the main loop (and the application) by deleting the top window.

This function simply calls wxEvtLoopBase::Exit() on the active loop.

## ◆ FilterEvent()

virtual int wxAppConsole::FilterEvent | ( | wxEvent & | event | ) |
| virtual

Overridden wxEventFilter method.

This function is called before processing any event and allows the application to preempt the processing of some events, see wxEventFilter documentation for more information.

wxApp implementation of this method always return -1 indicating that the event should be processed normally.

Implements wxEventFilter.

## ◆ GetAppDisplayName()

wxString wxAppConsole::GetAppDisplayName | ( |  | ) | const

Returns the user-readable application name.

The difference between this string and the one returned by GetAppName() is that this one is meant to be shown to the user and so should be used for the window titles, page headers and so on while the other one should be only used internally, e.g. for the file names or configuration file keys.

If the application name for display had been previously set by SetAppDisplayName(), it will be returned by this function. Otherwise, if SetAppName() had been called its value will be returned; also as is. Finally if none was called, this function returns the program name capitalized using wxString::Capitalize().

Since
  2.9.0

## ◆ GetAppName()

wxString wxAppConsole::GetAppName | ( |  | ) | const

Returns the application name.

If SetAppName() had been called, returns the string passed to it. Otherwise returns the program name, i.e. the value of `argv`[0] passed to the `main()` function.

See also
  GetAppDisplayName()

## ◆ GetClassName()

wxString wxAppConsole::GetClassName | ( |  | ) | const

Gets the class name of the application.

The class name may be used in a platform specific manner to refer to the application.

See also
  SetClassName()

## ◆ GetInstance()

static wxAppConsole* wxAppConsole::GetInstance | ( |  | ) |
| static

Returns the one and only global application object.

Usually wxTheApp is used instead.

See also
  SetInstance(), wxApp::GetGUIInstance()

## ◆ GetMainLoop()

wxEventLoopBase* wxAppConsole::GetMainLoop | ( |  | ) | const

Returns the main event loop instance, i.e. the event loop which is started by OnRun() and which dispatches all events sent from the native toolkit to the application (except when new event loops are temporarily set-up).

The returned value maybe NULL. Put initialization code which needs a non-NULL main event loop into OnEventLoopEnter().

## ◆ GetTraits()

wxAppTraits* wxAppConsole::GetTraits | ( |  | ) |

Returns a pointer to the wxAppTraits object for the application.

If you want to customize the wxAppTraits object, you must override the CreateTraits() function.

## ◆ GetVendorDisplayName()

const wxString& wxAppConsole::GetVendorDisplayName | ( |  | ) | const

Returns the user-readable vendor name.

The difference between this string and the one returned by GetVendorName() is that this one is meant to be shown to the user and so should be used for the window titles, page headers and so on while the other one should be only used internally, e.g. for the file names or configuration file keys.

By default, returns the same string as GetVendorName().

Since
  2.9.0

## ◆ GetVendorName()

const wxString& wxAppConsole::GetVendorName | ( |  | ) | const

Returns the application's vendor name.

## ◆ HandleEvent()

virtual void wxAppConsole::HandleEvent | ( | wxEvtHandler * | handler,
|  | wxEventFunction | func,
|  | wxEvent & | event
| ) |  | const
| virtual

This function simply invokes the given method func of the specified event handler handler with the event as parameter.

It exists solely to allow to catch the C++ exceptions which could be thrown by all event handlers in the application in one place: if you want to do this, override this function in your wxApp-derived class and add try/catch clause(s) to it.

## ◆ HasPendingEvents()

bool wxAppConsole::HasPendingEvents | ( |  | ) | const

Returns true if there are pending events on the internal pending event list.

Whenever wxEvtHandler::QueueEvent or wxEvtHandler::AddPendingEvent() are called (not only for wxApp itself, but for any event handler of the application!), the internal wxApp's list of handlers with pending events is updated and this function will return true.

## ◆ IsMainLoopRunning()

static bool wxAppConsole::IsMainLoopRunning | ( |  | ) |
| static

Returns true if the main event loop is currently running, i.e. if the application is inside OnRun().

This can be useful to test whether events can be dispatched. For example, if this function returns false, non-blocking sockets cannot be used because the events from them would never be processed.

## ◆ IsScheduledForDestruction()

bool wxAppConsole::IsScheduledForDestruction | ( | wxObject * | object | ) | const

Check if the object had been scheduled for destruction with ScheduleForDestruction().

This function may be useful as an optimization to avoid doing something with an object which will be soon destroyed in any case.

## ◆ MainLoop()

virtual int wxAppConsole::MainLoop | ( |  | ) |
| virtual

Called by wxWidgets on creation of the application.

Override this if you wish to provide your own (environment-dependent) main loop.

Returns
  0 under X, and the wParam of the WM_QUIT message under Windows.

## ◆ OnAssertFailure()

virtual void wxAppConsole::OnAssertFailure | ( | const wxChar * | file,
|  | int | line,
|  | const wxChar * | func,
|  | const wxChar * | cond,
|  | const wxChar * | msg
| ) |  |
| virtual

This function is called when an assert failure occurs, i.e. the condition specified in wxASSERT() macro evaluated to false.

It is only called in debug mode (when `__WXDEBUG__` is defined) as asserts are not left in the release code at all. The base class version shows the default assert failure dialog box proposing to the user to stop the program, continue or ignore all subsequent asserts.

Parameters

  file | the name of the source file where the assert occurred
  line | the line number in this file where the assert occurred
  func | the name of the function where the assert occurred, may be empty if the compiler doesn't support C99 __FUNCTION__
  cond | the condition of the failed assert in text form
  msg | the message specified as argument to wxASSERT_MSG or wxFAIL_MSG, will be NULL if just wxASSERT or wxFAIL was used

## ◆ OnCmdLineError()

virtual bool wxAppConsole::OnCmdLineError | ( | wxCmdLineParser & | parser | ) |
| virtual

Called when command line parsing fails (i.e. an incorrect command line option was specified by the user).

The default behaviour is to show the program usage text and abort the program.

Return true to continue normal execution or false to return false from OnInit() thus terminating the program.

See also
  OnInitCmdLine()

## ◆ OnCmdLineHelp()

virtual bool wxAppConsole::OnCmdLineHelp | ( | wxCmdLineParser & | parser | ) |
| virtual

Called when the help option (`--help`) was specified on the command line.

The default behaviour is to show the program usage text and abort the program.

Return true to continue normal execution or false to return false from OnInit() thus terminating the program.

See also
  OnInitCmdLine()

## ◆ OnCmdLineParsed()

virtual bool wxAppConsole::OnCmdLineParsed | ( | wxCmdLineParser & | parser | ) |
| virtual

Called after the command line had been successfully parsed.

You may override this method to test for the values of the various parameters which could be set from the command line.

Don't forget to call the base class version unless you want to suppress processing of the standard command line options. Return true to continue normal execution or false to return false from OnInit() thus terminating the program.

See also
  OnInitCmdLine()

## ◆ OnEventLoopEnter()

virtual void wxAppConsole::OnEventLoopEnter | ( | wxEventLoopBase * | loop | ) |
| virtual

Called by wxEventLoopBase::SetActive(): you can override this function and put here the code which needs an active event loop.

Note that this function is called whenever an event loop is activated; you may want to use wxEventLoopBase::IsMain() to perform initialization specific for the app's main event loop.

See also
  OnEventLoopExit()

## ◆ OnEventLoopExit()

virtual void wxAppConsole::OnEventLoopExit | ( | wxEventLoopBase * | loop | ) |
| virtual

Called by wxEventLoopBase::OnExit() for each event loop which is exited.

See also
  OnEventLoopEnter()

## ◆ OnExceptionInMainLoop()

virtual bool wxAppConsole::OnExceptionInMainLoop | ( |  | ) |
| virtual

This function is called if an unhandled exception occurs inside the main application event loop.

It can return true to ignore the exception and to continue running the loop or false to exit the loop and terminate the program.

The default behaviour of this function is the latter in all ports except under Windows where a dialog is shown to the user which allows him to choose between the different options. You may override this function in your class to do something more appropriate.

If this method rethrows the exception and if the exception can't be stored for later processing using StoreCurrentException(), the program will terminate after calling OnUnhandledException().

You should consider overriding this method to perform whichever last resort exception handling that would be done in a typical C++ program in a `try/catch` block around the entire `main()` function. As this method is called during exception handling, you may use the C++ `throw` keyword to rethrow the current exception to catch it again and analyze it. For example:

class MyApp : public wxApp {
public:
virtual bool OnExceptionInMainLoop()
{
wxString error;
try {
throw; // Rethrow the current exception.
} catch (const MyException& e) {
error = e.GetMyErrorMessage();
} catch (const std::exception& e) {
error = e.what();
} catch ( ... ) {
error = "unknown error.";
}
wxLogError("Unexpected exception has occurred: %s, the program will terminate.", error);
// Exit the main loop and thus terminate the program.
return false;
}
};
wxAppConsole::OnExceptionInMainLoop
virtual bool OnExceptionInMainLoop()
This function is called if an unhandled exception occurs inside the main application event loop.
wxApp
The wxApp class represents the application itself when wxUSE_GUI=1.
Definition: app.h:846
wxString
String class for passing textual data to or receiving it from wxWidgets.
Definition: string.h:315
wxLogError
void wxLogError(const char *formatString,...)
The functions to use for error messages, i.e.

## ◆ OnExit()

virtual int wxAppConsole::OnExit | ( |  | ) |
| virtual

Override this member function for any processing which needs to be done as the application is about to exit.

OnExit is called after destroying all application windows and controls, but before wxWidgets cleanup. Note that it is not called at all if OnInit() failed.

The return value of this function is currently ignored, return the same value as returned by the base class method if you override it.

## ◆ OnFatalException()

virtual void wxAppConsole::OnFatalException | ( |  | ) |
| virtual

This function may be called if something fatal happens: an unhandled exception under Win32 or a fatal signal under Unix, for example.

However, this will not happen by default: you have to explicitly call wxHandleFatalExceptions() to enable this.

Generally speaking, this function should only show a message to the user and return. You may attempt to save unsaved data but this is not guaranteed to work and, in fact, probably won't.

See also
  wxHandleFatalExceptions()

## ◆ OnInit()

virtual bool wxAppConsole::OnInit | ( |  | ) |
| virtual

This must be provided by the application, and will usually create the application's main window, optionally calling SetTopWindow().

You may use OnExit() to clean up anything initialized here, provided that the function returns true.

Notice that if you want to use the command line processing provided by wxWidgets you have to call the base class version in the derived class OnInit().

Return true to continue processing, false to exit the application immediately. In the latter case, you may want to call SetErrorExitCode() to set the process exit code to use when the application terminates.

## ◆ OnInitCmdLine()

virtual void wxAppConsole::OnInitCmdLine | ( | wxCmdLineParser & | parser | ) |
| virtual

Called from OnInit() and may be used to initialize the parser with the command line options for this application.

The base class versions adds support for a few standard options only.

Note that this method should just configure parser to accept the desired command line options by calling wxCmdLineParser::AddOption(), wxCmdLineParser::AddSwitch() and similar methods, but should not call wxCmdLineParser::Parse() as this will be done by wxWidgets itself slightly later.

## ◆ OnRun()

virtual int wxAppConsole::OnRun | ( |  | ) |
| virtual

This virtual function is where the execution of a program written in wxWidgets starts.

The default implementation just enters the main loop and starts handling the events until it terminates, either because ExitMainLoop() has been explicitly called or because the last frame has been deleted and GetExitOnFrameDelete() flag is true (this is the default).

The return value of this function becomes the exit code of the program, so it should return 0 in case of successful termination.

## ◆ OnUnhandledException()

virtual void wxAppConsole::OnUnhandledException | ( |  | ) |
| virtual

This function is called when an unhandled C++ exception occurs in user code called by wxWidgets.

Any unhandled exceptions thrown from (overridden versions of) OnInit() and OnExit() methods as well as any exceptions thrown from inside the main loop and re-thrown by OnUnhandledException() will result in a call to this function.

By the time this function is called, the program is already about to exit and the exception can't be handled nor ignored any more, override OnUnhandledException() or use explicit `try/catch` blocks around OnInit() body to be able to handle the exception earlier.

The default implementation dumps information about the exception using wxMessageOutputBest.

## ◆ ProcessPendingEvents()

virtual void wxAppConsole::ProcessPendingEvents | ( |  | ) |
| virtual

Process all pending events; it is necessary to call this function to process events posted with wxEvtHandler::QueueEvent or wxEvtHandler::AddPendingEvent.

This happens during each event loop iteration (see wxEventLoopBase) in GUI mode but it may be also called directly.

Note that this function does not only process the pending events for the wxApp object itself (which derives from wxEvtHandler) but also the pending events for any event handler of this application.

This function will immediately return and do nothing if SuspendProcessingOfPendingEvents() was called.

## ◆ ResumeProcessingOfPendingEvents()

void wxAppConsole::ResumeProcessingOfPendingEvents | ( |  | ) |

Resume processing of the pending events previously stopped because of a call to SuspendProcessingOfPendingEvents().

## ◆ RethrowStoredException()

virtual void wxAppConsole::RethrowStoredException | ( |  | ) |
| virtual

Method to rethrow exceptions stored by StoreCurrentException().

Note
  Just as with StoreCurrentException(), it is usually not necessary to override this method when using C++11.

If StoreCurrentException() is overridden, this function should be overridden as well to rethrow the exceptions stored by it when the control gets back to our code, i.e. when it's safe to do it.

See StoreCurrentException() for an example of implementing this method.

The default version does nothing when using C++98 and uses std::rethrow_exception() in C++11.

Since
  3.1.0

## ◆ ScheduleForDestruction()

void wxAppConsole::ScheduleForDestruction | ( | wxObject * | object | ) |

Delayed objects destruction.

In applications using events it may be unsafe for an event handler to delete the object which generated the event because more events may be still pending for the same object. In this case the handler may call ScheduleForDestruction() instead. Schedule the object for destruction in the near future.

Notice that if the application is not using an event loop, i.e. if UsesEventLoop() returns false, this method will simply delete the object immediately.

Examples of using this function inside wxWidgets itself include deleting the top level windows when they are closed and sockets when they are disconnected.

## ◆ SetAppDisplayName()

void wxAppConsole::SetAppDisplayName | ( | const wxString & | name | ) |

Set the application name to be used in the user-visible places such as window titles.

See GetAppDisplayName() for more about the differences between the display name and name.

Notice that if this function is called, the name is used as is, without any capitalization as done by default by GetAppDisplayName().

## ◆ SetAppName()

void wxAppConsole::SetAppName | ( | const wxString & | name | ) |

Sets the name of the application.

This name should be used for file names, configuration file entries and other internal strings. For the user-visible strings, such as the window titles, the application display name set by SetAppDisplayName() is used instead.

By default the application name is set to the name of its executable file.

See also
  GetAppName()

## ◆ SetClassName()

void wxAppConsole::SetClassName | ( | const wxString & | name | ) |

Sets the class name of the application.

This may be used in a platform specific manner to refer to the application.

See also
  GetClassName()

## ◆ SetCLocale()

void wxAppConsole::SetCLocale | ( |  | ) |

Sets the C locale to the default locale for the current environment.

It is advised to call this to ensure that the underlying toolkit uses the locale in which the numbers and monetary amounts are shown in the format expected by user and so on.

Calling this function is roughly equivalent to calling

setlocale(LC_ALL, "");

but performs additional toolkit-specific tasks under some platforms and so should be used instead of `setlocale()` itself. Alternatively, you can use wxLocale to change the locale with more control.

Notice that this does not change the global C++ locale, you need to do it explicitly if you want, e.g.

std::locale::global(std::locale(""));

but be warned that locale support in C++ standard library can be poor or worse under some platforms.

Since
  2.9.5

## ◆ SetErrorExitCode()

void wxAppConsole::SetErrorExitCode | ( | int | code | ) |

Sets the error code to use in case of exit on error.

This function is mostly useful to customize the error code returned by the application when it exits due to OnInit() returning false and can be called from OnInit() itself or other virtual functions called from it, for example OnCmdLineError().

By default, the exit code depends on the compiler being used, e.g. it is `255` with typical Unix compilers (gcc, clang) and `127` with MSVC, so it is recommended to call this function to set a consistent exit code, e.g. `2` which is a de facto standard exit code if command line parsing fails.

SetErrorExitCode() can be overridden by the application to perform additional actions, but the overridden version should call the base class version to update the value returned by GetErrorExitCode() and actually used when exiting the application.

Since
  3.2.7

## ◆ SetInstance()

static void wxAppConsole::SetInstance | ( | wxAppConsole * | app | ) |
| static

Allows external code to modify global wxTheApp, but you should really know what you're doing if you call it.

Parameters

  app | Replacement for the global application object.

See also
  GetInstance()

## ◆ SetVendorDisplayName()

void wxAppConsole::SetVendorDisplayName | ( | const wxString & | name | ) |

Set the vendor name to be used in the user-visible places.

See GetVendorDisplayName() for more about the differences between the display name and name.

## ◆ SetVendorName()

void wxAppConsole::SetVendorName | ( | const wxString & | name | ) |

Sets the name of application's vendor.

The name will be used in registry access. A default name is set by wxWidgets.

See also
  GetVendorName()

## ◆ StoreCurrentException()

virtual bool wxAppConsole::StoreCurrentException | ( |  | ) |
| virtual

Method to store exceptions not handled by OnExceptionInMainLoop().

Note
  The default implementation of this function when using C++98 compiler just returns false, as there is no generic way to store an arbitrary exception in C++98 and each application must do it on its own for the exceptions it uses in its overridden version. When using C++11, the default implementation uses std::current_exception() and returns true, so it's normally not necessary to override this method when using C++11.

This function can be overridden to store the current exception, in view of rethrowing it later when RethrowStoredException() is called. If the exception was stored, return true. If the exception can't be stored, i.e. if this function returns false, the program will abort after calling OnUnhandledException().

It is necessary to override this function if OnExceptionInMainLoop() doesn't catch all exceptions, but you still want to handle them using explicit `try/catch` statements. Typical use could be to allow code like the following to work:

void MyFrame::SomeFunction()
{
try {
MyDialog dlg(this);
dlg.ShowModal();
} catch ( const MyExpectedException& e ) {
// Deal with the exceptions thrown from the dialog.
}
}

By default, throwing an exception from an event handler called from the dialog modal event loop would terminate the application as the exception can't be safely propagated to the code in the catch clause because of the presence of the native system functions (through which C++ exceptions can't, generally speaking, propagate) in the call stack between them.

Overriding this method allows the exception to be stored when it is detected and rethrown using RethrowStoredException() when the native system function dispatching the dialog events terminates, with the result that the code above works as expected.

An example of implementing this method:

class MyApp : public wxApp {
public:
virtual bool StoreCurrentException()
{
try {
throw;
} catch ( const std::runtime_exception& e ) {
if ( !m_runtimeError.empty() ) {
// This is not supposed to happen, only one exception,
// at most, should be stored.
return false;
}
m_runtimeError = e.what();
// Don't terminate, let our code handle this exception later.
return true;
} catch ( ... ) {
// This could be extended to store information about any
// other exceptions too, but if we don't store them, we
// should return false to let the program die.
}
return false;
}
virtual void RethrowStoredException()
{
if ( !m_runtimeError.empty() ) {
std::runtime_exception e(m_runtimeError);
m_runtimeError.clear();
throw e;
}
}
private:
std::string m_runtimeError;
};
wxAppConsole::RethrowStoredException
virtual void RethrowStoredException()
Method to rethrow exceptions stored by StoreCurrentException().
wxAppConsole::StoreCurrentException
virtual bool StoreCurrentException()
Method to store exceptions not handled by OnExceptionInMainLoop().

See also
  OnExceptionInMainLoop(), RethrowStoredException()

Since
  3.1.0

## ◆ SuspendProcessingOfPendingEvents()

void wxAppConsole::SuspendProcessingOfPendingEvents | ( |  | ) |

Temporary suspends processing of the pending events.

See also
  ResumeProcessingOfPendingEvents()

## ◆ UsesEventLoop()

virtual bool wxAppConsole::UsesEventLoop | ( |  | ) | const
| virtual

Returns true if the application is using an event loop.

This function always returns true for the GUI applications which must use an event loop but by default only returns true for the console programs if an event loop is already running as it can't know whether one will be created in the future.

Thus, it only makes sense to override it in console applications which do use an event loop, to return true instead of checking if there is a currently active event loop.

## ◆ Yield()

bool wxAppConsole::Yield | ( | bool | onlyIfNeeded = `false` | ) |

Yields control to pending messages in the event loop.

This method is a convenient wrapper for wxEvtLoopBase::Yield(). If the main loop is currently running, it calls this method on it. Otherwise it creates a temporary event loop and uses it instead, which can be useful to process pending messages during the program startup, before the main loop is created.

Use extreme caution when calling this function as, just as wxEvtLoopBase::Yield(), it can result in unexpected reentrances.

## Member Data Documentation

## ◆ argc

int wxAppConsole::argc

Number of command line arguments (after environment-specific processing).

## ◆ argv

wxChar** wxAppConsole::argv

Command line arguments (after environment-specific processing).

Under Windows and Linux/Unix, you should parse the command line arguments and check for files to be opened when starting your application. Under macOS, you need to override MacOpenFiles() since command line arguments are used differently there.

You may use the wxCmdLineParser to parse command line arguments.