The wxApp class represents the application itself. It is used to:
You should use the macro IMPLEMENT_APP(appClass) in your application implementation file to tell wxWindows how to create an instance of your application class.
Use DECLARE_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.
Derived from
Include files
<wx/app.h>
See also
Members
wxApp::wxApp
wxApp::~wxApp
wxApp::argc
wxApp::argv
wxApp::CreateLogTarget
wxApp::Dispatch
wxApp::GetAppName
wxApp::GetAuto3D
wxApp::GetClassName
wxApp::GetExitOnFrameDelete
wxApp::GetTopWindow
wxApp::GetUseBestVisual
wxApp::GetVendorName
wxApp::ExitMainLoop
wxApp::Initialized
wxApp::MainLoop
wxApp::OnActivate
wxApp::OnExit
wxApp::OnCharHook
wxApp::OnFatalException
wxApp::OnIdle
wxApp::OnEndSession
wxApp::OnInit
wxApp::OnQueryEndSession
wxApp::ProcessMessage
wxApp::Pending
wxApp::SendIdleEvents
wxApp::SetAppName
wxApp::SetAuto3D
wxApp::SetClassName
wxApp::SetExitOnFrameDelete
wxApp::SetTopWindow
wxApp::SetVendorName
wxApp::GetStdIcon
wxApp::SetUseBestVisual
void wxApp()
Constructor. Called implicitly with a definition of a wxApp object.
void ~wxApp()
Destructor. Will be called implicitly on program exit if the wxApp object is created on the stack.
int argc
Number of command line arguments (after environment-specific processing).
char ** argv
Command line arguments (after environment-specific processing).
virtual wxLog* CreateLogTarget()
Creates a wxLog class for the application to use for logging errors. The default implementation returns a new wxLogGui class.
See also
void Dispatch()
Dispatches the next event in the windowing system event queue.
This can be used for programming event loops, e.g.
while (app.Pending()) Dispatch();See also
wxString GetAppName() const
Returns the application name.
Remarks
wxWindows sets this to a reasonable default before calling wxApp::OnInit, but the application can reset it at will.
bool GetAuto3D() const
Returns TRUE if 3D control mode is on, FALSE otherwise.
See also
wxString 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
bool GetExitFrameOnDelete() const
Returns TRUE if the application will exit when the top-level window is deleted, FALSE otherwise.
See also
wxWindow * GetTopWindow() const
Returns a pointer to the top window.
Remarks
If the top window hasn't been set using wxApp::SetTopWindow, this function will find the first top-level window (frame or dialog) and return that.
See also
bool GetUseBestVisual() const
Returns TRUE if the application will use the best visual on systems that support different visuals, FALSE otherwise.
See also
wxString GetVendorName() const
Returns the application's vendor name.
void ExitMainLoop()
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.
bool Initialized()
Returns TRUE if the application has been initialized (i.e. if wxApp::OnInit has returned successfully). This can be useful for error message routines to determine which method of output is best for the current state of the program (some windowing systems may not like dialogs to pop up before the main loop has been entered).
int MainLoop()
Called by wxWindows on creation of the application. Override this if you wish to provide your own (environment-dependent) main loop.
Return value
Returns 0 under X, and the wParam of the WM_QUIT message under Windows.
void OnActivate(wxActivateEvent& event)
Provide this member function to know whether the application is being activated or deactivated (Windows only).
See also
wxWindow::OnActivate, wxActivateEvent
int OnExit()
Provide this member function for any processing which needs to be done as the application is about to exit.
void OnCharHook(wxKeyEvent& event)
This event handler function is called (under Windows only) to allow the window to intercept keyboard events before they are processed by child windows.
Parameters
event
Remarks
Use the wxEVT_CHAR_HOOK macro in your event table.
If you use this member, you can selectively consume keypress events by calling wxEvent::Skip for characters the application is not interested in.
See also
wxKeyEvent, wxWindow::OnChar, wxWindow::OnCharHook, wxDialog::OnCharHook
void OnFatalException()
This function may be called if something fatal happens: an unhandled exception under Win32 or a 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
void OnIdle(wxIdleEvent& event)
Override this member function for any processing which needs to be done when the application is idle. You should call wxApp::OnIdle from your own function, since this forwards OnIdle events to windows and also performs garbage collection for windows whose destruction has been delayed.
wxWindows' strategy for OnIdle processing is as follows. After pending user interface events for an application have all been processed, wxWindows sends an OnIdle event to the application object. wxApp::OnIdle itself sends an OnIdle event to each application window, allowing windows to do idle processing such as updating their appearance. If either wxApp::OnIdle or a window OnIdle function requested more time, by caling wxIdleEvent::RequestMore, wxWindows will send another OnIdle event to the application object. This will occur in a loop until either a user event is found to be pending, or OnIdle requests no more time. Then all pending user events are processed until the system goes idle again, when OnIdle is called, and so on.
See also
wxWindow::OnIdle, wxIdleEvent, wxWindow::SendIdleEvents
void OnEndSession(wxCloseEvent& event)
This is an event handler function called when the operating system or GUI session is about to close down. The application has a chance to silently save information, and can optionally close itself.
Use the EVT_END_SESSION event table macro to handle query end session events.
The default handler calls wxWindow::Close with a TRUE argument (forcing the application to close itself silently).
Remarks
Under X, OnEndSession is called in response to the 'die' event.
Under Windows, OnEndSession is called in response to the WM_ENDSESSION message.
See also
wxWindow::Close, wxWindow::OnCloseWindow, wxCloseEvent, wxApp::OnQueryEndSession
bool OnInit()
This must be provided by the application, and will usually create the application's main window, optionally calling wxApp::SetTopWindow.
Return TRUE to continue processing, FALSE to exit the application.
void OnQueryEndSession(wxCloseEvent& event)
This is an event handler function called when the operating system or GUI session is about to close down. Typically, an application will try to save unsaved documents at this point.
If wxCloseEvent::CanVeto returns TRUE, the application is allowed to veto the shutdown by calling wxCloseEvent::Veto. The application might veto the shutdown after prompting for documents to be saved, and the user has cancelled the save.
Use the EVT_QUERY_END_SESSION event table macro to handle query end session events.
You should check whether the application is forcing the deletion of the window using wxCloseEvent::GetForce. If this is TRUE, destroy the window using wxWindow::Destroy. If not, it is up to you whether you respond by destroying the window.
The default handler calls wxWindow::Close on the top-level window, and vetoes the shutdown if Close returns FALSE. This will be sufficient for many applications.
Remarks
Under X, OnQueryEndSession is called in response to the 'save session' event.
Under Windows, OnQueryEndSession is called in response to the WM_QUERYENDSESSION message.
See also
wxWindow::Close, wxWindow::OnCloseWindow, wxCloseEvent, wxApp::OnEndSession
bool ProcessMessage(MSG *msg)
Windows-only function for processing a message. This function is called from the main message loop, checking for windows that may wish to process it. The function returns TRUE if the message was processed, FALSE otherwise. If you use wxWindows with another class library with its own message loop, you should make sure that this function is called to allow wxWindows to receive messages. For example, to allow co-existance with the Microsoft Foundation Classes, override the PreTranslateMessage function:
// Provide wxWindows message loop compatibility BOOL CTheApp::PreTranslateMessage(MSG *msg) { if (wxTheApp && wxTheApp->ProcessMessage(msg)) return TRUE; else return CWinApp::PreTranslateMessage(msg); }
bool Pending()
Returns TRUE if unprocessed events are in the window system event queue.
See also
bool SendIdleEvents()
Sends idle events to all top-level windows.
bool SendIdleEvents(wxWindow* win)
Sends idle events to a window and its children.
Remarks
These functions poll the top-level windows, and their children, for idle event processing. If TRUE is returned, more OnIdle processing is requested by one or more window.
See also
wxApp::OnIdle, wxWindow::OnIdle, wxIdleEvent
void SetAppName(const wxString& name)
Sets the name of the application. The name may be used in dialogs (for example by the document/view framework). A default name is set by wxWindows.
See also
void SetAuto3D(const bool auto3D)
Switches automatic 3D controls on or off.
Parameters
auto3D
Remarks
This has an effect on Windows only.
See also
void 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
void SetExitOnFrameDelete(bool flag)
Allows the programmer to specify whether the application will exit when the top-level frame is deleted.
Parameters
flag
void SetTopWindow(wxWindow* window)
Sets the 'top' window. You can call this from within wxApp::OnInit to let wxWindows know which is the main window. You don't have to set the top window; it is only a convenience so that (for example) certain dialogs without parents can use a specific window as the top window. If no top window is specified by the application, wxWindows just uses the first frame or dialog in its top-level window list, when it needs to use the top window.
Parameters
window
See also
wxApp::GetTopWindow, wxApp::OnInit
void 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 wxWindows.
See also
virtual wxIcon GetStdIcon(int which) const
Returns the icons used by wxWindows internally, e.g. the ones used for message boxes. This function is used internally and can be overridden by the user to change the default icons.
Parameters
which
See wxMessageBox for a list of icon identifiers.
void SetUseBestVisual(bool flag)
Allows the programmer to specify whether the application will use the best visual on systems that support several visual on the same display. This is typically the case under Solaris and IRIX, where the default visual is only 8-bit whereas certain appications are supposed to run in TrueColour mode.
Note that this function has to be called in the constructor of the wxApp instance and won't have any effect when called later on.
This function currently only has effect under GTK.
Parameters
flag