]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/registry.h
Some of these are not in BASE, cahnge back to WXDLLEXPORT
[wxWidgets.git] / include / wx / msw / registry.h
CommitLineData
2bda0e17
KB
1///////////////////////////////////////////////////////////////////////////////
2// Name: msw/registry.h
3// Purpose: Registry classes and functions
4// Author: Vadim Zeitlin
23f681ec 5// Modified by:
2bda0e17
KB
6// Created: 03.04.198
7// RCS-ID: $Id$
8// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
65571936 9// Licence: wxWindows licence
2bda0e17
KB
10///////////////////////////////////////////////////////////////////////////////
11
12#ifndef _REGISTRY_H
13#define _REGISTRY_H
14
12028905 15#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
0d3820b3
JS
16#pragma interface "registry.h"
17#endif
18
2bda0e17 19// ----------------------------------------------------------------------------
8f494e5d 20// types used in this module
2bda0e17 21// ----------------------------------------------------------------------------
0d8d91a9
JS
22
23/*
2bda0e17
KB
24#ifndef HKEY_DEFINED
25 #define HKEY_DEFINED
26 #define HKEY unsigned long
27#endif
0d8d91a9 28*/
2bda0e17 29
8f494e5d
VZ
30typedef unsigned long ulong;
31
2bda0e17
KB
32// ----------------------------------------------------------------------------
33// class wxRegKey encapsulates window HKEY handle
34// ----------------------------------------------------------------------------
1fa9e5bc 35class WXDLLIMPEXP_BASE wxRegKey
2bda0e17
KB
36{
37public:
38 // NB: do _not_ change the values of elements in these enumerations!
39
40 // registry value types (with comments from winnt.h)
41 enum ValueType
42 {
43 Type_None, // No value type
44 Type_String, // Unicode nul terminated string
45#ifdef __WIN32__
46 Type_Expand_String, // Unicode nul terminated string
47 // (with environment variable references)
48 Type_Binary, // Free form binary
49 Type_Dword, // 32-bit number
23f681ec
VZ
50 Type_Dword_little_endian // 32-bit number
51 = Type_Dword, // (same as Type_DWORD)
2bda0e17
KB
52 Type_Dword_big_endian, // 32-bit number
53 Type_Link, // Symbolic Link (unicode)
54 Type_Multi_String, // Multiple Unicode strings
55 Type_Resource_list, // Resource list in the resource map
56 Type_Full_resource_descriptor, // Resource list in the hardware description
a3ef5bf5 57 Type_Resource_requirements_list // ???
2bda0e17
KB
58#endif //WIN32
59 };
60
61 // predefined registry keys
62 enum StdKey
63 {
23f681ec 64 HKCR // classes root
2bda0e17 65#ifdef __WIN32__
23f681ec
VZ
66 ,
67 HKCU, // current user
68 HKLM, // local machine
69 HKUSR, // users
70 HKPD // performance data (WinNT/2K only)
71#if WINVER >= 0x0400
72 ,
73 HKCC, // current config (starting from Win95/NT 4.0)
74 HKDD // dynamic data (Win95/98 only)
2bda0e17
KB
75#endif // Winver
76#endif // Win32/16
77 };
78
bee96abf
VZ
79 // access mode for the key
80 enum AccessMode
81 {
82 Read, // read-only
83 Write // read and write
84 };
85
2bda0e17
KB
86 // information about standard (predefined) registry keys
87 // number of standard keys
88 static const size_t nStdKeys;
89 // get the name of a standard key
4de6207a 90 static const wxChar *GetStdKeyName(size_t key);
2bda0e17 91 // get the short name of a standard key
4de6207a 92 static const wxChar *GetStdKeyShortName(size_t key);
2bda0e17 93 // get StdKey from root HKEY
0d8d91a9 94 static StdKey GetStdKeyFromHkey(WXHKEY hkey);
2bda0e17
KB
95
96 // extacts the std key prefix from the string (return value) and
97 // leaves only the part after it (i.e. modifies the string passed!)
98 static StdKey ExtractKeyName(wxString& str);
99
100 // ctors
101 // root key is set to HKCR (the only root key under Win16)
102 wxRegKey();
103 // strKey is the full name of the key (i.e. starting with HKEY_xxx...)
104 wxRegKey(const wxString& strKey);
105 // strKey is the name of key under (standard key) keyParent
2dc77646 106 wxRegKey(StdKey keyParent, const wxString& strKey);
2bda0e17
KB
107 // strKey is the name of key under (previously created) keyParent
108 wxRegKey(const wxRegKey& keyParent, const wxString& strKey);
bee96abf 109 // dtor closes the key
2bda0e17
KB
110 ~wxRegKey();
111
112 // change key (closes the previously opened key if any)
2dc77646 113 // the name is absolute, i.e. should start with HKEY_xxx
2bda0e17 114 void SetName(const wxString& strKey);
2dc77646
VZ
115 // the name is relative to the parent key
116 void SetName(StdKey keyParent, const wxString& strKey);
117 // the name is relative to the parent key
118 void SetName(const wxRegKey& keyParent, const wxString& strKey);
119 // hKey should be opened and will be closed in wxRegKey dtor
0d8d91a9 120 void SetHkey(WXHKEY hKey);
2bda0e17
KB
121
122 // get infomation about the key
123 // get the (full) key name. Abbreviate std root keys if bShortPrefix.
cf447356 124 wxString GetName(bool bShortPrefix = TRUE) const;
2dc77646 125 // return true if the key exists
8f494e5d
VZ
126 bool Exists() const;
127 // get the info about key (any number of these pointers may be NULL)
3cda6353
VZ
128 bool GetKeyInfo(size_t *pnSubKeys, // number of subkeys
129 size_t *pnMaxKeyLen, // max len of subkey name
130 size_t *pnValues, // number of values
131 size_t *pnMaxValueLen) const;
2dc77646 132 // return true if the key is opened
8f494e5d 133 bool IsOpened() const { return m_hKey != 0; }
2bda0e17
KB
134 // for "if ( !key ) wxLogError(...)" kind of expressions
135 operator bool() const { return m_dwLastError == 0; }
136
137 // operations on the key itself
138 // explicitly open the key (will be automatically done by all functions
139 // which need the key to be opened if the key is not opened yet)
bee96abf 140 bool Open(AccessMode mode = Write);
23f681ec 141 // create the key: will fail if the key already exists and !bOkIfExists
cf447356 142 bool Create(bool bOkIfExists = TRUE);
23f681ec
VZ
143 // rename a value from old name to new one
144 bool RenameValue(const wxChar *szValueOld, const wxChar *szValueNew);
225fe9d6
VZ
145 // rename the key
146 bool Rename(const wxChar *szNewName);
23f681ec
VZ
147 // copy value to another key possibly changing its name (by default it will
148 // remain the same)
149 bool CopyValue(const wxChar *szValue, wxRegKey& keyDst,
150 const wxChar *szNewName = NULL);
151 // copy the entire contents of the key recursively to another location
225fe9d6 152 bool Copy(const wxChar *szNewName);
23f681ec
VZ
153 // same as Copy() but using a key and not the name
154 bool Copy(wxRegKey& keyDst);
2bda0e17
KB
155 // close the key (will be automatically done in dtor)
156 bool Close();
157
158 // deleting keys/values
159 // deletes this key and all of it's subkeys/values
160 bool DeleteSelf();
161 // deletes the subkey with all of it's subkeys/values recursively
4de6207a 162 bool DeleteKey(const wxChar *szKey);
2bda0e17 163 // deletes the named value (may be NULL to remove the default value)
4de6207a 164 bool DeleteValue(const wxChar *szValue);
2bda0e17
KB
165
166 // access to values and subkeys
167 // get value type
4de6207a 168 ValueType GetValueType(const wxChar *szValue) const;
90186e52 169 // returns TRUE if the value contains a number (else it's some string)
4de6207a 170 bool IsNumericValue(const wxChar *szValue) const;
2bda0e17
KB
171
172 // assignment operators set the default value of the key
173 wxRegKey& operator=(const wxString& strValue)
174 { SetValue(NULL, strValue); return *this; }
175 wxRegKey& operator=(long lValue)
176 { SetValue(NULL, lValue); return *this; }
177
50e42404
VZ
178 // query the default value of the key: implicitly or explicitly
179 wxString QueryDefaultValue() const;
180 operator wxString() const { return QueryDefaultValue(); }
181
182 // named values
2bda0e17
KB
183
184 // set the string value
4de6207a 185 bool SetValue(const wxChar *szValue, const wxString& strValue);
6dfec4b8
VZ
186 // retrieve the string value
187 bool QueryValue(const wxChar *szValue, wxString& strValue) const
188 { return QueryValue(szValue, strValue, FALSE); }
189 // retrieve raw string value
190 bool QueryRawValue(const wxChar *szValue, wxString& strValue) const
191 { return QueryValue(szValue, strValue, TRUE); }
192 // retrieve either raw or expanded string value
193 bool QueryValue(const wxChar *szValue, wxString& strValue, bool raw) const;
2bda0e17
KB
194
195#ifdef __WIN32__
196 // set the numeric value
4de6207a 197 bool SetValue(const wxChar *szValue, long lValue);
2bda0e17 198 // return the numeric value
4de6207a 199 bool QueryValue(const wxChar *szValue, long *plValue) const;
9b386eca
RG
200 // set the binary value
201 bool SetValue(const wxChar *szValue, const wxMemoryBuffer& buf);
202 // return the binary value
203 bool QueryValue(const wxChar *szValue, wxMemoryBuffer& buf) const;
2bda0e17
KB
204#endif //Win32
205
2dc77646
VZ
206 // query existence of a key/value
207 // return true if value exists
92049cd4 208 bool HasValue(const wxChar *szKey) const;
2dc77646 209 // return true if given subkey exists
92049cd4 210 bool HasSubKey(const wxChar *szKey) const;
2dc77646 211 // return true if any subkeys exist
92049cd4
VZ
212 bool HasSubkeys() const;
213 // return true if any values exist
214 bool HasValues() const;
215 // return true if the key is empty (nothing under this key)
216 bool IsEmpty() const { return !HasSubkeys() && !HasValues(); }
2bda0e17
KB
217
218 // enumerate values and subkeys
2bda0e17
KB
219 bool GetFirstValue(wxString& strValueName, long& lIndex);
220 bool GetNextValue (wxString& strValueName, long& lIndex) const;
2bda0e17
KB
221
222 bool GetFirstKey (wxString& strKeyName , long& lIndex);
223 bool GetNextKey (wxString& strKeyName , long& lIndex) const;
224
807a903e
VZ
225 // for wxRegConfig usage only: preallocate some memory for the name
226 void ReserveMemoryForName(size_t bytes) { m_strKey.reserve(bytes); }
227
2bda0e17 228private:
807a903e
VZ
229 // common part of all ctors
230 void Init()
231 {
232 m_hKey = (WXHKEY) NULL;
233 m_dwLastError = 0;
234 }
235
2bda0e17
KB
236 // no copy ctor/assignment operator
237 wxRegKey(const wxRegKey& key); // not implemented
238 wxRegKey& operator=(const wxRegKey& key); // not implemented
239
c085e333 240 WXHKEY m_hKey, // our handle
2bda0e17
KB
241 m_hRootKey; // handle of the top key (i.e. StdKey)
242 wxString m_strKey; // key name (relative to m_hRootKey)
243
807a903e 244 long m_dwLastError; // last error (0 if none)
2bda0e17
KB
245};
246
247#endif //_REGISTRY_H
2dc77646 248