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 (same as Type_DWORD)
60 Type_Dword_big_endian
, // 32-bit number
61 Type_Link
, // Symbolic Link (unicode)
62 Type_Multi_String
, // Multiple Unicode strings
63 Type_Resource_list
, // Resource list in the resource map
64 Type_Full_resource_descriptor
, // Resource list in the hardware description
65 Type_Resource_requirements_list
// ???
69 // predefined registry keys
74 , HKCU
, // current user
75 HKLM
, // local machine
77 HKPD
// performance data (@@ NT only?)
79 , HKCC
, // current config
85 // information about standard (predefined) registry keys
86 // number of standard keys
87 static const size_t nStdKeys
;
88 // get the name of a standard key
89 static const wxChar
*GetStdKeyName(size_t key
);
90 // get the short name of a standard key
91 static const wxChar
*GetStdKeyShortName(size_t key
);
92 // get StdKey from root HKEY
93 static StdKey
GetStdKeyFromHkey(WXHKEY hkey
);
95 // extacts the std key prefix from the string (return value) and
96 // leaves only the part after it (i.e. modifies the string passed!)
97 static StdKey
ExtractKeyName(wxString
& str
);
100 // root key is set to HKCR (the only root key under Win16)
102 // strKey is the full name of the key (i.e. starting with HKEY_xxx...)
103 wxRegKey(const wxString
& strKey
);
104 // strKey is the name of key under (standard key) keyParent
105 wxRegKey(StdKey keyParent
, const wxString
& strKey
);
106 // strKey is the name of key under (previously created) keyParent
107 wxRegKey(const wxRegKey
& keyParent
, const wxString
& strKey
);
111 // change key (closes the previously opened key if any)
112 // the name is absolute, i.e. should start with HKEY_xxx
113 void SetName(const wxString
& strKey
);
114 // the name is relative to the parent key
115 void SetName(StdKey keyParent
, const wxString
& strKey
);
116 // the name is relative to the parent key
117 void SetName(const wxRegKey
& keyParent
, const wxString
& strKey
);
118 // hKey should be opened and will be closed in wxRegKey dtor
119 void SetHkey(WXHKEY hKey
);
121 // get infomation about the key
122 // get the (full) key name. Abbreviate std root keys if bShortPrefix.
123 wxString
GetName(bool bShortPrefix
= TRUE
) const;
124 // return true if the key exists
126 // get the info about key (any number of these pointers may be NULL)
128 #if defined( __GNUWIN32__) && !defined(wxUSE_NORLANDER_HEADERS)
129 bool GetKeyInfo(size_t *pnSubKeys
, // number of subkeys
130 size_t *pnMaxKeyLen
, // max len of subkey name
131 size_t *pnValues
, // number of values
132 size_t *pnMaxValueLen
) const;
134 bool GetKeyInfo(ulong
*pnSubKeys
, // number of subkeys
135 ulong
*pnMaxKeyLen
, // max len of subkey name
136 ulong
*pnValues
, // number of values
137 ulong
*pnMaxValueLen
) const;
139 // return true if the key is opened
140 bool IsOpened() const { return m_hKey
!= 0; }
141 // for "if ( !key ) wxLogError(...)" kind of expressions
142 operator bool() const { return m_dwLastError
== 0; }
144 // operations on the key itself
145 // explicitly open the key (will be automatically done by all functions
146 // which need the key to be opened if the key is not opened yet)
148 // create the key: will fail if the key already exists and bOkIfExists
149 bool Create(bool bOkIfExists
= TRUE
);
150 // close the key (will be automatically done in dtor)
153 // deleting keys/values
154 // deletes this key and all of it's subkeys/values
156 // deletes the subkey with all of it's subkeys/values recursively
157 bool DeleteKey(const wxChar
*szKey
);
158 // deletes the named value (may be NULL to remove the default value)
159 bool DeleteValue(const wxChar
*szValue
);
161 // access to values and subkeys
163 ValueType
GetValueType(const wxChar
*szValue
) const;
164 // returns TRUE if the value contains a number (else it's some string)
165 bool IsNumericValue(const wxChar
*szValue
) const;
167 // assignment operators set the default value of the key
168 wxRegKey
& operator=(const wxString
& strValue
)
169 { SetValue(NULL
, strValue
); return *this; }
170 wxRegKey
& operator=(long lValue
)
171 { SetValue(NULL
, lValue
); return *this; }
173 // conversion operators query the default value of the key
174 operator wxString() const;
176 // set the string value
177 bool SetValue(const wxChar
*szValue
, const wxString
& strValue
);
178 // return the string value
179 bool QueryValue(const wxChar
*szValue
, wxString
& strValue
) const;
182 // set the numeric value
183 bool SetValue(const wxChar
*szValue
, long lValue
);
184 // return the numeric value
185 bool QueryValue(const wxChar
*szValue
, long *plValue
) const;
188 // query existence of a key/value
189 // return true if value exists
190 bool HasValue(const wxChar
*szKey
) const;
191 // return true if given subkey exists
192 bool HasSubKey(const wxChar
*szKey
) const;
193 // return true if any subkeys exist
194 bool HasSubkeys() const;
195 // return true if any values exist
196 bool HasValues() const;
197 // return true if the key is empty (nothing under this key)
198 bool IsEmpty() const { return !HasSubkeys() && !HasValues(); }
200 // enumerate values and subkeys
201 bool GetFirstValue(wxString
& strValueName
, long& lIndex
);
202 bool GetNextValue (wxString
& strValueName
, long& lIndex
) const;
204 bool GetFirstKey (wxString
& strKeyName
, long& lIndex
);
205 bool GetNextKey (wxString
& strKeyName
, long& lIndex
) const;
208 // no copy ctor/assignment operator
209 wxRegKey(const wxRegKey
& key
); // not implemented
210 wxRegKey
& operator=(const wxRegKey
& key
); // not implemented
212 WXHKEY m_hKey
, // our handle
213 m_hRootKey
; // handle of the top key (i.e. StdKey)
214 wxString m_strKey
; // key name (relative to m_hRootKey)
216 MUTABLE
long m_dwLastError
; // last error (0 if none)