1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: msw/registry.h
3 // Purpose: Registry classes and functions
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
16 #pragma interface "registry.h"
19 // ----------------------------------------------------------------------------
20 // types used in this module
21 // ----------------------------------------------------------------------------
26 #define HKEY unsigned long
30 typedef unsigned long ulong
;
32 // ----------------------------------------------------------------------------
33 // class wxRegKey encapsulates window HKEY handle
34 // ----------------------------------------------------------------------------
35 class WXDLLEXPORT wxRegKey
38 // NB: do _not_ change the values of elements in these enumerations!
40 // registry value types (with comments from winnt.h)
43 Type_None
, // No value type
44 Type_String
, // Unicode nul terminated string
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
50 Type_Dword_little_endian
// 32-bit number
51 = Type_Dword
, // (same as Type_DWORD)
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
57 Type_Resource_requirements_list
// ???
61 // predefined registry keys
68 HKLM
, // local machine
70 HKPD
// performance data (WinNT/2K only)
73 HKCC
, // current config (starting from Win95/NT 4.0)
74 HKDD
// dynamic data (Win95/98 only)
79 // information about standard (predefined) registry keys
80 // number of standard keys
81 static const size_t nStdKeys
;
82 // get the name of a standard key
83 static const wxChar
*GetStdKeyName(size_t key
);
84 // get the short name of a standard key
85 static const wxChar
*GetStdKeyShortName(size_t key
);
86 // get StdKey from root HKEY
87 static StdKey
GetStdKeyFromHkey(WXHKEY hkey
);
89 // extacts the std key prefix from the string (return value) and
90 // leaves only the part after it (i.e. modifies the string passed!)
91 static StdKey
ExtractKeyName(wxString
& str
);
94 // root key is set to HKCR (the only root key under Win16)
96 // strKey is the full name of the key (i.e. starting with HKEY_xxx...)
97 wxRegKey(const wxString
& strKey
);
98 // strKey is the name of key under (standard key) keyParent
99 wxRegKey(StdKey keyParent
, const wxString
& strKey
);
100 // strKey is the name of key under (previously created) keyParent
101 wxRegKey(const wxRegKey
& keyParent
, const wxString
& strKey
);
105 // change key (closes the previously opened key if any)
106 // the name is absolute, i.e. should start with HKEY_xxx
107 void SetName(const wxString
& strKey
);
108 // the name is relative to the parent key
109 void SetName(StdKey keyParent
, const wxString
& strKey
);
110 // the name is relative to the parent key
111 void SetName(const wxRegKey
& keyParent
, const wxString
& strKey
);
112 // hKey should be opened and will be closed in wxRegKey dtor
113 void SetHkey(WXHKEY hKey
);
115 // get infomation about the key
116 // get the (full) key name. Abbreviate std root keys if bShortPrefix.
117 wxString
GetName(bool bShortPrefix
= TRUE
) const;
118 // return true if the key exists
120 // get the info about key (any number of these pointers may be NULL)
121 bool GetKeyInfo(size_t *pnSubKeys
, // number of subkeys
122 size_t *pnMaxKeyLen
, // max len of subkey name
123 size_t *pnValues
, // number of values
124 size_t *pnMaxValueLen
) const;
125 // return true if the key is opened
126 bool IsOpened() const { return m_hKey
!= 0; }
127 // for "if ( !key ) wxLogError(...)" kind of expressions
128 operator bool() const { return m_dwLastError
== 0; }
130 // operations on the key itself
131 // explicitly open the key (will be automatically done by all functions
132 // which need the key to be opened if the key is not opened yet)
134 // create the key: will fail if the key already exists and !bOkIfExists
135 bool Create(bool bOkIfExists
= TRUE
);
136 // rename a value from old name to new one
137 bool RenameValue(const wxChar
*szValueOld
, const wxChar
*szValueNew
);
139 bool Rename(const wxChar
*szNewName
);
140 // copy value to another key possibly changing its name (by default it will
142 bool CopyValue(const wxChar
*szValue
, wxRegKey
& keyDst
,
143 const wxChar
*szNewName
= NULL
);
144 // copy the entire contents of the key recursively to another location
145 bool Copy(const wxChar
*szNewName
);
146 // same as Copy() but using a key and not the name
147 bool Copy(wxRegKey
& keyDst
);
148 // close the key (will be automatically done in dtor)
151 // deleting keys/values
152 // deletes this key and all of it's subkeys/values
154 // deletes the subkey with all of it's subkeys/values recursively
155 bool DeleteKey(const wxChar
*szKey
);
156 // deletes the named value (may be NULL to remove the default value)
157 bool DeleteValue(const wxChar
*szValue
);
159 // access to values and subkeys
161 ValueType
GetValueType(const wxChar
*szValue
) const;
162 // returns TRUE if the value contains a number (else it's some string)
163 bool IsNumericValue(const wxChar
*szValue
) const;
165 // assignment operators set the default value of the key
166 wxRegKey
& operator=(const wxString
& strValue
)
167 { SetValue(NULL
, strValue
); return *this; }
168 wxRegKey
& operator=(long lValue
)
169 { SetValue(NULL
, lValue
); return *this; }
171 // conversion operators query the default value of the key
172 operator wxString() const;
174 // set the string value
175 bool SetValue(const wxChar
*szValue
, const wxString
& strValue
);
176 // retrieve the string value
177 bool QueryValue(const wxChar
*szValue
, wxString
& strValue
) const
178 { return QueryValue(szValue
, strValue
, FALSE
); }
179 // retrieve raw string value
180 bool QueryRawValue(const wxChar
*szValue
, wxString
& strValue
) const
181 { return QueryValue(szValue
, strValue
, TRUE
); }
182 // retrieve either raw or expanded string value
183 bool QueryValue(const wxChar
*szValue
, wxString
& strValue
, bool raw
) const;
186 // set the numeric value
187 bool SetValue(const wxChar
*szValue
, long lValue
);
188 // return the numeric value
189 bool QueryValue(const wxChar
*szValue
, long *plValue
) const;
192 // query existence of a key/value
193 // return true if value exists
194 bool HasValue(const wxChar
*szKey
) const;
195 // return true if given subkey exists
196 bool HasSubKey(const wxChar
*szKey
) const;
197 // return true if any subkeys exist
198 bool HasSubkeys() const;
199 // return true if any values exist
200 bool HasValues() const;
201 // return true if the key is empty (nothing under this key)
202 bool IsEmpty() const { return !HasSubkeys() && !HasValues(); }
204 // enumerate values and subkeys
205 bool GetFirstValue(wxString
& strValueName
, long& lIndex
);
206 bool GetNextValue (wxString
& strValueName
, long& lIndex
) const;
208 bool GetFirstKey (wxString
& strKeyName
, long& lIndex
);
209 bool GetNextKey (wxString
& strKeyName
, long& lIndex
) const;
211 // for wxRegConfig usage only: preallocate some memory for the name
212 void ReserveMemoryForName(size_t bytes
) { m_strKey
.reserve(bytes
); }
215 // common part of all ctors
218 m_hKey
= (WXHKEY
) NULL
;
222 // no copy ctor/assignment operator
223 wxRegKey(const wxRegKey
& key
); // not implemented
224 wxRegKey
& operator=(const wxRegKey
& key
); // not implemented
226 WXHKEY m_hKey
, // our handle
227 m_hRootKey
; // handle of the top key (i.e. StdKey)
228 wxString m_strKey
; // key name (relative to m_hRootKey)
230 long m_dwLastError
; // last error (0 if none)