]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: msw/registry.h | |
3 | // Purpose: Registry classes and functions | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 03.04.198 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> | |
bbcdf8bc | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _REGISTRY_H | |
13 | #define _REGISTRY_H | |
14 | ||
0d3820b3 JS |
15 | #ifdef __GNUG__ |
16 | #pragma interface "registry.h" | |
17 | #endif | |
18 | ||
2bda0e17 KB |
19 | // ---------------------------------------------------------------------------- |
20 | // mutable hack (see also registry.cpp) | |
21 | // ---------------------------------------------------------------------------- | |
47d67540 | 22 | #if wxUSE_MUTABLE |
2bda0e17 KB |
23 | #define MUTABLE mutable |
24 | #else | |
25 | #define MUTABLE | |
26 | #endif | |
27 | ||
28 | // ---------------------------------------------------------------------------- | |
8f494e5d | 29 | // types used in this module |
2bda0e17 | 30 | // ---------------------------------------------------------------------------- |
0d8d91a9 JS |
31 | |
32 | /* | |
2bda0e17 KB |
33 | #ifndef HKEY_DEFINED |
34 | #define HKEY_DEFINED | |
35 | #define HKEY unsigned long | |
36 | #endif | |
0d8d91a9 | 37 | */ |
2bda0e17 | 38 | |
8f494e5d VZ |
39 | typedef unsigned long ulong; |
40 | ||
2bda0e17 KB |
41 | // ---------------------------------------------------------------------------- |
42 | // class wxRegKey encapsulates window HKEY handle | |
43 | // ---------------------------------------------------------------------------- | |
44 | class WXDLLEXPORT wxRegKey | |
45 | { | |
46 | public: | |
47 | // NB: do _not_ change the values of elements in these enumerations! | |
48 | ||
49 | // registry value types (with comments from winnt.h) | |
50 | enum ValueType | |
51 | { | |
52 | Type_None, // No value type | |
53 | Type_String, // Unicode nul terminated string | |
54 | #ifdef __WIN32__ | |
55 | Type_Expand_String, // Unicode nul terminated string | |
56 | // (with environment variable references) | |
57 | Type_Binary, // Free form binary | |
58 | Type_Dword, // 32-bit number | |
59 | Type_Dword_little_endian, // 32-bit number (same as Type_DWORD) | |
60 | Type_Dword_big_endian, // 32-bit number | |
61 | Type_Link, // Symbolic Link (unicode) | |
62 | Type_Multi_String, // Multiple Unicode strings | |
63 | Type_Resource_list, // Resource list in the resource map | |
64 | Type_Full_resource_descriptor, // Resource list in the hardware description | |
65 | Type_Resource_requirements_list, // ??? | |
66 | #endif //WIN32 | |
67 | }; | |
68 | ||
69 | // predefined registry keys | |
70 | enum StdKey | |
71 | { | |
72 | HKCR, // classes root | |
73 | #ifdef __WIN32__ | |
74 | HKCU, // current user | |
75 | HKLM, // local machine | |
76 | HKUSR, // users | |
77 | HKPD, // performance data (@@ NT only?) | |
78 | #if WINVER >= 0x0400 | |
79 | HKCC, // current config | |
80 | HKDD, // dynamic data | |
81 | #endif // Winver | |
82 | #endif // Win32/16 | |
83 | }; | |
84 | ||
85 | // information about standard (predefined) registry keys | |
86 | // number of standard keys | |
87 | static const size_t nStdKeys; | |
88 | // get the name of a standard key | |
3cda6353 | 89 | static const char *GetStdKeyName(size_t key); |
2bda0e17 | 90 | // get the short name of a standard key |
3cda6353 | 91 | static const char *GetStdKeyShortName(size_t key); |
2bda0e17 | 92 | // get StdKey from root HKEY |
0d8d91a9 | 93 | static StdKey GetStdKeyFromHkey(WXHKEY hkey); |
2bda0e17 KB |
94 | |
95 | // extacts the std key prefix from the string (return value) and | |
96 | // leaves only the part after it (i.e. modifies the string passed!) | |
97 | static StdKey ExtractKeyName(wxString& str); | |
98 | ||
99 | // ctors | |
100 | // root key is set to HKCR (the only root key under Win16) | |
101 | wxRegKey(); | |
102 | // strKey is the full name of the key (i.e. starting with HKEY_xxx...) | |
103 | wxRegKey(const wxString& strKey); | |
104 | // strKey is the name of key under (standard key) keyParent | |
2dc77646 | 105 | wxRegKey(StdKey keyParent, const wxString& strKey); |
2bda0e17 KB |
106 | // strKey is the name of key under (previously created) keyParent |
107 | wxRegKey(const wxRegKey& keyParent, const wxString& strKey); | |
108 | // | |
109 | ~wxRegKey(); | |
110 | ||
111 | // change key (closes the previously opened key if any) | |
2dc77646 | 112 | // the name is absolute, i.e. should start with HKEY_xxx |
2bda0e17 | 113 | void SetName(const wxString& strKey); |
2dc77646 VZ |
114 | // the name is relative to the parent key |
115 | void SetName(StdKey keyParent, const wxString& strKey); | |
116 | // the name is relative to the parent key | |
117 | void SetName(const wxRegKey& keyParent, const wxString& strKey); | |
118 | // hKey should be opened and will be closed in wxRegKey dtor | |
0d8d91a9 | 119 | void SetHkey(WXHKEY hKey); |
2bda0e17 KB |
120 | |
121 | // get infomation about the key | |
122 | // get the (full) key name. Abbreviate std root keys if bShortPrefix. | |
cf447356 | 123 | wxString GetName(bool bShortPrefix = TRUE) const; |
2dc77646 | 124 | // return true if the key exists |
8f494e5d VZ |
125 | bool Exists() const; |
126 | // get the info about key (any number of these pointers may be NULL) | |
14b72bf5 JS |
127 | |
128 | #ifdef __GNUWIN32__ | |
3cda6353 VZ |
129 | bool GetKeyInfo(size_t *pnSubKeys, // number of subkeys |
130 | size_t *pnMaxKeyLen, // max len of subkey name | |
131 | size_t *pnValues, // number of values | |
132 | size_t *pnMaxValueLen) const; | |
14b72bf5 | 133 | #else |
8f494e5d VZ |
134 | bool GetKeyInfo(ulong *pnSubKeys, // number of subkeys |
135 | ulong *pnMaxKeyLen, // max len of subkey name | |
136 | ulong *pnValues, // number of values | |
137 | ulong *pnMaxValueLen) const; | |
14b72bf5 | 138 | #endif |
2dc77646 | 139 | // return true if the key is opened |
8f494e5d | 140 | bool IsOpened() const { return m_hKey != 0; } |
2bda0e17 KB |
141 | // for "if ( !key ) wxLogError(...)" kind of expressions |
142 | operator bool() const { return m_dwLastError == 0; } | |
143 | ||
144 | // operations on the key itself | |
145 | // explicitly open the key (will be automatically done by all functions | |
146 | // which need the key to be opened if the key is not opened yet) | |
147 | bool Open(); | |
148 | // create the key: will fail if the key already exists and bOkIfExists | |
cf447356 | 149 | bool Create(bool bOkIfExists = TRUE); |
2bda0e17 KB |
150 | // close the key (will be automatically done in dtor) |
151 | bool Close(); | |
152 | ||
153 | // deleting keys/values | |
154 | // deletes this key and all of it's subkeys/values | |
155 | bool DeleteSelf(); | |
156 | // deletes the subkey with all of it's subkeys/values recursively | |
157 | bool DeleteKey(const char *szKey); | |
158 | // deletes the named value (may be NULL to remove the default value) | |
159 | bool DeleteValue(const char *szValue); | |
160 | ||
161 | // access to values and subkeys | |
162 | // get value type | |
163 | ValueType GetValueType(const char *szValue); | |
164 | ||
165 | // assignment operators set the default value of the key | |
166 | wxRegKey& operator=(const wxString& strValue) | |
167 | { SetValue(NULL, strValue); return *this; } | |
168 | wxRegKey& operator=(long lValue) | |
169 | { SetValue(NULL, lValue); return *this; } | |
170 | ||
171 | // conversion operators query the default value of the key | |
172 | operator wxString() const; | |
173 | ||
174 | // set the string value | |
175 | bool SetValue(const char *szValue, const wxString& strValue); | |
176 | // return the string value | |
177 | bool QueryValue(const char *szValue, wxString& strValue) const; | |
178 | ||
179 | #ifdef __WIN32__ | |
180 | // set the numeric value | |
181 | bool SetValue(const char *szValue, long lValue); | |
182 | // return the numeric value | |
183 | bool QueryValue(const char *szValue, long *plValue) const; | |
184 | #endif //Win32 | |
185 | ||
2dc77646 VZ |
186 | // query existence of a key/value |
187 | // return true if value exists | |
188 | bool HasValue(const char *szKey) const; | |
189 | // return true if given subkey exists | |
2bda0e17 | 190 | bool HasSubKey(const char *szKey) const; |
2dc77646 | 191 | // return true if any subkeys exist |
2bda0e17 KB |
192 | bool HasSubkeys() const; |
193 | ||
194 | // enumerate values and subkeys | |
2bda0e17 KB |
195 | bool GetFirstValue(wxString& strValueName, long& lIndex); |
196 | bool GetNextValue (wxString& strValueName, long& lIndex) const; | |
2bda0e17 KB |
197 | |
198 | bool GetFirstKey (wxString& strKeyName , long& lIndex); | |
199 | bool GetNextKey (wxString& strKeyName , long& lIndex) const; | |
200 | ||
201 | private: | |
202 | // no copy ctor/assignment operator | |
203 | wxRegKey(const wxRegKey& key); // not implemented | |
204 | wxRegKey& operator=(const wxRegKey& key); // not implemented | |
205 | ||
c085e333 | 206 | WXHKEY m_hKey, // our handle |
2bda0e17 KB |
207 | m_hRootKey; // handle of the top key (i.e. StdKey) |
208 | wxString m_strKey; // key name (relative to m_hRootKey) | |
209 | ||
210 | MUTABLE long m_dwLastError; // last error (0 if none) | |
211 | }; | |
212 | ||
213 | #endif //_REGISTRY_H | |
2dc77646 | 214 |