]>
Commit | Line | Data |
---|---|---|
1 | \section{\class{wxModule}}\label{wxmodule} | |
2 | ||
3 | The module system is a very simple mechanism to allow applications (and parts | |
4 | of wxWidgets itself) to define initialization and cleanup functions that are | |
5 | automatically called on wxWidgets startup and exit. | |
6 | ||
7 | To define a new kind of module, derive a class from wxModule, override the | |
8 | \helpref{OnInit}{wxmoduleoninit} and \helpref{OnExit}{wxmoduleonexit} | |
9 | functions, and add the DECLARE\_DYNAMIC\_CLASS and IMPLEMENT\_DYNAMIC\_CLASS to | |
10 | header and implementation files (which can be the same file). On | |
11 | initialization, wxWidgets will find all classes derived from wxModule, create | |
12 | an instance of each, and call each OnInit function. On exit, wxWidgets will | |
13 | call the OnExit function for each module instance. | |
14 | ||
15 | Note that your module class does not have to be in a header file. | |
16 | ||
17 | For example: | |
18 | ||
19 | \begin{verbatim} | |
20 | // A module to allow DDE initialization/cleanup | |
21 | // without calling these functions from app.cpp or from | |
22 | // the user's application. | |
23 | class wxDDEModule: public wxModule | |
24 | { | |
25 | public: | |
26 | wxDDEModule() { } | |
27 | virtual bool OnInit() { wxDDEInitialize(); return true; }; | |
28 | virtual void OnExit() { wxDDECleanUp(); }; | |
29 | ||
30 | private: | |
31 | DECLARE_DYNAMIC_CLASS(wxDDEModule) | |
32 | }; | |
33 | ||
34 | IMPLEMENT_DYNAMIC_CLASS(wxDDEModule, wxModule) | |
35 | ||
36 | ||
37 | // Another module which uses DDE in its OnInit() | |
38 | class MyModule: public wxModule | |
39 | { | |
40 | public: | |
41 | wxDDEModule() { AddDependency(CLASSINFO(wxDDEModule)); } | |
42 | virtual bool OnInit() { ... code using DDE ... } | |
43 | virtual void OnExit() { ... } | |
44 | ||
45 | private: | |
46 | DECLARE_DYNAMIC_CLASS(wxDDEModule) | |
47 | }; | |
48 | \end{verbatim} | |
49 | ||
50 | \wxheading{Derived from} | |
51 | ||
52 | \helpref{wxObject}{wxobject} | |
53 | ||
54 | \wxheading{Include files} | |
55 | ||
56 | <wx/module.h> | |
57 | ||
58 | \latexignore{\rtfignore{\wxheading{Members}}} | |
59 | ||
60 | ||
61 | \membersection{wxModule::wxModule}\label{wxmodulector} | |
62 | ||
63 | \func{}{wxModule}{\void} | |
64 | ||
65 | Constructs a wxModule object. | |
66 | ||
67 | ||
68 | \membersection{wxModule::\destruct{wxModule}}\label{wxmoduledtor} | |
69 | ||
70 | \func{}{\destruct{wxModule}}{\void} | |
71 | ||
72 | Destructor. | |
73 | ||
74 | ||
75 | \membersection{wxModule::AddDependency}\label{wxmoduleoninit} | |
76 | ||
77 | \func{void}{AddDependency}{\param{wxClassInfo * }{dep}} | |
78 | ||
79 | Call this function from the constructor of the derived class. \arg{dep} must be | |
80 | the \helpref{CLASSINFO}{classinfo} of a wxModule-derived class and the | |
81 | corresponding module will be loaded \emph{before} and unloaded \emph{after} | |
82 | this module. | |
83 | ||
84 | Note that circular dependencies are detected and result in a fatal error. | |
85 | ||
86 | \wxheading{Parameters} | |
87 | ||
88 | \docparam{dep}{The class information object for the dependent module.} | |
89 | ||
90 | ||
91 | \membersection{wxModule::OnExit}\label{wxmoduleonexit} | |
92 | ||
93 | \func{virtual void}{OnExit}{\void} | |
94 | ||
95 | Provide this function with appropriate cleanup for your module. | |
96 | ||
97 | ||
98 | \membersection{wxModule::OnInit}\label{wxmoduleoninit} | |
99 | ||
100 | \func{virtual bool}{OnInit}{\void} | |
101 | ||
102 | Provide this function with appropriate initialization for your module. If the function | |
103 | returns false, wxWidgets will exit immediately. | |
104 |