]> git.saurik.com Git - wxWidgets.git/blob - interface/wx/msw/registry.h
export wxActiveX stuff from core (not media) DLL (closes #8991)
[wxWidgets.git] / interface / wx / msw / registry.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/registry.h
3 // Purpose: interface of wxRegKey
4 // Author: wxWidgets team
5 // RCS-ID: $Id$
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
8
9 /**
10 @class wxRegKey
11
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
14 class.
15
16 The Windows registry is easy to understand. There are five registry keys,
17 namely:
18
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)
24
25 After creating a key, it can hold a value. The values can be:
26
27 @li String Value
28 @li Binary Value
29 @li DWORD Value
30 @li Multi String Value
31 @li Expandable String Value
32
33 @onlyfor{wxmsw}
34
35 @library{wxbase}
36 @category{misc}
37
38 @b Example:
39
40 @code
41 wxRegKey *key = new wxRegKey("HKEY_LOCAL_MACHINE\\Software\\MyKey");
42
43 // Create the key if it does not exist.
44 if( !key->Exists() )
45 key->Create();
46
47 // Create a new value "MYVALUE" and set it to 12.
48 key->SetValue("MYVALUE", 12);
49
50 // Read the value back.
51 long value;
52 key->QueryValue("MYVALUE", &value);
53 wxMessageBox(wxString::Format("%d", value), "Registry Value", wxOK);
54
55 // Get the number of subkeys and enumerate them.
56 size_t subkeys;
57 key->GetKeyInfo(&subkeys, NULL, NULL, NULL);
58
59 wxString key_name;
60 key->GetFirstKey(key_name, 1);
61 for(int i = 0; i < subkeys; i++)
62 {
63 wxMessageBox(key_name, "Subkey Name", wxOK);
64 key->GetNextKey(key_name, 1);
65 }
66 @endcode
67 */
68 class wxRegKey
69 {
70 public:
71 /**
72 Default constructor, initializes to @c HKEY_CLASSES_ROOT.
73 */
74 wxRegKey();
75 /**
76 The constructor to set the full name of the key.
77 */
78 wxRegKey(const wxString& strKey);
79 /**
80 The constructor to set the full name of the key using one of the
81 standard keys, that is, HKCR, HKCU, HKLM, HKUSR, HKPD, HKCC or HKDD.
82 */
83 wxRegKey(StdKey keyParent, const wxString& strKey);
84 /**
85 The constructor to set the full name of the key under a previously created
86 parent.
87 */
88 wxRegKey(const wxRegKey& keyParent, const wxString& strKey);
89
90 /**
91 Access modes for wxRegKey.
92 */
93 enum AccessMode
94 {
95 Read, ///< Read-only
96 Write ///< Read and Write
97 };
98
99 /**
100 The standard registry key enumerator.
101 */
102 enum StdKey
103 {
104 HKCR, ///< HKEY_CLASSES_ROOT
105 HKCU, ///< HKEY_CURRENT_USER
106 HKLM, ///< HKEY_LOCAL_MACHINE
107 HKUSR, ///< HKEY_USERS
108 HKPD, ///< HKEY_PERFORMANCE_DATA (Windows NT and 2K only)
109 HKCC, ///< HKEY_CURRENT_CONFIG
110 HKDD, ///< HKEY_DYN_DATA (Windows 95 and 98 only)
111 HKMAX
112 };
113
114 /**
115 The value type enumerator.
116 */
117 enum ValueType
118 {
119 Type_None, ///< No value type
120 Type_String, ///< Unicode null-terminated string
121 Type_Expand_String, ///< Unicode null-terminated string
122 ///< (with environment variable references)
123 Type_Binary, ///< Free form binary
124 Type_Dword, ///< 32-bit number
125 Type_Dword_little_endian, ///< 32-bit number (same as Type_Dword)
126 Type_Dword_big_endian, ///< 32-bit number
127 Type_Link, ///< Symbolic Link (Unicode)
128 Type_Multi_String, ///< Multiple Unicode strings
129 Type_Resource_list, ///< Resource list in the resource map
130 Type_Full_resource_descriptor, ///< Resource list in the hardware description
131 Type_Resource_requirements_list ///<
132 };
133
134 /**
135 Closes the key.
136 */
137 void Close();
138
139 /**
140 Copy the entire contents of the key recursively to another location
141 using the name.
142 */
143 bool Copy(const wxString& szNewName);
144 /**
145 Copy the entire contents of the key recursively to another location
146 using the key.
147 */
148 bool Copy(wxRegKey& keyDst);
149
150 /**
151 Copy the value to another key, possibly changing its name. By default
152 it will remain the same.
153 */
154 bool CopyValue(const wxString& szValue, wxRegKey& keyDst,
155 const wxString& szNewName = wxEmptyString);
156 /**
157 Creates the key. Will fail if the key already exists and @a bOkIfExists is
158 @false.
159 */
160 bool Create(bool bOkIfExists = true);
161
162 /**
163 Deletes the subkey with all of its subkeys/values recursively.
164 */
165 void DeleteKey(const wxString& szKey);
166
167 /**
168 Deletes this key and all of its subkeys and values recursively.
169 */
170 void DeleteSelf();
171
172 /**
173 Deletes the named value.
174 */
175 void DeleteValue(const wxString& szKey);
176
177 /**
178 Returns @true if the key exists.
179 */
180 bool Exists() const;
181
182 /**
183 Write the contents of this key and all its subkeys to the given file.
184 (The file will not be overwritten; it's an error if it already exists.)
185 Note that we export the key in REGEDIT4 format, not RegSaveKey() binary
186 format nor the newer REGEDIT5.
187 */
188 bool Export(const wxString& filename) const;
189 /**
190 Write the contents of this key and all its subkeys to the opened stream.
191 */
192 bool Export(wxOutputStream& ostr) const;
193
194 /**
195 Gets the first key.
196 */
197 bool GetFirstKey(wxString& strKeyName, long& lIndex);
198
199 /**
200 Gets the first value of this key.
201 */
202 bool GetFirstValue(wxString& strValueName, long& lIndex);
203
204 /**
205 Gets information about the key.
206
207 @param pnSubKeys
208 The number of subkeys.
209 @param pnMaxKeyLen
210 The maximum length of the subkey name.
211 @param pnValues
212 The number of values.
213 @param pnMaxValueLen
214 The maximum length of a value.
215 */
216 bool GetKeyInfo(size_t* pnSubKeys, size_t* pnMaxKeyLen,
217 size_t* pnValues, size_t* pnMaxValueLen) const;
218
219 /**
220 Gets the name of the registry key.
221 */
222 wxString GetName(bool bShortPrefix = true) const;
223
224 /**
225 Gets the next key.
226 */
227 bool GetNextKey(wxString& strKeyName, long& lIndex) const;
228
229 /**
230 Gets the next key value for this key.
231 */
232 bool GetNextValue(wxString& strValueName, long& lIndex) const;
233
234 /**
235 Gets the value type.
236 */
237 ValueType GetValueType(const wxString& szValue) const;
238
239 /**
240 Returns @true if given subkey exists.
241 */
242 bool HasSubKey(const wxString& szKey) const;
243
244 /**
245 Returns @true if any subkeys exist.
246 */
247 bool HasSubKeys() const;
248
249 /**
250 Returns @true if the value exists.
251 */
252 bool HasValue(const wxString& szValue) const;
253
254 /**
255 Returns @true if any values exist.
256 */
257 bool HasValues() const;
258
259 /**
260 Returns @true if this key is empty, nothing under this key.
261 */
262 bool IsEmpty() const;
263
264 /**
265 Returns true if the value contains a number.
266 */
267 bool IsNumericValue(const wxString& szValue) const;
268
269 /**
270 Returns @true if the key is opened.
271 */
272 bool IsOpened() const;
273
274 /**
275 Explicitly opens the key. This method also allows the key to be opened in
276 read-only mode by passing wxRegKey::Read instead of default
277 wxRegKey::Write parameter.
278 */
279 bool Open(AccessMode mode = Write);
280
281 /**
282 Return the default value of the key.
283 */
284 wxString QueryDefaultValue() const;
285
286 /**
287 Retrieves the raw string value.
288 */
289 bool QueryRawValue(const wxString& szValue, wxString& strValue) const;
290
291 /**
292 Retrieves the raw or expanded string value.
293 */
294 bool QueryValue(const wxString& szValue, wxString& strValue, bool raw) const;
295
296 /**
297 Retrieves the numeric value.
298 */
299 bool QueryValue(const wxString& szValue, long* plValue) const;
300
301 /**
302 Retrieves the binary structure.
303 */
304 bool QueryValue(const wxString& szValue, wxMemoryBuffer& buf) const;
305
306 /**
307 Renames the key.
308 */
309 bool Rename(const wxString& szNewName);
310
311 /**
312 Renames a value.
313 */
314 bool RenameValue(const wxString& szValueOld,
315 const wxString& szValueNew);
316
317 /**
318 Preallocate some memory for the name. For wxRegConfig usage only.
319 */
320 void ReserveMemoryForName(size_t bytes);
321
322 /**
323 Set or change the HKEY handle.
324 */
325 void SetHkey(WXHKEY hKey);
326
327 /**
328 Set the full key name. The name is absolute. It should start with
329 HKEY_xxx.
330 */
331 void SetName(const wxString& strKey);
332 /**
333 Set the name relative to the parent key
334 */
335 void SetName(StdKey keyParent, const wxString& strKey);
336 /**
337 Set the name relative to the parent key
338 */
339 void SetName(const wxRegKey& keyParent, const wxString& strKey);
340
341 /**
342 Sets the given @a szValue which must be numeric.
343 If the value doesn't exist, it is created.
344 */
345 bool SetValue(const wxString& szValue, long lValue);
346 /**
347 Sets the given @a szValue which must be string.
348 If the value doesn't exist, it is created.
349 */
350 bool SetValue(const wxString& szValue, const wxString& strValue);
351 /**
352 Sets the given @a szValue which must be binary.
353 If the value doesn't exist, it is created.
354 */
355 bool SetValue(const wxString& szValue, const wxMemoryBuffer& buf);
356 };