The module system is a very simple mechanism to allow applications (and parts of wxWidgets itself) to define initialization and cleanup functions that are automatically called on wxWidgets startup and exit.
To define a new kind of module, derive a class from wxModule, override the wxModule::OnInit and wxModule::OnExit functions, and add the wxDECLARE_DYNAMIC_CLASS and wxIMPLEMENT_DYNAMIC_CLASS to header and implementation files (which can be the same file). On initialization, wxWidgets will find all classes derived from wxModule, create an instance of each, and call each wxModule::OnInit function. On exit, wxWidgets will call the wxModule::OnExit function for each module instance.
Note that your module class does not have to be in a header file.
For example:
{
public:
wxDDEModule() { }
private:
};
{
public:
virtual bool OnInit() { ... code
using DDE ... }
private:
};
{
public:
virtual bool OnInit() { ... code
using DDE ... }
private:
};
The module system is a very simple mechanism to allow applications (and parts of wxWidgets itself) to...
Definition: module.h:78
virtual bool OnInit()=0
Provide this function with appropriate initialization for your module.
void AddDependency(wxClassInfo *dep)
Call this function from the constructor of the derived class.
virtual void OnExit()=0
Provide this function with appropriate cleanup for your module.
void wxDDEInitialize()
Initializes the DDE system.
void wxDDECleanUp()
Called when wxWidgets exits, to clean up the DDE system.
#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
#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
#define wxCLASSINFO(className)
Returns a pointer to the wxClassInfo object associated with this class.
Definition: object.h:682
void wxModule::AddDependency |
( |
const char * |
classname | ) |
|
|
protected |
Call this function from the constructor of the derived class.
This overload allows a dependency to be added by name without access to the class info.
This is useful when a module is declared entirely in a source file and there is no header for the declaration of the module needed by wxCLASSINFO(), however errors are not detected until run-time, instead of compile-time, then. Note that circular dependencies are detected and result in a fatal error.
- Parameters
-
classname | The class name of the dependent module. |