| Version: 3.3.1

Macros | Functions
Runtime Type Information (RTTI)
Functions and Macros by Category

## Detailed Description

wxWidgets uses its own RTTI ("run-time type identification") system which predates the current standard C++ RTTI and so is kept for backwards compatibility reasons but also because it allows some things which the standard RTTI doesn't directly support (such as creating a class from its name).

The standard C++ RTTI can be used in the user code without any problems and in general you shouldn't need to use the functions and the macros in this section unless you are thinking of modifying or adding any wxWidgets classes.

Related Overviews: Runtime Type Information (RTTI)

Related class group: Runtime Type Information (RTTI)

## Macros
#define | wxDECLARE_APP(className)
| This is used in headers to create a forward declaration of the wxGetApp() function implemented by wxIMPLEMENT_APP(). More...
#define | wxIMPLEMENT_APP(className)
| This macro defines the application entry point and tells wxWidgets which application class should be used. More...
#define | wxIMPLEMENT_APP_CONSOLE(className)
| This macro defines the application entry point for non-GUI applications and tells wxWidgets which application class should be used. More...
#define | wxIMPLEMENT_WXWIN_MAIN
| This macro defines the application entry point appropriate for the current platform. More...
#define | wxIMPLEMENT_WXWIN_MAIN_CONSOLE
| This macro defines the application entry point for console applications. More...
#define | wxCLASSINFO(className)
| Returns a pointer to the wxClassInfo object associated with this class. More...
#define | wxDECLARE_ABSTRACT_CLASS(className)
| Used inside a class declaration to declare that the class should be made known to the class hierarchy, but objects of this class cannot be created dynamically. More...
#define | wxDECLARE_DYNAMIC_CLASS(className)
| Used inside a class declaration to make the class known to wxWidgets RTTI system and also declare that the objects of this class should be dynamically creatable from run-time type information. More...
#define | wxDECLARE_CLASS(className)
| Used inside a class declaration to declare that the class should be made known to the class hierarchy, but objects of this class cannot be created dynamically. More...
#define | wxIMPLEMENT_ABSTRACT_CLASS(className, baseClassName)
| Used in a C++ implementation file to complete the declaration of a class that has run-time type information. More...
#define | wxIMPLEMENT_ABSTRACT_CLASS2(className, baseClassName1, baseClassName2)
| Used in a C++ implementation file to complete the declaration of a class that has run-time type information and two base classes. More...
#define | wxIMPLEMENT_DYNAMIC_CLASS(className, baseClassName)
| Used in a C++ implementation file to complete the declaration of a class that has run-time type information, and whose instances can be created dynamically. More...
#define | wxIMPLEMENT_DYNAMIC_CLASS2(className, baseClassName1, baseClassName2)
| Used in a C++ implementation file to complete the declaration of a class that has run-time type information, and whose instances can be created dynamically. More...
#define | wxIMPLEMENT_CLASS(className, baseClassName)
| Synonym for wxIMPLEMENT_ABSTRACT_CLASS(). More...
#define | wxIMPLEMENT_CLASS2(className, baseClassName1, baseClassName2)
| Synonym for wxIMPLEMENT_ABSTRACT_CLASS2(). More...
#define | wx_truncate_cast(T, x)
| This case doesn’t correspond to any standard cast but exists solely to make casts which possibly result in a truncation of an integer value more readable. More...
#define | wxConstCast(ptr, classname)
| This macro expands into `const_cast<classname *>(ptr)` if the compiler supports const_cast or into an old, C-style cast, otherwise. More...
#define | wxDynamicCast(ptr, classname)
| This macro returns the pointer ptr cast to the type classname * if the pointer is of this type (the check is done during the run-time) or nullptr otherwise. More...
#define | wxDynamicCastThis(classname)
| This macro is equivalent to `wxDynamicCast(this, classname)` but the latter provokes spurious compilation warnings from some compilers (because it tests whether `this` pointer is non-null which is always true), so this macro should be used to avoid them. More...
#define | wxStaticCast(ptr, classname)
| This macro checks that the cast is valid in debug mode (an assert failure will result if wxDynamicCast(ptr, classname) == nullptr) and then returns the result of executing an equivalent of `static_cast<classname *>(ptr)`. More...
#define | wxGetVariantCast(var, classname)
| This macro returns a pointer to the data stored in var (wxVariant) cast to the type classname if the data is of this type (the check is done during the run-time) or nullptr otherwise. More...

