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 // mutable hack (see also registry.cpp)
21 // ----------------------------------------------------------------------------
23 #define MUTABLE mutable
28 // ----------------------------------------------------------------------------
29 // types used in this module
30 // ----------------------------------------------------------------------------
35 #define HKEY unsigned long
39 typedef unsigned long ulong
;
41 // ----------------------------------------------------------------------------
42 // class wxRegKey encapsulates window HKEY handle
43 // ----------------------------------------------------------------------------
44 class WXDLLEXPORT wxRegKey
47 // NB: do _not_ change the values of elements in these enumerations!
49 // registry value types (with comments from winnt.h)
52 Type_None
, // No value type
53 Type_String
, // Unicode nul terminated string
55 Type_Expand_String
, // Unicode nul terminated string
56 // (with environment variable references)
57 Type_Binary
, // Free form binary
58 Type_Dword
, // 32-bit number
59 Type_Dword_little_endian
// 32-bit number
60 = Type_Dword
, // (same as Type_DWORD)
61 Type_Dword_big_endian
, // 32-bit number
62 Type_Link
, // Symbolic Link (unicode)
63 Type_Multi_String
, // Multiple Unicode strings
64 Type_Resource_list
, // Resource list in the resource map
65 Type_Full_resource_descriptor
, // Resource list in the hardware description
66 Type_Resource_requirements_list
// ???
70 // predefined registry keys
77 HKLM
, // local machine
79 HKPD
// performance data (WinNT/2K only)
82 HKCC
, // current config (starting from Win95/NT 4.0)
83 HKDD
// dynamic data (Win95/98 only)
88 // information about standard (predefined) registry keys
89 // number of standard keys
90 static const size_t nStdKeys
;
91 // get the name of a standard key
92 static const wxChar
*GetStdKeyName(size_t key
);
93 // get the short name of a standard key
94 static const wxChar
*GetStdKeyShortName(size_t key
);
95 // get StdKey from root HKEY
96 static StdKey
GetStdKeyFromHkey(WXHKEY hkey
);
98 // extacts the std key prefix from the string (return value) and
99 // leaves only the part after it (i.e. modifies the string passed!)
100 static StdKey
ExtractKeyName(wxString
& str
);
103 // root key is set to HKCR (the only root key under Win16)
105 // strKey is the full name of the key (i.e. starting with HKEY_xxx...)
106 wxRegKey(const wxString
& strKey
);
107 // strKey is the name of key under (standard key) keyParent
108 wxRegKey(StdKey keyParent
, const wxString
& strKey
);
109 // strKey is the name of key under (previously created) keyParent
110 wxRegKey(const wxRegKey
& keyParent
, const wxString
& strKey
);
114 // change key (closes the previously opened key if any)
115 // the name is absolute, i.e. should start with HKEY_xxx
116 void SetName(const wxString
& strKey
);
117 // the name is relative to the parent key
118 void SetName(StdKey keyParent
, const wxString
& strKey
);
119 // the name is relative to the parent key
120 void SetName(const wxRegKey
& keyParent
, const wxString
& strKey
);
121 // hKey should be opened and will be closed in wxRegKey dtor
122 void SetHkey(WXHKEY hKey
);
124 // get infomation about the key
125 // get the (full) key name. Abbreviate std root keys if bShortPrefix.
126 wxString
GetName(bool bShortPrefix
= TRUE
) const;
127 // return true if the key exists
129 // get the info about key (any number of these pointers may be NULL)
130 bool GetKeyInfo(size_t *pnSubKeys
, // number of subkeys
131 size_t *pnMaxKeyLen
, // max len of subkey name
132 size_t *pnValues
, // number of values
133 size_t *pnMaxValueLen
) const;
134 // return true if the key is opened
135 bool IsOpened() const { return m_hKey
!= 0; }
136 // for "if ( !key ) wxLogError(...)" kind of expressions
137 operator bool() const { return m_dwLastError
== 0; }
139 // operations on the key itself
140 // explicitly open the key (will be automatically done by all functions
141 // which need the key to be opened if the key is not opened yet)
143 // create the key: will fail if the key already exists and !bOkIfExists
144 bool Create(bool bOkIfExists
= TRUE
);
145 // rename a value from old name to new one
146 bool RenameValue(const wxChar
*szValueOld
, const wxChar
*szValueNew
);
148 bool Rename(const wxChar
*szNewName
);
149 // copy value to another key possibly changing its name (by default it will
151 bool CopyValue(const wxChar
*szValue
, wxRegKey
& keyDst
,
152 const wxChar
*szNewName
= NULL
);
153 // copy the entire contents of the key recursively to another location
154 bool Copy(const wxChar
*szNewName
);
155 // same as Copy() but using a key and not the name
156 bool Copy(wxRegKey
& keyDst
);
157 // close the key (will be automatically done in dtor)
160 // deleting keys/values
161 // deletes this key and all of it's subkeys/values
163 // deletes the subkey with all of it's subkeys/values recursively
164 bool DeleteKey(const wxChar
*szKey
);
165 // deletes the named value (may be NULL to remove the default value)
166 bool DeleteValue(const wxChar
*szValue
);
168 // access to values and subkeys
170 ValueType
GetValueType(const wxChar
*szValue
) const;
171 // returns TRUE if the value contains a number (else it's some string)
172 bool IsNumericValue(const wxChar
*szValue
) const;
174 // assignment operators set the default value of the key
175 wxRegKey
& operator=(const wxString
& strValue
)
176 { SetValue(NULL
, strValue
); return *this; }
177 wxRegKey
& operator=(long lValue
)
178 { SetValue(NULL
, lValue
); return *this; }
180 // conversion operators query the default value of the key
181 operator wxString() const;
183 // set the string value
184 bool SetValue(const wxChar
*szValue
, const wxString
& strValue
);
185 // retrieve the string value
186 bool QueryValue(const wxChar
*szValue
, wxString
& strValue
) const
187 { return QueryValue(szValue
, strValue
, FALSE
); }
188 // retrieve raw string value
189 bool QueryRawValue(const wxChar
*szValue
, wxString
& strValue
) const
190 { return QueryValue(szValue
, strValue
, TRUE
); }
191 // retrieve either raw or expanded string value
192 bool QueryValue(const wxChar
*szValue
, wxString
& strValue
, bool raw
) const;
195 // set the numeric value
196 bool SetValue(const wxChar
*szValue
, long lValue
);
197 // return the numeric value
198 bool QueryValue(const wxChar
*szValue
, long *plValue
) const;
201 // query existence of a key/value
202 // return true if value exists
203 bool HasValue(const wxChar
*szKey
) const;
204 // return true if given subkey exists
205 bool HasSubKey(const wxChar
*szKey
) const;
206 // return true if any subkeys exist
207 bool HasSubkeys() const;
208 // return true if any values exist
209 bool HasValues() const;
210 // return true if the key is empty (nothing under this key)
211 bool IsEmpty() const { return !HasSubkeys() && !HasValues(); }
213 // enumerate values and subkeys
214 bool GetFirstValue(wxString
& strValueName
, long& lIndex
);
215 bool GetNextValue (wxString
& strValueName
, long& lIndex
) const;
217 bool GetFirstKey (wxString
& strKeyName
, long& lIndex
);
218 bool GetNextKey (wxString
& strKeyName
, long& lIndex
) const;
221 // no copy ctor/assignment operator
222 wxRegKey(const wxRegKey
& key
); // not implemented
223 wxRegKey
& operator=(const wxRegKey
& key
); // not implemented
225 WXHKEY m_hKey
, // our handle
226 m_hRootKey
; // handle of the top key (i.e. StdKey)
227 wxString m_strKey
; // key name (relative to m_hRootKey)
229 MUTABLE
long m_dwLastError
; // last error (0 if none)