]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: msw/registry.h | |
e54c96f1 | 3 | // Purpose: interface of wxRegKey |
23324ae1 | 4 | // Author: wxWidgets team |
526954c5 | 5 | // Licence: wxWindows licence |
23324ae1 FM |
6 | ///////////////////////////////////////////////////////////////////////////// |
7 | ||
8 | /** | |
9 | @class wxRegKey | |
7c913512 | 10 | |
23324ae1 FM |
11 | wxRegKey is a class representing the Windows registry (it is only available |
12 | under Windows). One can create, query and delete registry keys using this | |
13 | class. | |
7c913512 | 14 | |
23324ae1 FM |
15 | The Windows registry is easy to understand. There are five registry keys, |
16 | namely: | |
7c913512 | 17 | |
9602ce3d BP |
18 | @li @c HKEY_CLASSES_ROOT (HKCR) |
19 | @li @c HKEY_CURRENT_USER (HKCU) | |
20 | @li @c HKEY_LOCAL_MACHINE (HKLM) | |
21 | @li @c HKEY_CURRENT_CONFIG (HKCC) | |
22 | @li @c HKEY_USERS (HKU) | |
7c913512 | 23 | |
23324ae1 | 24 | After creating a key, it can hold a value. The values can be: |
7c913512 | 25 | |
bbc5b7f8 BP |
26 | @li String Value |
27 | @li Binary Value | |
28 | @li DWORD Value | |
29 | @li Multi String Value | |
30 | @li Expandable String Value | |
7c913512 | 31 | |
d9faa1fe | 32 | @onlyfor{wxmsw} |
7c913512 | 33 | |
bbc5b7f8 BP |
34 | @b Example: |
35 | ||
36 | @code | |
03c9cce5 VZ |
37 | // This assume that the key already exists, use HasSubKey() to check |
38 | // for the key existence if necessary. | |
39 | wxRegKey key(wxRegKey::HKLM, "Software\\MyKey"); | |
bbc5b7f8 | 40 | |
4c51a665 | 41 | // Create a new value "MyValue" and set it to 12. |
03c9cce5 | 42 | key.SetValue("MyValue", 12); |
bbc5b7f8 BP |
43 | |
44 | // Read the value back. | |
45 | long value; | |
03c9cce5 | 46 | key.QueryValue("MyValue", &value); |
bbc5b7f8 BP |
47 | wxMessageBox(wxString::Format("%d", value), "Registry Value", wxOK); |
48 | ||
49 | // Get the number of subkeys and enumerate them. | |
50 | size_t subkeys; | |
03c9cce5 | 51 | key.GetKeyInfo(&subkeys, NULL, NULL, NULL); |
bbc5b7f8 BP |
52 | |
53 | wxString key_name; | |
03c9cce5 | 54 | key.GetFirstKey(key_name, 1); |
bbc5b7f8 BP |
55 | for(int i = 0; i < subkeys; i++) |
56 | { | |
57 | wxMessageBox(key_name, "Subkey Name", wxOK); | |
03c9cce5 | 58 | key.GetNextKey(key_name, 1); |
bbc5b7f8 BP |
59 | } |
60 | @endcode | |
3c99e2fd FM |
61 | |
62 | ||
63 | @library{wxbase} | |
64 | @category{cfg} | |
23324ae1 | 65 | */ |
7c913512 | 66 | class wxRegKey |
23324ae1 FM |
67 | { |
68 | public: | |
23324ae1 | 69 | /** |
9602ce3d | 70 | Default constructor, initializes to @c HKEY_CLASSES_ROOT. |
a5c46848 VZ |
71 | |
72 | The @a viewMode parameter is new since wxWidgets 2.9.2. | |
23324ae1 | 73 | */ |
a5c46848 | 74 | wxRegKey(WOW64ViewMode viewMode = WOW64ViewMode_Default); |
bbc5b7f8 BP |
75 | /** |
76 | The constructor to set the full name of the key. | |
a5c46848 VZ |
77 | |
78 | The @a viewMode parameter is new since wxWidgets 2.9.2. | |
bbc5b7f8 | 79 | */ |
a5c46848 VZ |
80 | wxRegKey(const wxString& strKey, |
81 | WOW64ViewMode viewMode = WOW64ViewMode_Default); | |
69e037ac | 82 | /** |
3c99e2fd | 83 | The constructor to set the full name of the key using one of the |
69e037ac | 84 | standard keys, that is, HKCR, HKCU, HKLM, HKUSR, HKPD, HKCC or HKDD. |
a5c46848 | 85 | The @a viewMode parameter is new since wxWidgets 2.9.2. |
69e037ac | 86 | */ |
a5c46848 VZ |
87 | wxRegKey(StdKey keyParent, const wxString& strKey, |
88 | WOW64ViewMode viewMode = WOW64ViewMode_Default); | |
bbc5b7f8 | 89 | /** |
a5c46848 VZ |
90 | The constructor to set the full name of the key under a previously |
91 | created parent. The registry view is inherited from the parent. | |
bbc5b7f8 | 92 | */ |
7c913512 | 93 | wxRegKey(const wxRegKey& keyParent, const wxString& strKey); |
bbc5b7f8 BP |
94 | |
95 | /** | |
96 | Access modes for wxRegKey. | |
97 | */ | |
98 | enum AccessMode | |
99 | { | |
69e037ac VZ |
100 | Read, ///< Read-only |
101 | Write ///< Read and Write | |
102 | }; | |
103 | ||
3c99e2fd | 104 | /** |
69e037ac VZ |
105 | The standard registry key enumerator. |
106 | */ | |
107 | enum StdKey | |
108 | { | |
109 | HKCR, ///< HKEY_CLASSES_ROOT | |
110 | HKCU, ///< HKEY_CURRENT_USER | |
111 | HKLM, ///< HKEY_LOCAL_MACHINE | |
112 | HKUSR, ///< HKEY_USERS | |
113 | HKPD, ///< HKEY_PERFORMANCE_DATA (Windows NT and 2K only) | |
114 | HKCC, ///< HKEY_CURRENT_CONFIG | |
115 | HKDD, ///< HKEY_DYN_DATA (Windows 95 and 98 only) | |
116 | HKMAX | |
117 | }; | |
118 | ||
119 | /** | |
120 | The value type enumerator. | |
121 | */ | |
122 | enum ValueType | |
123 | { | |
124 | Type_None, ///< No value type | |
125 | Type_String, ///< Unicode null-terminated string | |
126 | Type_Expand_String, ///< Unicode null-terminated string | |
127 | ///< (with environment variable references) | |
128 | Type_Binary, ///< Free form binary | |
129 | Type_Dword, ///< 32-bit number | |
130 | Type_Dword_little_endian, ///< 32-bit number (same as Type_Dword) | |
131 | Type_Dword_big_endian, ///< 32-bit number | |
132 | Type_Link, ///< Symbolic Link (Unicode) | |
133 | Type_Multi_String, ///< Multiple Unicode strings | |
134 | Type_Resource_list, ///< Resource list in the resource map | |
135 | Type_Full_resource_descriptor, ///< Resource list in the hardware description | |
3c99e2fd | 136 | Type_Resource_requirements_list ///< |
bbc5b7f8 | 137 | }; |
23324ae1 | 138 | |
a5c46848 VZ |
139 | /** |
140 | Used to determine how the registry will be viewed, either as | |
141 | 32-bit or 64-bit. | |
142 | ||
143 | @since 2.9.2 | |
144 | */ | |
145 | enum WOW64ViewMode | |
146 | { | |
147 | /** | |
148 | Uses 32-bit registry for 32-bit applications and | |
149 | 64-bit registry for 64-bit ones. | |
150 | */ | |
151 | WOW64ViewMode_Default, | |
152 | ||
153 | /** | |
154 | Can be used in 64-bit apps to access the 32-bit registry, | |
155 | has no effect (i.e. treated as default) in 32-bit apps. | |
156 | */ | |
157 | WOW64ViewMode_32, | |
158 | ||
159 | /** | |
160 | Can be used in 32-bit apps to access the 64-bit registry, | |
161 | has no effect (i.e. treated as default) in 64-bit apps. | |
162 | */ | |
163 | WOW64ViewMode_64 | |
164 | }; | |
165 | ||
23324ae1 FM |
166 | /** |
167 | Closes the key. | |
168 | */ | |
169 | void Close(); | |
170 | ||
69e037ac VZ |
171 | /** |
172 | Copy the entire contents of the key recursively to another location | |
a90280fe | 173 | using the name. Returns @true if successful. |
69e037ac VZ |
174 | */ |
175 | bool Copy(const wxString& szNewName); | |
176 | /** | |
177 | Copy the entire contents of the key recursively to another location | |
a90280fe | 178 | using the key. Returns @true if successful. |
69e037ac VZ |
179 | */ |
180 | bool Copy(wxRegKey& keyDst); | |
3c99e2fd | 181 | |
69e037ac VZ |
182 | /** |
183 | Copy the value to another key, possibly changing its name. By default | |
a90280fe | 184 | it will remain the same. Returns @true if successful. |
69e037ac | 185 | */ |
3c99e2fd | 186 | bool CopyValue(const wxString& szValue, wxRegKey& keyDst, |
69e037ac | 187 | const wxString& szNewName = wxEmptyString); |
23324ae1 | 188 | /** |
a90280fe BP |
189 | Creates the key. Will fail if the key already exists and @a bOkIfExists |
190 | is @false. Returns @true if successful. | |
23324ae1 | 191 | */ |
4cc4bfaf | 192 | bool Create(bool bOkIfExists = true); |
23324ae1 FM |
193 | |
194 | /** | |
a90280fe | 195 | Deletes the subkey with all its subkeys and values recursively. |
23324ae1 | 196 | */ |
920b92a3 | 197 | void DeleteKey(const wxString& szKey); |
23324ae1 FM |
198 | |
199 | /** | |
a90280fe | 200 | Deletes this key and all its subkeys and values recursively. |
23324ae1 FM |
201 | */ |
202 | void DeleteSelf(); | |
203 | ||
204 | /** | |
3c99e2fd | 205 | Deletes the named value or use an empty string argument to remove the |
a90280fe | 206 | default value of the key. |
23324ae1 | 207 | */ |
920b92a3 | 208 | void DeleteValue(const wxString& szKey); |
23324ae1 FM |
209 | |
210 | /** | |
211 | Returns @true if the key exists. | |
212 | */ | |
bbc5b7f8 | 213 | bool Exists() const; |
23324ae1 | 214 | |
69e037ac VZ |
215 | /** |
216 | Write the contents of this key and all its subkeys to the given file. | |
217 | (The file will not be overwritten; it's an error if it already exists.) | |
218 | Note that we export the key in REGEDIT4 format, not RegSaveKey() binary | |
a90280fe | 219 | format nor the newer REGEDIT5. Returns @true if successful. |
69e037ac VZ |
220 | */ |
221 | bool Export(const wxString& filename) const; | |
222 | /** | |
223 | Write the contents of this key and all its subkeys to the opened stream. | |
a90280fe | 224 | Returns @true if successful. |
69e037ac VZ |
225 | */ |
226 | bool Export(wxOutputStream& ostr) const; | |
3c99e2fd | 227 | |
23324ae1 | 228 | /** |
a90280fe | 229 | Gets the first key. Returns @true if successful. |
23324ae1 FM |
230 | */ |
231 | bool GetFirstKey(wxString& strKeyName, long& lIndex); | |
232 | ||
233 | /** | |
a90280fe | 234 | Gets the first value of this key. Returns @true if successful. |
23324ae1 FM |
235 | */ |
236 | bool GetFirstValue(wxString& strValueName, long& lIndex); | |
237 | ||
238 | /** | |
a90280fe | 239 | Gets information about the key. Returns @true if successful. |
d9faa1fe | 240 | |
7c913512 | 241 | @param pnSubKeys |
4cc4bfaf | 242 | The number of subkeys. |
7c913512 | 243 | @param pnMaxKeyLen |
4cc4bfaf | 244 | The maximum length of the subkey name. |
7c913512 | 245 | @param pnValues |
4cc4bfaf | 246 | The number of values. |
7c913512 | 247 | @param pnMaxValueLen |
4cc4bfaf | 248 | The maximum length of a value. |
23324ae1 | 249 | */ |
bbc5b7f8 BP |
250 | bool GetKeyInfo(size_t* pnSubKeys, size_t* pnMaxKeyLen, |
251 | size_t* pnValues, size_t* pnMaxValueLen) const; | |
23324ae1 FM |
252 | |
253 | /** | |
254 | Gets the name of the registry key. | |
255 | */ | |
328f5751 | 256 | wxString GetName(bool bShortPrefix = true) const; |
23324ae1 | 257 | |
a5c46848 VZ |
258 | /** |
259 | Retrieves the registry view used by this key. | |
260 | ||
261 | @since 2.9.2 | |
262 | ||
263 | @return The registry view given at the object's construction. | |
264 | */ | |
265 | WOW64ViewMode GetView() const { return m_viewMode; } | |
266 | ||
23324ae1 | 267 | /** |
a90280fe | 268 | Gets the next key. Returns @true if successful. |
23324ae1 | 269 | */ |
328f5751 | 270 | bool GetNextKey(wxString& strKeyName, long& lIndex) const; |
23324ae1 FM |
271 | |
272 | /** | |
a90280fe | 273 | Gets the next key value for this key. Returns @true if successful. |
23324ae1 | 274 | */ |
328f5751 | 275 | bool GetNextValue(wxString& strValueName, long& lIndex) const; |
23324ae1 | 276 | |
69e037ac VZ |
277 | /** |
278 | Gets the value type. | |
279 | */ | |
280 | ValueType GetValueType(const wxString& szValue) const; | |
3c99e2fd | 281 | |
23324ae1 FM |
282 | /** |
283 | Returns @true if given subkey exists. | |
284 | */ | |
920b92a3 | 285 | bool HasSubKey(const wxString& szKey) const; |
23324ae1 FM |
286 | |
287 | /** | |
288 | Returns @true if any subkeys exist. | |
289 | */ | |
267c55c3 | 290 | bool HasSubkeys() const; |
23324ae1 FM |
291 | |
292 | /** | |
293 | Returns @true if the value exists. | |
294 | */ | |
920b92a3 | 295 | bool HasValue(const wxString& szValue) const; |
23324ae1 FM |
296 | |
297 | /** | |
298 | Returns @true if any values exist. | |
299 | */ | |
328f5751 | 300 | bool HasValues() const; |
23324ae1 FM |
301 | |
302 | /** | |
303 | Returns @true if this key is empty, nothing under this key. | |
304 | */ | |
328f5751 | 305 | bool IsEmpty() const; |
23324ae1 | 306 | |
69e037ac | 307 | /** |
a90280fe | 308 | Returns @true if the value contains a number. |
69e037ac VZ |
309 | */ |
310 | bool IsNumericValue(const wxString& szValue) const; | |
311 | ||
23324ae1 FM |
312 | /** |
313 | Returns @true if the key is opened. | |
314 | */ | |
328f5751 | 315 | bool IsOpened() const; |
23324ae1 FM |
316 | |
317 | /** | |
a90280fe BP |
318 | Explicitly opens the key. This method also allows the key to be opened |
319 | in read-only mode by passing wxRegKey::Read instead of default | |
320 | wxRegKey::Write parameter. Returns @true if successful. | |
23324ae1 FM |
321 | */ |
322 | bool Open(AccessMode mode = Write); | |
323 | ||
a90280fe BP |
324 | /** |
325 | Assignment operator to set the default value of the key. | |
326 | */ | |
327 | wxRegKey& operator=(const wxString& strValue); | |
328 | ||
23324ae1 | 329 | /** |
69e037ac VZ |
330 | Return the default value of the key. |
331 | */ | |
332 | wxString QueryDefaultValue() const; | |
333 | ||
334 | /** | |
a90280fe | 335 | Retrieves the raw string value. Returns @true if successful. |
3a326bfe | 336 | An empty @a szValue queries the default/unnamed key value. |
23324ae1 | 337 | */ |
69e037ac VZ |
338 | bool QueryRawValue(const wxString& szValue, wxString& strValue) const; |
339 | ||
340 | /** | |
a90280fe | 341 | Retrieves the raw or expanded string value. Returns @true if successful. |
3a326bfe | 342 | An empty @a szValue queries the default/unnamed key value. |
69e037ac VZ |
343 | */ |
344 | bool QueryValue(const wxString& szValue, wxString& strValue, bool raw) const; | |
bbc5b7f8 BP |
345 | |
346 | /** | |
a90280fe | 347 | Retrieves the numeric value. Returns @true if successful. |
3a326bfe | 348 | An empty @a szValue queries the default/unnamed key value. |
bbc5b7f8 | 349 | */ |
69e037ac VZ |
350 | bool QueryValue(const wxString& szValue, long* plValue) const; |
351 | ||
352 | /** | |
a90280fe | 353 | Retrieves the binary structure. Returns @true if successful. |
3a326bfe | 354 | An empty @a szValue queries the default/unnamed key value. |
69e037ac VZ |
355 | */ |
356 | bool QueryValue(const wxString& szValue, wxMemoryBuffer& buf) const; | |
23324ae1 FM |
357 | |
358 | /** | |
a90280fe | 359 | Renames the key. Returns @true if successful. |
23324ae1 | 360 | */ |
920b92a3 | 361 | bool Rename(const wxString& szNewName); |
23324ae1 FM |
362 | |
363 | /** | |
a90280fe | 364 | Renames a value. Returns @true if successful. |
23324ae1 | 365 | */ |
920b92a3 FM |
366 | bool RenameValue(const wxString& szValueOld, |
367 | const wxString& szValueNew); | |
23324ae1 | 368 | |
69e037ac VZ |
369 | /** |
370 | Preallocate some memory for the name. For wxRegConfig usage only. | |
371 | */ | |
3c99e2fd | 372 | void ReserveMemoryForName(size_t bytes); |
69e037ac VZ |
373 | |
374 | /** | |
375 | Set or change the HKEY handle. | |
376 | */ | |
377 | void SetHkey(WXHKEY hKey); | |
3c99e2fd | 378 | |
69e037ac VZ |
379 | /** |
380 | Set the full key name. The name is absolute. It should start with | |
381 | HKEY_xxx. | |
382 | */ | |
383 | void SetName(const wxString& strKey); | |
384 | /** | |
385 | Set the name relative to the parent key | |
386 | */ | |
387 | void SetName(StdKey keyParent, const wxString& strKey); | |
388 | /** | |
389 | Set the name relative to the parent key | |
390 | */ | |
391 | void SetName(const wxRegKey& keyParent, const wxString& strKey); | |
3c99e2fd | 392 | |
23324ae1 | 393 | /** |
a90280fe BP |
394 | Sets the given @a szValue which must be numeric. If the value doesn't |
395 | exist, it is created. Returns @true if successful. | |
3a326bfe | 396 | An empty @a szValue sets the default/unnamed key value. |
23324ae1 | 397 | */ |
920b92a3 | 398 | bool SetValue(const wxString& szValue, long lValue); |
bbc5b7f8 | 399 | /** |
a90280fe BP |
400 | Sets the given @a szValue which must be string. If the value doesn't |
401 | exist, it is created. Returns @true if successful. | |
3a326bfe | 402 | An empty @a szValue sets the default/unnamed key value. |
bbc5b7f8 | 403 | */ |
920b92a3 | 404 | bool SetValue(const wxString& szValue, const wxString& strValue); |
bbc5b7f8 | 405 | /** |
3c99e2fd | 406 | Sets the given @a szValue which must be binary. If the value doesn't |
a90280fe | 407 | exist, it is created. Returns @true if successful. |
3a326bfe | 408 | An empty @a szValue sets the default/unnamed key value. |
bbc5b7f8 | 409 | */ |
920b92a3 | 410 | bool SetValue(const wxString& szValue, const wxMemoryBuffer& buf); |
23324ae1 | 411 | }; |