## Functions
wxObject * | wxCreateDynamicObject (const wxString &className)
| Creates and returns an object of the given class, if the class has been registered with the dynamic class system using DECLARE... More...

## Macro Definition Documentation

## ◆ wx_truncate_cast

#define wx_truncate_cast | ( |  | T,
|  |  | x
| ) |  |

This case doesn’t correspond to any standard cast but exists solely to make casts which possibly result in a truncation of an integer value more readable.

Include file:

    #include <wx/defs.h>

## ◆ wxCLASSINFO

#define wxCLASSINFO | ( |  | className | ) |

Returns a pointer to the wxClassInfo object associated with this class.

Include file:

    #include <wx/object.h>

## ◆ wxConstCast

#define wxConstCast | ( |  | ptr,
|  |  | classname
| ) |  |

This macro expands into `const_cast<classname *>(ptr)` if the compiler supports const_cast or into an old, C-style cast, otherwise.

Include file:

    #include <wx/defs.h>

See also
  wxDynamicCast(), wxStaticCast()

## ◆ wxDECLARE_ABSTRACT_CLASS

#define wxDECLARE_ABSTRACT_CLASS | ( |  | className | ) |

Used inside a class declaration to declare that the class should be made known to the class hierarchy, but objects of this class cannot be created dynamically.

Include file:

    #include <wx/object.h>

Example:

class wxCommand: public wxObject
{
wxDECLARE_ABSTRACT_CLASS(wxCommand);
private:
...
public:
...
};
wxCommand
wxCommand is a base class for modelling an application command, which is an action usually performed ...
Definition: cmdproc.h:22
wxObject
This is the root class of many of the wxWidgets classes.
Definition: object.h:233
wxDECLARE_ABSTRACT_CLASS
#define wxDECLARE_ABSTRACT_CLASS(className)
Used inside a class declaration to declare that the class should be made known to the class hierarchy...
Definition: object.h:705

## ◆ wxDECLARE_APP

#define wxDECLARE_APP | ( |  | className | ) |

This is used in headers to create a forward declaration of the wxGetApp() function implemented by wxIMPLEMENT_APP().

It creates the declaration `className& wxGetApp()` (requires a final semicolon).

Include file:

    #include <wx/app.h>

Example:

wxDECLARE_APP(MyApp);
wxDECLARE_APP
#define wxDECLARE_APP(className)
This is used in headers to create a forward declaration of the wxGetApp() function implemented by wxI...
Definition: app.h:1493

## ◆ wxDECLARE_CLASS

#define wxDECLARE_CLASS | ( |  | className | ) |

Used inside a class declaration to declare that the class should be made known to the class hierarchy, but objects of this class cannot be created dynamically.

The same as wxDECLARE_ABSTRACT_CLASS().

Include file:

    #include <wx/object.h>

## ◆ wxDECLARE_DYNAMIC_CLASS

#define wxDECLARE_DYNAMIC_CLASS | ( |  | className | ) |

Used inside a class declaration to make the class known to wxWidgets RTTI system and also declare that the objects of this class should be dynamically creatable from run-time type information.

Notice that this implies that the class should have a default constructor, if this is not the case consider using wxDECLARE_ABSTRACT_CLASS().

Include file:

    #include <wx/object.h>

Example:

class wxFrame: public wxWindow
{
wxDECLARE_DYNAMIC_CLASS(wxFrame);
private:
const wxString& frameTitle;
public:
...
};
wxFrame
A frame is a window whose size and position can (usually) be changed by the user.
Definition: frame.h:166
wxString
String class for passing textual data to or receiving it from wxWidgets.
Definition: string.h:372
wxWindow
wxWindow is the base class for all windows and represents any visible object on screen.
Definition: window.h:353
wxDECLARE_DYNAMIC_CLASS
#define wxDECLARE_DYNAMIC_CLASS(className)
Used inside a class declaration to make the class known to wxWidgets RTTI system and also declare tha...
Definition: object.h:730

## ◆ wxDynamicCast

#define wxDynamicCast | ( |  | ptr,
|  |  | classname
| ) |  |

This macro returns the pointer ptr cast to the type classname * if the pointer is of this type (the check is done during the run-time) or nullptr otherwise.

Usage of this macro is preferred over obsoleted wxObject::IsKindOf() function.

The ptr argument may be nullptr, in which case nullptr will be returned.

Include file:

    #include <wx/object.h>

Example:

