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 wxRegKey *key = new wxRegKey("HKEY_LOCAL_MACHINE\\Software\\MyKey");
40 // Create the key if it does not exist.
44 // Create a new value "MYVALUE" and set it to 12.
45 key->SetValue("MYVALUE", 12);
47 // Read the value back.
49 key->QueryValue("MYVALUE", &value);
50 wxMessageBox(wxString::Format("%d", value), "Registry Value", wxOK);
52 // Get the number of subkeys and enumerate them.
54 key->GetKeyInfo(&subkeys, NULL, NULL, NULL);
57 key->GetFirstKey(key_name, 1);
58 for(int i = 0; i < subkeys; i++)
60 wxMessageBox(key_name, "Subkey Name", wxOK);
61 key->GetNextKey(key_name, 1);
73 Default constructor, initializes to @c HKEY_CLASSES_ROOT.
75 The @a viewMode parameter is new since wxWidgets 2.9.2.
77 wxRegKey(WOW64ViewMode viewMode
= WOW64ViewMode_Default
);
79 The constructor to set the full name of the key.
81 The @a viewMode parameter is new since wxWidgets 2.9.2.
83 wxRegKey(const wxString
& strKey
,
84 WOW64ViewMode viewMode
= WOW64ViewMode_Default
);
86 The constructor to set the full name of the key using one of the
87 standard keys, that is, HKCR, HKCU, HKLM, HKUSR, HKPD, HKCC or HKDD.
88 The @a viewMode parameter is new since wxWidgets 2.9.2.
90 wxRegKey(StdKey keyParent
, const wxString
& strKey
,
91 WOW64ViewMode viewMode
= WOW64ViewMode_Default
);
93 The constructor to set the full name of the key under a previously
94 created parent. The registry view is inherited from the parent.
96 wxRegKey(const wxRegKey
& keyParent
, const wxString
& strKey
);
99 Access modes for wxRegKey.
104 Write
///< Read and Write
108 The standard registry key enumerator.
112 HKCR
, ///< HKEY_CLASSES_ROOT
113 HKCU
, ///< HKEY_CURRENT_USER
114 HKLM
, ///< HKEY_LOCAL_MACHINE
115 HKUSR
, ///< HKEY_USERS
116 HKPD
, ///< HKEY_PERFORMANCE_DATA (Windows NT and 2K only)
117 HKCC
, ///< HKEY_CURRENT_CONFIG
118 HKDD
, ///< HKEY_DYN_DATA (Windows 95 and 98 only)
123 The value type enumerator.
127 Type_None
, ///< No value type
128 Type_String
, ///< Unicode null-terminated string
129 Type_Expand_String
, ///< Unicode null-terminated string
130 ///< (with environment variable references)
131 Type_Binary
, ///< Free form binary
132 Type_Dword
, ///< 32-bit number
133 Type_Dword_little_endian
, ///< 32-bit number (same as Type_Dword)
134 Type_Dword_big_endian
, ///< 32-bit number
135 Type_Link
, ///< Symbolic Link (Unicode)
136 Type_Multi_String
, ///< Multiple Unicode strings
137 Type_Resource_list
, ///< Resource list in the resource map
138 Type_Full_resource_descriptor
, ///< Resource list in the hardware description
139 Type_Resource_requirements_list
///<
143 Used to determine how the registry will be viewed, either as
151 Uses 32-bit registry for 32-bit applications and
152 64-bit registry for 64-bit ones.
154 WOW64ViewMode_Default
,
157 Can be used in 64-bit apps to access the 32-bit registry,
158 has no effect (i.e. treated as default) in 32-bit apps.
163 Can be used in 32-bit apps to access the 64-bit registry,
164 has no effect (i.e. treated as default) in 64-bit apps.
175 Copy the entire contents of the key recursively to another location
176 using the name. Returns @true if successful.
178 bool Copy(const wxString
& szNewName
);
180 Copy the entire contents of the key recursively to another location
181 using the key. Returns @true if successful.
183 bool Copy(wxRegKey
& keyDst
);
186 Copy the value to another key, possibly changing its name. By default
187 it will remain the same. Returns @true if successful.
189 bool CopyValue(const wxString
& szValue
, wxRegKey
& keyDst
,
190 const wxString
& szNewName
= wxEmptyString
);
192 Creates the key. Will fail if the key already exists and @a bOkIfExists
193 is @false. Returns @true if successful.
195 bool Create(bool bOkIfExists
= true);
198 Deletes the subkey with all its subkeys and values recursively.
200 void DeleteKey(const wxString
& szKey
);
203 Deletes this key and all its subkeys and values recursively.
208 Deletes the named value or use an empty string argument to remove the
209 default value of the key.
211 void DeleteValue(const wxString
& szKey
);
214 Returns @true if the key exists.
219 Write the contents of this key and all its subkeys to the given file.
220 (The file will not be overwritten; it's an error if it already exists.)
221 Note that we export the key in REGEDIT4 format, not RegSaveKey() binary
222 format nor the newer REGEDIT5. Returns @true if successful.
224 bool Export(const wxString
& filename
) const;
226 Write the contents of this key and all its subkeys to the opened stream.
227 Returns @true if successful.
229 bool Export(wxOutputStream
& ostr
) const;
232 Gets the first key. Returns @true if successful.
234 bool GetFirstKey(wxString
& strKeyName
, long& lIndex
);
237 Gets the first value of this key. Returns @true if successful.
239 bool GetFirstValue(wxString
& strValueName
, long& lIndex
);
242 Gets information about the key. Returns @true if successful.
245 The number of subkeys.
247 The maximum length of the subkey name.
249 The number of values.
251 The maximum length of a value.
253 bool GetKeyInfo(size_t* pnSubKeys
, size_t* pnMaxKeyLen
,
254 size_t* pnValues
, size_t* pnMaxValueLen
) const;
257 Gets the name of the registry key.
259 wxString
GetName(bool bShortPrefix
= true) const;
262 Retrieves the registry view used by this key.
266 @return The registry view given at the object's construction.
268 WOW64ViewMode
GetView() const { return m_viewMode
; }
271 Gets the next key. Returns @true if successful.
273 bool GetNextKey(wxString
& strKeyName
, long& lIndex
) const;
276 Gets the next key value for this key. Returns @true if successful.
278 bool GetNextValue(wxString
& strValueName
, long& lIndex
) const;
283 ValueType
GetValueType(const wxString
& szValue
) const;
286 Returns @true if given subkey exists.
288 bool HasSubKey(const wxString
& szKey
) const;
291 Returns @true if any subkeys exist.
293 bool HasSubKeys() const;
296 Returns @true if the value exists.
298 bool HasValue(const wxString
& szValue
) const;
301 Returns @true if any values exist.
303 bool HasValues() const;
306 Returns @true if this key is empty, nothing under this key.
308 bool IsEmpty() const;
311 Returns @true if the value contains a number.
313 bool IsNumericValue(const wxString
& szValue
) const;
316 Returns @true if the key is opened.
318 bool IsOpened() const;
321 Explicitly opens the key. This method also allows the key to be opened
322 in read-only mode by passing wxRegKey::Read instead of default
323 wxRegKey::Write parameter. Returns @true if successful.
325 bool Open(AccessMode mode
= Write
);
328 Assignment operator to set the default value of the key.
330 wxRegKey
& operator=(const wxString
& strValue
);
333 Return the default value of the key.
335 wxString
QueryDefaultValue() const;
338 Retrieves the raw string value. Returns @true if successful.
339 An empty @a szValue queries the default/unnamed key value.
341 bool QueryRawValue(const wxString
& szValue
, wxString
& strValue
) const;
344 Retrieves the raw or expanded string value. Returns @true if successful.
345 An empty @a szValue queries the default/unnamed key value.
347 bool QueryValue(const wxString
& szValue
, wxString
& strValue
, bool raw
) const;
350 Retrieves the numeric value. Returns @true if successful.
351 An empty @a szValue queries the default/unnamed key value.
353 bool QueryValue(const wxString
& szValue
, long* plValue
) const;
356 Retrieves the binary structure. Returns @true if successful.
357 An empty @a szValue queries the default/unnamed key value.
359 bool QueryValue(const wxString
& szValue
, wxMemoryBuffer
& buf
) const;
362 Renames the key. Returns @true if successful.
364 bool Rename(const wxString
& szNewName
);
367 Renames a value. Returns @true if successful.
369 bool RenameValue(const wxString
& szValueOld
,
370 const wxString
& szValueNew
);
373 Preallocate some memory for the name. For wxRegConfig usage only.
375 void ReserveMemoryForName(size_t bytes
);
378 Set or change the HKEY handle.
380 void SetHkey(WXHKEY hKey
);
383 Set the full key name. The name is absolute. It should start with
386 void SetName(const wxString
& strKey
);
388 Set the name relative to the parent key
390 void SetName(StdKey keyParent
, const wxString
& strKey
);
392 Set the name relative to the parent key
394 void SetName(const wxRegKey
& keyParent
, const wxString
& strKey
);
397 Sets the given @a szValue which must be numeric. If the value doesn't
398 exist, it is created. Returns @true if successful.
399 An empty @a szValue sets the default/unnamed key value.
401 bool SetValue(const wxString
& szValue
, long lValue
);
403 Sets the given @a szValue which must be string. If the value doesn't
404 exist, it is created. Returns @true if successful.
405 An empty @a szValue sets the default/unnamed key value.
407 bool SetValue(const wxString
& szValue
, const wxString
& strValue
);
409 Sets the given @a szValue which must be binary. If the value doesn't
410 exist, it is created. Returns @true if successful.
411 An empty @a szValue sets the default/unnamed key value.
413 bool SetValue(const wxString
& szValue
, const wxMemoryBuffer
& buf
);