]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: msw/registry.h | |
3 | // Purpose: Registry classes and functions | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 03.04.198 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> | |
bbcdf8bc | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _REGISTRY_H | |
13 | #define _REGISTRY_H | |
14 | ||
0d3820b3 JS |
15 | #ifdef __GNUG__ |
16 | #pragma interface "registry.h" | |
17 | #endif | |
18 | ||
2bda0e17 KB |
19 | // ---------------------------------------------------------------------------- |
20 | // mutable hack (see also registry.cpp) | |
21 | // ---------------------------------------------------------------------------- | |
22 | #if USE_MUTABLE | |
23 | #define MUTABLE mutable | |
24 | #else | |
25 | #define MUTABLE | |
26 | #endif | |
27 | ||
28 | // ---------------------------------------------------------------------------- | |
8f494e5d | 29 | // types used in this module |
2bda0e17 KB |
30 | // ---------------------------------------------------------------------------- |
31 | #ifndef HKEY_DEFINED | |
32 | #define HKEY_DEFINED | |
33 | #define HKEY unsigned long | |
34 | #endif | |
35 | ||
8f494e5d VZ |
36 | typedef unsigned long ulong; |
37 | ||
2bda0e17 KB |
38 | // ---------------------------------------------------------------------------- |
39 | // class wxRegKey encapsulates window HKEY handle | |
40 | // ---------------------------------------------------------------------------- | |
41 | class WXDLLEXPORT wxRegKey | |
42 | { | |
43 | public: | |
44 | // NB: do _not_ change the values of elements in these enumerations! | |
45 | ||
46 | // registry value types (with comments from winnt.h) | |
47 | enum ValueType | |
48 | { | |
49 | Type_None, // No value type | |
50 | Type_String, // Unicode nul terminated string | |
51 | #ifdef __WIN32__ | |
52 | Type_Expand_String, // Unicode nul terminated string | |
53 | // (with environment variable references) | |
54 | Type_Binary, // Free form binary | |
55 | Type_Dword, // 32-bit number | |
56 | Type_Dword_little_endian, // 32-bit number (same as Type_DWORD) | |
57 | Type_Dword_big_endian, // 32-bit number | |
58 | Type_Link, // Symbolic Link (unicode) | |
59 | Type_Multi_String, // Multiple Unicode strings | |
60 | Type_Resource_list, // Resource list in the resource map | |
61 | Type_Full_resource_descriptor, // Resource list in the hardware description | |
62 | Type_Resource_requirements_list, // ??? | |
63 | #endif //WIN32 | |
64 | }; | |
65 | ||
66 | // predefined registry keys | |
67 | enum StdKey | |
68 | { | |
69 | HKCR, // classes root | |
70 | #ifdef __WIN32__ | |
71 | HKCU, // current user | |
72 | HKLM, // local machine | |
73 | HKUSR, // users | |
74 | HKPD, // performance data (@@ NT only?) | |
75 | #if WINVER >= 0x0400 | |
76 | HKCC, // current config | |
77 | HKDD, // dynamic data | |
78 | #endif // Winver | |
79 | #endif // Win32/16 | |
80 | }; | |
81 | ||
82 | // information about standard (predefined) registry keys | |
83 | // number of standard keys | |
84 | static const size_t nStdKeys; | |
85 | // get the name of a standard key | |
86 | static const char *GetStdKeyName(uint key); | |
87 | // get the short name of a standard key | |
88 | static const char *GetStdKeyShortName(uint key); | |
89 | // get StdKey from root HKEY | |
90 | static StdKey GetStdKeyFromHkey(HKEY hkey); | |
91 | ||
92 | // extacts the std key prefix from the string (return value) and | |
93 | // leaves only the part after it (i.e. modifies the string passed!) | |
94 | static StdKey ExtractKeyName(wxString& str); | |
95 | ||
96 | // ctors | |
97 | // root key is set to HKCR (the only root key under Win16) | |
98 | wxRegKey(); | |
99 | // strKey is the full name of the key (i.e. starting with HKEY_xxx...) | |
100 | wxRegKey(const wxString& strKey); | |
101 | // strKey is the name of key under (standard key) keyParent | |
2dc77646 | 102 | wxRegKey(StdKey keyParent, const wxString& strKey); |
2bda0e17 KB |
103 | // strKey is the name of key under (previously created) keyParent |
104 | wxRegKey(const wxRegKey& keyParent, const wxString& strKey); | |
105 | // | |
106 | ~wxRegKey(); | |
107 | ||
108 | // change key (closes the previously opened key if any) | |
2dc77646 | 109 | // the name is absolute, i.e. should start with HKEY_xxx |
2bda0e17 | 110 | void SetName(const wxString& strKey); |
2dc77646 VZ |
111 | // the name is relative to the parent key |
112 | void SetName(StdKey keyParent, const wxString& strKey); | |
113 | // the name is relative to the parent key | |
114 | void SetName(const wxRegKey& keyParent, const wxString& strKey); | |
115 | // hKey should be opened and will be closed in wxRegKey dtor | |
116 | void SetHkey(HKEY hKey); | |
2bda0e17 KB |
117 | |
118 | // get infomation about the key | |
119 | // get the (full) key name. Abbreviate std root keys if bShortPrefix. | |
cf447356 | 120 | wxString GetName(bool bShortPrefix = TRUE) const; |
2dc77646 | 121 | // return true if the key exists |
8f494e5d VZ |
122 | bool Exists() const; |
123 | // get the info about key (any number of these pointers may be NULL) | |
124 | bool GetKeyInfo(ulong *pnSubKeys, // number of subkeys | |
125 | ulong *pnMaxKeyLen, // max len of subkey name | |
126 | ulong *pnValues, // number of values | |
127 | ulong *pnMaxValueLen) const; | |
2dc77646 | 128 | // return true if the key is opened |
8f494e5d | 129 | bool IsOpened() const { return m_hKey != 0; } |
2bda0e17 KB |
130 | // for "if ( !key ) wxLogError(...)" kind of expressions |
131 | operator bool() const { return m_dwLastError == 0; } | |
132 | ||
133 | // operations on the key itself | |
134 | // explicitly open the key (will be automatically done by all functions | |
135 | // which need the key to be opened if the key is not opened yet) | |
136 | bool Open(); | |
137 | // create the key: will fail if the key already exists and bOkIfExists | |
cf447356 | 138 | bool Create(bool bOkIfExists = TRUE); |
2bda0e17 KB |
139 | // close the key (will be automatically done in dtor) |
140 | bool Close(); | |
141 | ||
142 | // deleting keys/values | |
143 | // deletes this key and all of it's subkeys/values | |
144 | bool DeleteSelf(); | |
145 | // deletes the subkey with all of it's subkeys/values recursively | |
146 | bool DeleteKey(const char *szKey); | |
147 | // deletes the named value (may be NULL to remove the default value) | |
148 | bool DeleteValue(const char *szValue); | |
149 | ||
150 | // access to values and subkeys | |
151 | // get value type | |
152 | ValueType GetValueType(const char *szValue); | |
153 | ||
154 | // assignment operators set the default value of the key | |
155 | wxRegKey& operator=(const wxString& strValue) | |
156 | { SetValue(NULL, strValue); return *this; } | |
157 | wxRegKey& operator=(long lValue) | |
158 | { SetValue(NULL, lValue); return *this; } | |
159 | ||
160 | // conversion operators query the default value of the key | |
161 | operator wxString() const; | |
162 | ||
163 | // set the string value | |
164 | bool SetValue(const char *szValue, const wxString& strValue); | |
165 | // return the string value | |
166 | bool QueryValue(const char *szValue, wxString& strValue) const; | |
167 | ||
168 | #ifdef __WIN32__ | |
169 | // set the numeric value | |
170 | bool SetValue(const char *szValue, long lValue); | |
171 | // return the numeric value | |
172 | bool QueryValue(const char *szValue, long *plValue) const; | |
173 | #endif //Win32 | |
174 | ||
2dc77646 VZ |
175 | // query existence of a key/value |
176 | // return true if value exists | |
177 | bool HasValue(const char *szKey) const; | |
178 | // return true if given subkey exists | |
2bda0e17 | 179 | bool HasSubKey(const char *szKey) const; |
2dc77646 | 180 | // return true if any subkeys exist |
2bda0e17 KB |
181 | bool HasSubkeys() const; |
182 | ||
183 | // enumerate values and subkeys | |
2bda0e17 KB |
184 | bool GetFirstValue(wxString& strValueName, long& lIndex); |
185 | bool GetNextValue (wxString& strValueName, long& lIndex) const; | |
2bda0e17 KB |
186 | |
187 | bool GetFirstKey (wxString& strKeyName , long& lIndex); | |
188 | bool GetNextKey (wxString& strKeyName , long& lIndex) const; | |
189 | ||
190 | private: | |
191 | // no copy ctor/assignment operator | |
192 | wxRegKey(const wxRegKey& key); // not implemented | |
193 | wxRegKey& operator=(const wxRegKey& key); // not implemented | |
194 | ||
195 | HKEY m_hKey, // our handle | |
196 | m_hRootKey; // handle of the top key (i.e. StdKey) | |
197 | wxString m_strKey; // key name (relative to m_hRootKey) | |
198 | ||
199 | MUTABLE long m_dwLastError; // last error (0 if none) | |
200 | }; | |
201 | ||
202 | #endif //_REGISTRY_H | |
2dc77646 | 203 |