wxWindow *win = wxWindow::FindFocus();
wxTextCtrl *text = wxDynamicCast(win, wxTextCtrl);
if ( text )
{
// a text control has the focus...
}
else
{
// no window has the focus or it is not a text control
}
wxTextCtrl
A text control allows text to be displayed and edited.
Definition: textctrl.h:1580
wxWindow::FindFocus
static wxWindow * FindFocus()
Finds the window or control which currently has the keyboard focus.
wxDynamicCast
#define wxDynamicCast(ptr, classname)
This macro returns the pointer ptr cast to the type classname * if the pointer is of this type (the c...
Definition: object.h:865

See also
  Runtime Type Information (RTTI), wxDynamicCastThis(), wxConstCast(), wxStaticCast()

## ◆ wxDynamicCastThis

#define wxDynamicCastThis | ( |  | classname | ) |

This macro is equivalent to `wxDynamicCast(this, classname)` but the latter provokes spurious compilation warnings from some compilers (because it tests whether `this` pointer is non-null which is always true), so this macro should be used to avoid them.

Note that ptr must be an object of wxObject-derived class, otherwise using this macro results in undefined behaviour.

Include file:

    #include <wx/object.h>

See also
  wxDynamicCast()

## ◆ wxGetVariantCast

#define wxGetVariantCast | ( |  | var,
|  |  | classname
| ) |  |

This macro returns a pointer to the data stored in var (wxVariant) cast to the type classname if the data is of this type (the check is done during the run-time) or nullptr otherwise.

Include file:

    #include <wx/variant.h>

See also
  Runtime Type Information (RTTI), wxDynamicCast()

## ◆ wxIMPLEMENT_ABSTRACT_CLASS

#define wxIMPLEMENT_ABSTRACT_CLASS | ( |  | className,
|  |  | baseClassName
| ) |  |

Used in a C++ implementation file to complete the declaration of a class that has run-time type information.

Include file:

    #include <wx/object.h>

Example:

wxIMPLEMENT_ABSTRACT_CLASS(wxCommand, wxObject);
wxCommand::wxCommand()
{
...
}
wxCommand::wxCommand
wxCommand(bool canUndo=false, const wxString &name=wxEmptyString)
Constructor.
wxIMPLEMENT_ABSTRACT_CLASS
#define wxIMPLEMENT_ABSTRACT_CLASS(className, baseClassName)
Used in a C++ implementation file to complete the declaration of a class that has run-time type infor...
Definition: object.h:760

## ◆ wxIMPLEMENT_ABSTRACT_CLASS2

#define wxIMPLEMENT_ABSTRACT_CLASS2 | ( |  | className,
|  |  | baseClassName1,
|  |  | baseClassName2
| ) |  |

Used in a C++ implementation file to complete the declaration of a class that has run-time type information and two base classes.

Include file:

    #include <wx/object.h>

## ◆ wxIMPLEMENT_APP

#define wxIMPLEMENT_APP | ( |  | className | ) |

This macro defines the application entry point and tells wxWidgets which application class should be used.

The two tasks performed by this macro can be done separately by using wxIMPLEMENT_APP_NO_MAIN() and wxIMPLEMENT_WXWIN_MAIN() macros, but in a typical GUI application it's simpler and more convenient to use this macro to do both together.

The className passed to this macro must be a name of the class deriving from wxApp.

Note that this macro requires a final semicolon.

Include file:

    #include <wx/app.h>

Example:

wxIMPLEMENT_APP(MyApp);
wxIMPLEMENT_APP
#define wxIMPLEMENT_APP(className)
This macro defines the application entry point and tells wxWidgets which application class should be ...
Definition: app.h:1519

See also
  wxDECLARE_APP(), wxIMPLEMENT_APP_CONSOLE()

## ◆ wxIMPLEMENT_APP_CONSOLE

#define wxIMPLEMENT_APP_CONSOLE | ( |  | className | ) |

This macro defines the application entry point for non-GUI applications and tells wxWidgets which application class should be used.

This macro is provided for symmetry with wxIMPLEMENT_APP() for the console (non-GUI) applications and is equivalent to using wxIMPLEMENT_APP_NO_MAIN() and wxIMPLEMENT_WXWIN_MAIN_CONSOLE().

The className passed to this macro must be a name of the class deriving from wxApp.

Note that this macro requires a final semicolon.

Include file:

    #include <wx/app.h>

Example:

