1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/registry.h
3 // Purpose: interface of wxRegKey
4 // Author: wxWidgets team
6 // Licence: wxWindows license
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.
77 The constructor to set the full name of the key.
79 wxRegKey(const wxString
& strKey
);
81 The constructor to set the full name of the key using one of the
82 standard keys, that is, HKCR, HKCU, HKLM, HKUSR, HKPD, HKCC or HKDD.
84 wxRegKey(StdKey keyParent
, const wxString
& strKey
);
86 The constructor to set the full name of the key under a previously created
89 wxRegKey(const wxRegKey
& keyParent
, const wxString
& strKey
);
92 Access modes for wxRegKey.
97 Write
///< Read and Write
101 The standard registry key enumerator.
105 HKCR
, ///< HKEY_CLASSES_ROOT
106 HKCU
, ///< HKEY_CURRENT_USER
107 HKLM
, ///< HKEY_LOCAL_MACHINE
108 HKUSR
, ///< HKEY_USERS
109 HKPD
, ///< HKEY_PERFORMANCE_DATA (Windows NT and 2K only)
110 HKCC
, ///< HKEY_CURRENT_CONFIG
111 HKDD
, ///< HKEY_DYN_DATA (Windows 95 and 98 only)
116 The value type enumerator.
120 Type_None
, ///< No value type
121 Type_String
, ///< Unicode null-terminated string
122 Type_Expand_String
, ///< Unicode null-terminated string
123 ///< (with environment variable references)
124 Type_Binary
, ///< Free form binary
125 Type_Dword
, ///< 32-bit number
126 Type_Dword_little_endian
, ///< 32-bit number (same as Type_Dword)
127 Type_Dword_big_endian
, ///< 32-bit number
128 Type_Link
, ///< Symbolic Link (Unicode)
129 Type_Multi_String
, ///< Multiple Unicode strings
130 Type_Resource_list
, ///< Resource list in the resource map
131 Type_Full_resource_descriptor
, ///< Resource list in the hardware description
132 Type_Resource_requirements_list
///<
141 Copy the entire contents of the key recursively to another location
142 using the name. Returns @true if successful.
144 bool Copy(const wxString
& szNewName
);
146 Copy the entire contents of the key recursively to another location
147 using the key. Returns @true if successful.
149 bool Copy(wxRegKey
& keyDst
);
152 Copy the value to another key, possibly changing its name. By default
153 it will remain the same. Returns @true if successful.
155 bool CopyValue(const wxString
& szValue
, wxRegKey
& keyDst
,
156 const wxString
& szNewName
= wxEmptyString
);
158 Creates the key. Will fail if the key already exists and @a bOkIfExists
159 is @false. Returns @true if successful.
161 bool Create(bool bOkIfExists
= true);
164 Deletes the subkey with all its subkeys and values recursively.
166 void DeleteKey(const wxString
& szKey
);
169 Deletes this key and all its subkeys and values recursively.
174 Deletes the named value or use an empty string argument to remove the
175 default value of the key.
177 void DeleteValue(const wxString
& szKey
);
180 Returns @true if the key exists.
185 Write the contents of this key and all its subkeys to the given file.
186 (The file will not be overwritten; it's an error if it already exists.)
187 Note that we export the key in REGEDIT4 format, not RegSaveKey() binary
188 format nor the newer REGEDIT5. Returns @true if successful.
190 bool Export(const wxString
& filename
) const;
192 Write the contents of this key and all its subkeys to the opened stream.
193 Returns @true if successful.
195 bool Export(wxOutputStream
& ostr
) const;
198 Gets the first key. Returns @true if successful.
200 bool GetFirstKey(wxString
& strKeyName
, long& lIndex
);
203 Gets the first value of this key. Returns @true if successful.
205 bool GetFirstValue(wxString
& strValueName
, long& lIndex
);
208 Gets information about the key. Returns @true if successful.
211 The number of subkeys.
213 The maximum length of the subkey name.
215 The number of values.
217 The maximum length of a value.
219 bool GetKeyInfo(size_t* pnSubKeys
, size_t* pnMaxKeyLen
,
220 size_t* pnValues
, size_t* pnMaxValueLen
) const;
223 Gets the name of the registry key.
225 wxString
GetName(bool bShortPrefix
= true) const;
228 Gets the next key. Returns @true if successful.
230 bool GetNextKey(wxString
& strKeyName
, long& lIndex
) const;
233 Gets the next key value for this key. Returns @true if successful.
235 bool GetNextValue(wxString
& strValueName
, long& lIndex
) const;
240 ValueType
GetValueType(const wxString
& szValue
) const;
243 Returns @true if given subkey exists.
245 bool HasSubKey(const wxString
& szKey
) const;
248 Returns @true if any subkeys exist.
250 bool HasSubKeys() const;
253 Returns @true if the value exists.
255 bool HasValue(const wxString
& szValue
) const;
258 Returns @true if any values exist.
260 bool HasValues() const;
263 Returns @true if this key is empty, nothing under this key.
265 bool IsEmpty() const;
268 Returns @true if the value contains a number.
270 bool IsNumericValue(const wxString
& szValue
) const;
273 Returns @true if the key is opened.
275 bool IsOpened() const;
278 Explicitly opens the key. This method also allows the key to be opened
279 in read-only mode by passing wxRegKey::Read instead of default
280 wxRegKey::Write parameter. Returns @true if successful.
282 bool Open(AccessMode mode
= Write
);
285 Assignment operator to set the default value of the key.
287 wxRegKey
& operator=(const wxString
& strValue
);
290 Return the default value of the key.
292 wxString
QueryDefaultValue() const;
295 Retrieves the raw string value. Returns @true if successful.
297 bool QueryRawValue(const wxString
& szValue
, wxString
& strValue
) const;
300 Retrieves the raw or expanded string value. Returns @true if successful.
302 bool QueryValue(const wxString
& szValue
, wxString
& strValue
, bool raw
) const;
305 Retrieves the numeric value. Returns @true if successful.
307 bool QueryValue(const wxString
& szValue
, long* plValue
) const;
310 Retrieves the binary structure. Returns @true if successful.
312 bool QueryValue(const wxString
& szValue
, wxMemoryBuffer
& buf
) const;
315 Renames the key. Returns @true if successful.
317 bool Rename(const wxString
& szNewName
);
320 Renames a value. Returns @true if successful.
322 bool RenameValue(const wxString
& szValueOld
,
323 const wxString
& szValueNew
);
326 Preallocate some memory for the name. For wxRegConfig usage only.
328 void ReserveMemoryForName(size_t bytes
);
331 Set or change the HKEY handle.
333 void SetHkey(WXHKEY hKey
);
336 Set the full key name. The name is absolute. It should start with
339 void SetName(const wxString
& strKey
);
341 Set the name relative to the parent key
343 void SetName(StdKey keyParent
, const wxString
& strKey
);
345 Set the name relative to the parent key
347 void SetName(const wxRegKey
& keyParent
, const wxString
& strKey
);
350 Sets the given @a szValue which must be numeric. If the value doesn't
351 exist, it is created. Returns @true if successful.
353 bool SetValue(const wxString
& szValue
, long lValue
);
355 Sets the given @a szValue which must be string. If the value doesn't
356 exist, it is created. Returns @true if successful.
358 bool SetValue(const wxString
& szValue
, const wxString
& strValue
);
360 Sets the given @a szValue which must be binary. If the value doesn't
361 exist, it is created. Returns @true if successful.
363 bool SetValue(const wxString
& szValue
, const wxMemoryBuffer
& buf
);