]>
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 | \wxheading{Library} | |
59 | ||
60 | \helpref{wxBase}{librarieslist} | |
61 | ||
62 | \latexignore{\rtfignore{\wxheading{Members}}} | |
63 | ||
64 | ||
65 | \membersection{wxModule::wxModule}\label{wxmodulector} | |
66 | ||
67 | \func{}{wxModule}{\void} | |
68 | ||
69 | Constructs a wxModule object. | |
70 | ||
71 | ||
72 | \membersection{wxModule::\destruct{wxModule}}\label{wxmoduledtor} | |
73 | ||
74 | \func{}{\destruct{wxModule}}{\void} | |
75 | ||
76 | Destructor. | |
77 | ||
78 | ||
79 | \membersection{wxModule::AddDependency}\label{wxmoduleoninit} | |
80 | ||
81 | \func{void}{AddDependency}{\param{wxClassInfo * }{dep}} | |
82 | ||
83 | Call this function from the constructor of the derived class. \arg{dep} must be | |
84 | the \helpref{CLASSINFO}{classinfo} of a wxModule-derived class and the | |
85 | corresponding module will be loaded \emph{before} and unloaded \emph{after} | |
86 | this module. | |
87 | ||
88 | Note that circular dependencies are detected and result in a fatal error. | |
89 | ||
90 | \wxheading{Parameters} | |
91 | ||
92 | \docparam{dep}{The class information object for the dependent module.} | |
93 | ||
94 | ||
95 | \membersection{wxModule::OnExit}\label{wxmoduleonexit} | |
96 | ||
97 | \func{virtual void}{OnExit}{\void} | |
98 | ||
99 | Provide this function with appropriate cleanup for your module. | |
100 | ||
101 | ||
102 | \membersection{wxModule::OnInit}\label{wxmoduleoninit} | |
103 | ||
104 | \func{virtual bool}{OnInit}{\void} | |
105 | ||
106 | Provide this function with appropriate initialization for your module. If the function | |
107 | returns false, wxWidgets will exit immediately. | |
108 |