wxIMPLEMENT_APP_CONSOLE(MyApp);
wxIMPLEMENT_APP_CONSOLE
#define wxIMPLEMENT_APP_CONSOLE(className)
This macro defines the application entry point for non-GUI applications and tells wxWidgets which app...
Definition: app.h:1544

See also
  wxIMPLEMENT_APP()

## ◆ wxIMPLEMENT_CLASS

#define wxIMPLEMENT_CLASS | ( |  | className,
|  |  | baseClassName
| ) |  |

Synonym for wxIMPLEMENT_ABSTRACT_CLASS().

Please prefer to use the more clear, if longer, wxIMPLEMENT_ABSTRACT_CLASS in the new code.

Include file:

    #include <wx/object.h>

## ◆ wxIMPLEMENT_CLASS2

#define wxIMPLEMENT_CLASS2 | ( |  | className,
|  |  | baseClassName1,
|  |  | baseClassName2
| ) |  |

Synonym for wxIMPLEMENT_ABSTRACT_CLASS2().

Please prefer to use the more clear, if longer, wxIMPLEMENT_ABSTRACT_CLASS2 in the new code.

Include file:

    #include <wx/object.h>

## ◆ wxIMPLEMENT_DYNAMIC_CLASS

#define wxIMPLEMENT_DYNAMIC_CLASS | ( |  | className,
|  |  | baseClassName
| ) |  |

Used in a C++ implementation file to complete the declaration of a class that has run-time type information, and whose instances can be created dynamically.

Include file:

    #include <wx/object.h>

Example:

wxIMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow);
wxFrame::wxFrame()
{
...
}
wxFrame::wxFrame
wxFrame()
Default constructor.
wxIMPLEMENT_DYNAMIC_CLASS
#define wxIMPLEMENT_DYNAMIC_CLASS(className, baseClassName)
Used in a C++ implementation file to complete the declaration of a class that has run-time type infor...
Definition: object.h:788

## ◆ wxIMPLEMENT_DYNAMIC_CLASS2

#define wxIMPLEMENT_DYNAMIC_CLASS2 | ( |  | className,
|  |  | baseClassName1,
|  |  | baseClassName2
| ) |  |

Used in a C++ implementation file to complete the declaration of a class that has run-time type information, and whose instances can be created dynamically.

Use this for classes derived from two base classes.

Include file:

    #include <wx/object.h>

## ◆ wxIMPLEMENT_WXWIN_MAIN

#define wxIMPLEMENT_WXWIN_MAIN

This macro defines the application entry point appropriate for the current platform.

Note that usually wxIMPLEMENT_APP() is used instead of this macro.

For most platforms, it defines `main()` function, but for GUI Windows applications, it defines `WinMain()` instead.

In either case, the macro expansion includes the call to wxDISABLE_DEBUG_SUPPORT() which disables debugging code in release builds. If you don't use this macro, but define the entry point yourself, you probably want to call wxDISABLE_DEBUG_SUPPORT() explicitly.

Include file:

    #include <wx/app.h>

## ◆ wxIMPLEMENT_WXWIN_MAIN_CONSOLE

#define wxIMPLEMENT_WXWIN_MAIN_CONSOLE

This macro defines the application entry point for console applications.

This macro is provided mostly for symmetry with wxIMPLEMENT_WXWIN_MAIN() but is less useful, as it is also simple enough to define `main()` function directly.

Please note, however, that this macro, as well as wxIMPLEMENT_APP_CONSOLE() which uses it, contains the call to wxDISABLE_DEBUG_SUPPORT() which disables debugging code in release builds and that if you don't use this macro, but define `main()` yourself, you probably want to call wxDISABLE_DEBUG_SUPPORT() from it explicitly.

Include file:

    #include <wx/app.h>

## ◆ wxStaticCast

#define wxStaticCast | ( |  | ptr,
|  |  | classname
| ) |  |

This macro checks that the cast is valid in debug mode (an assert failure will result if wxDynamicCast(ptr, classname) == nullptr) and then returns the result of executing an equivalent of `static_cast<classname *>(ptr)`.

Note that ptr must be an object of wxObject-derived class, otherwise using this macro results in undefined behaviour.

Include file:

    #include <wx/object.h>

See also
  wxDynamicCast(), wxConstCast()

## Function Documentation

## ◆ wxCreateDynamicObject()

wxObject* wxCreateDynamicObject | ( | const wxString & | className | ) |

Creates and returns an object of the given class, if the class has been registered with the dynamic class system using DECLARE...

and IMPLEMENT... macros.

Include file:

    #include <wx/object.h>