1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/registry.h
3 // Purpose: interface of wxRegKey
4 // Author: wxWidgets team
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
12 wxRegKey is a class representing the Windows registry (it is only available
13 under Windows). One can create, query and delete registry keys using this
16 The Windows registry is easy to understand. There are five registry keys,
19 @li @c HKEY_CLASSES_ROOT (HKCR)
20 @li @c HKEY_CURRENT_USER (HKCU)
21 @li @c HKEY_LOCAL_MACHINE (HKLM)
22 @li @c HKEY_CURRENT_CONFIG (HKCC)
23 @li @c HKEY_USERS (HKU)
25 After creating a key, it can hold a value. The values can be:
30 @li Multi String Value
31 @li Expandable String Value
38 // This assume that the key already exists, use HasSubKey() to check
39 // for the key existence if necessary.
40 wxRegKey key(wxRegKey::HKLM, "Software\\MyKey");
42 // Create a new value "MYVALUE" and set it to 12.
43 key.SetValue("MyValue", 12);
45 // Read the value back.
47 key.QueryValue("MyValue", &value);
48 wxMessageBox(wxString::Format("%d", value), "Registry Value", wxOK);
50 // Get the number of subkeys and enumerate them.
52 key.GetKeyInfo(&subkeys, NULL, NULL, NULL);
55 key.GetFirstKey(key_name, 1);
56 for(int i = 0; i < subkeys; i++)
58 wxMessageBox(key_name, "Subkey Name", wxOK);
59 key.GetNextKey(key_name, 1);
71 Default constructor, initializes to @c HKEY_CLASSES_ROOT.
73 The @a viewMode parameter is new since wxWidgets 2.9.2.
75 wxRegKey(WOW64ViewMode viewMode
= WOW64ViewMode_Default
);
77 The constructor to set the full name of the key.
79 The @a viewMode parameter is new since wxWidgets 2.9.2.
81 wxRegKey(const wxString
& strKey
,
82 WOW64ViewMode viewMode
= WOW64ViewMode_Default
);
84 The constructor to set the full name of the key using one of the
85 standard keys, that is, HKCR, HKCU, HKLM, HKUSR, HKPD, HKCC or HKDD.
86 The @a viewMode parameter is new since wxWidgets 2.9.2.
88 wxRegKey(StdKey keyParent
, const wxString
& strKey
,
89 WOW64ViewMode viewMode
= WOW64ViewMode_Default
);
91 The constructor to set the full name of the key under a previously
92 created parent. The registry view is inherited from the parent.
94 wxRegKey(const wxRegKey
& keyParent
, const wxString
& strKey
);
97 Access modes for wxRegKey.
102 Write
///< Read and Write
106 The standard registry key enumerator.
110 HKCR
, ///< HKEY_CLASSES_ROOT
111 HKCU
, ///< HKEY_CURRENT_USER
112 HKLM
, ///< HKEY_LOCAL_MACHINE
113 HKUSR
, ///< HKEY_USERS
114 HKPD
, ///< HKEY_PERFORMANCE_DATA (Windows NT and 2K only)
115 HKCC
, ///< HKEY_CURRENT_CONFIG
116 HKDD
, ///< HKEY_DYN_DATA (Windows 95 and 98 only)
121 The value type enumerator.
125 Type_None
, ///< No value type
126 Type_String
, ///< Unicode null-terminated string
127 Type_Expand_String
, ///< Unicode null-terminated string
128 ///< (with environment variable references)
129 Type_Binary
, ///< Free form binary
130 Type_Dword
, ///< 32-bit number
131 Type_Dword_little_endian
, ///< 32-bit number (same as Type_Dword)
132 Type_Dword_big_endian
, ///< 32-bit number
133 Type_Link
, ///< Symbolic Link (Unicode)
134 Type_Multi_String
, ///< Multiple Unicode strings
135 Type_Resource_list
, ///< Resource list in the resource map
136 Type_Full_resource_descriptor
, ///< Resource list in the hardware description
137 Type_Resource_requirements_list
///<
141 Used to determine how the registry will be viewed, either as
149 Uses 32-bit registry for 32-bit applications and
150 64-bit registry for 64-bit ones.
152 WOW64ViewMode_Default
,
155 Can be used in 64-bit apps to access the 32-bit registry,
156 has no effect (i.e. treated as default) in 32-bit apps.
161 Can be used in 32-bit apps to access the 64-bit registry,
162 has no effect (i.e. treated as default) in 64-bit apps.
173 Copy the entire contents of the key recursively to another location
174 using the name. Returns @true if successful.
176 bool Copy(const wxString
& szNewName
);
178 Copy the entire contents of the key recursively to another location
179 using the key. Returns @true if successful.
181 bool Copy(wxRegKey
& keyDst
);
184 Copy the value to another key, possibly changing its name. By default
185 it will remain the same. Returns @true if successful.
187 bool CopyValue(const wxString
& szValue
, wxRegKey
& keyDst
,
188 const wxString
& szNewName
= wxEmptyString
);
190 Creates the key. Will fail if the key already exists and @a bOkIfExists
191 is @false. Returns @true if successful.
193 bool Create(bool bOkIfExists
= true);
196 Deletes the subkey with all its subkeys and values recursively.
198 void DeleteKey(const wxString
& szKey
);
201 Deletes this key and all its subkeys and values recursively.
206 Deletes the named value or use an empty string argument to remove the
207 default value of the key.
209 void DeleteValue(const wxString
& szKey
);
212 Returns @true if the key exists.
217 Write the contents of this key and all its subkeys to the given file.
218 (The file will not be overwritten; it's an error if it already exists.)
219 Note that we export the key in REGEDIT4 format, not RegSaveKey() binary
220 format nor the newer REGEDIT5. Returns @true if successful.
222 bool Export(const wxString
& filename
) const;
224 Write the contents of this key and all its subkeys to the opened stream.
225 Returns @true if successful.
227 bool Export(wxOutputStream
& ostr
) const;
230 Gets the first key. Returns @true if successful.
232 bool GetFirstKey(wxString
& strKeyName
, long& lIndex
);
235 Gets the first value of this key. Returns @true if successful.
237 bool GetFirstValue(wxString
& strValueName
, long& lIndex
);
240 Gets information about the key. Returns @true if successful.
243 The number of subkeys.
245 The maximum length of the subkey name.
247 The number of values.
249 The maximum length of a value.
251 bool GetKeyInfo(size_t* pnSubKeys
, size_t* pnMaxKeyLen
,
252 size_t* pnValues
, size_t* pnMaxValueLen
) const;
255 Gets the name of the registry key.
257 wxString
GetName(bool bShortPrefix
= true) const;
260 Retrieves the registry view used by this key.
264 @return The registry view given at the object's construction.
266 WOW64ViewMode
GetView() const { return m_viewMode
; }
269 Gets the next key. Returns @true if successful.
271 bool GetNextKey(wxString
& strKeyName
, long& lIndex
) const;
274 Gets the next key value for this key. Returns @true if successful.
276 bool GetNextValue(wxString
& strValueName
, long& lIndex
) const;
281 ValueType
GetValueType(const wxString
& szValue
) const;
284 Returns @true if given subkey exists.
286 bool HasSubKey(const wxString
& szKey
) const;
289 Returns @true if any subkeys exist.
291 bool HasSubKeys() const;
294 Returns @true if the value exists.
296 bool HasValue(const wxString
& szValue
) const;
299 Returns @true if any values exist.
301 bool HasValues() const;
304 Returns @true if this key is empty, nothing under this key.
306 bool IsEmpty() const;
309 Returns @true if the value contains a number.
311 bool IsNumericValue(const wxString
& szValue
) const;
314 Returns @true if the key is opened.
316 bool IsOpened() const;
319 Explicitly opens the key. This method also allows the key to be opened
320 in read-only mode by passing wxRegKey::Read instead of default
321 wxRegKey::Write parameter. Returns @true if successful.
323 bool Open(AccessMode mode
= Write
);
326 Assignment operator to set the default value of the key.
328 wxRegKey
& operator=(const wxString
& strValue
);
331 Return the default value of the key.
333 wxString
QueryDefaultValue() const;
336 Retrieves the raw string value. Returns @true if successful.
337 An empty @a szValue queries the default/unnamed key value.
339 bool QueryRawValue(const wxString
& szValue
, wxString
& strValue
) const;
342 Retrieves the raw or expanded string value. Returns @true if successful.
343 An empty @a szValue queries the default/unnamed key value.
345 bool QueryValue(const wxString
& szValue
, wxString
& strValue
, bool raw
) const;
348 Retrieves the numeric value. Returns @true if successful.
349 An empty @a szValue queries the default/unnamed key value.
351 bool QueryValue(const wxString
& szValue
, long* plValue
) const;
354 Retrieves the binary structure. Returns @true if successful.
355 An empty @a szValue queries the default/unnamed key value.
357 bool QueryValue(const wxString
& szValue
, wxMemoryBuffer
& buf
) const;
360 Renames the key. Returns @true if successful.
362 bool Rename(const wxString
& szNewName
);
365 Renames a value. Returns @true if successful.
367 bool RenameValue(const wxString
& szValueOld
,
368 const wxString
& szValueNew
);
371 Preallocate some memory for the name. For wxRegConfig usage only.
373 void ReserveMemoryForName(size_t bytes
);
376 Set or change the HKEY handle.
378 void SetHkey(WXHKEY hKey
);
381 Set the full key name. The name is absolute. It should start with
384 void SetName(const wxString
& strKey
);
386 Set the name relative to the parent key
388 void SetName(StdKey keyParent
, const wxString
& strKey
);
390 Set the name relative to the parent key
392 void SetName(const wxRegKey
& keyParent
, const wxString
& strKey
);
395 Sets the given @a szValue which must be numeric. If the value doesn't
396 exist, it is created. Returns @true if successful.
397 An empty @a szValue sets the default/unnamed key value.
399 bool SetValue(const wxString
& szValue
, long lValue
);
401 Sets the given @a szValue which must be string. If the value doesn't
402 exist, it is created. Returns @true if successful.
403 An empty @a szValue sets the default/unnamed key value.
405 bool SetValue(const wxString
& szValue
, const wxString
& strValue
);
407 Sets the given @a szValue which must be binary. If the value doesn't
408 exist, it is created. Returns @true if successful.
409 An empty @a szValue sets the default/unnamed key value.
411 bool SetValue(const wxString
& szValue
, const wxMemoryBuffer
& buf
);