]>
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> | |
9 | // Licence: wxWindows license | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _REGISTRY_H | |
13 | #define _REGISTRY_H | |
14 | ||
15 | // ---------------------------------------------------------------------------- | |
16 | // mutable hack (see also registry.cpp) | |
17 | // ---------------------------------------------------------------------------- | |
18 | #if USE_MUTABLE | |
19 | #define MUTABLE mutable | |
20 | #else | |
21 | #define MUTABLE | |
22 | #endif | |
23 | ||
24 | // ---------------------------------------------------------------------------- | |
25 | // forward decl for handle type | |
26 | // ---------------------------------------------------------------------------- | |
27 | #ifndef HKEY_DEFINED | |
28 | #define HKEY_DEFINED | |
29 | #define HKEY unsigned long | |
30 | #endif | |
31 | ||
32 | // ---------------------------------------------------------------------------- | |
33 | // class wxRegKey encapsulates window HKEY handle | |
34 | // ---------------------------------------------------------------------------- | |
35 | class WXDLLEXPORT wxRegKey | |
36 | { | |
37 | public: | |
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 | |
50 | Type_Dword_little_endian, // 32-bit number (same as Type_DWORD) | |
51 | Type_Dword_big_endian, // 32-bit number | |
52 | Type_Link, // Symbolic Link (unicode) | |
53 | Type_Multi_String, // Multiple Unicode strings | |
54 | Type_Resource_list, // Resource list in the resource map | |
55 | Type_Full_resource_descriptor, // Resource list in the hardware description | |
56 | Type_Resource_requirements_list, // ??? | |
57 | #endif //WIN32 | |
58 | }; | |
59 | ||
60 | // predefined registry keys | |
61 | enum StdKey | |
62 | { | |
63 | HKCR, // classes root | |
64 | #ifdef __WIN32__ | |
65 | HKCU, // current user | |
66 | HKLM, // local machine | |
67 | HKUSR, // users | |
68 | HKPD, // performance data (@@ NT only?) | |
69 | #if WINVER >= 0x0400 | |
70 | HKCC, // current config | |
71 | HKDD, // dynamic data | |
72 | #endif // Winver | |
73 | #endif // Win32/16 | |
74 | }; | |
75 | ||
76 | // information about standard (predefined) registry keys | |
77 | // number of standard keys | |
78 | static const size_t nStdKeys; | |
79 | // get the name of a standard key | |
80 | static const char *GetStdKeyName(uint key); | |
81 | // get the short name of a standard key | |
82 | static const char *GetStdKeyShortName(uint key); | |
83 | // get StdKey from root HKEY | |
84 | static StdKey GetStdKeyFromHkey(HKEY hkey); | |
85 | ||
86 | // extacts the std key prefix from the string (return value) and | |
87 | // leaves only the part after it (i.e. modifies the string passed!) | |
88 | static StdKey ExtractKeyName(wxString& str); | |
89 | ||
90 | // ctors | |
91 | // root key is set to HKCR (the only root key under Win16) | |
92 | wxRegKey(); | |
93 | // strKey is the full name of the key (i.e. starting with HKEY_xxx...) | |
94 | wxRegKey(const wxString& strKey); | |
95 | // strKey is the name of key under (standard key) keyParent | |
96 | wxRegKey(StdKey keyParent, const wxString& strKey); | |
97 | // strKey is the name of key under (previously created) keyParent | |
98 | wxRegKey(const wxRegKey& keyParent, const wxString& strKey); | |
99 | // | |
100 | ~wxRegKey(); | |
101 | ||
102 | // change key (closes the previously opened key if any) | |
103 | void SetName(const wxString& strKey); | |
104 | void SetHkey(HKEY hKey); | |
105 | ||
106 | // get infomation about the key | |
107 | // get the (full) key name. Abbreviate std root keys if bShortPrefix. | |
108 | wxString GetName(bool bShortPrefix = TRUE) const; | |
109 | // return TRUE if the key exists | |
110 | bool Exists() const; | |
111 | // return TRUE if the key is opened | |
112 | bool IsOpened() const { return m_hKey != 0; } | |
113 | // for "if ( !key ) wxLogError(...)" kind of expressions | |
114 | operator bool() const { return m_dwLastError == 0; } | |
115 | ||
116 | // operations on the key itself | |
117 | // explicitly open the key (will be automatically done by all functions | |
118 | // which need the key to be opened if the key is not opened yet) | |
119 | bool Open(); | |
120 | // create the key: will fail if the key already exists and bOkIfExists | |
121 | bool Create(bool bOkIfExists = TRUE); | |
122 | // close the key (will be automatically done in dtor) | |
123 | bool Close(); | |
124 | ||
125 | // deleting keys/values | |
126 | // deletes this key and all of it's subkeys/values | |
127 | bool DeleteSelf(); | |
128 | // deletes the subkey with all of it's subkeys/values recursively | |
129 | bool DeleteKey(const char *szKey); | |
130 | // deletes the named value (may be NULL to remove the default value) | |
131 | bool DeleteValue(const char *szValue); | |
132 | ||
133 | // access to values and subkeys | |
134 | // get value type | |
135 | ValueType GetValueType(const char *szValue); | |
136 | ||
137 | // assignment operators set the default value of the key | |
138 | wxRegKey& operator=(const wxString& strValue) | |
139 | { SetValue(NULL, strValue); return *this; } | |
140 | wxRegKey& operator=(long lValue) | |
141 | { SetValue(NULL, lValue); return *this; } | |
142 | ||
143 | // conversion operators query the default value of the key | |
144 | operator wxString() const; | |
145 | ||
146 | // set the string value | |
147 | bool SetValue(const char *szValue, const wxString& strValue); | |
148 | // return the string value | |
149 | bool QueryValue(const char *szValue, wxString& strValue) const; | |
150 | ||
151 | #ifdef __WIN32__ | |
152 | // set the numeric value | |
153 | bool SetValue(const char *szValue, long lValue); | |
154 | // return the numeric value | |
155 | bool QueryValue(const char *szValue, long *plValue) const; | |
156 | #endif //Win32 | |
157 | ||
158 | // return TRUE if given subkey exists | |
159 | bool HasSubKey(const char *szKey) const; | |
160 | // return TRUE if any subkeys exist | |
161 | bool HasSubkeys() const; | |
162 | ||
163 | // enumerate values and subkeys | |
164 | #ifdef __WIN32__ | |
165 | bool GetFirstValue(wxString& strValueName, long& lIndex); | |
166 | bool GetNextValue (wxString& strValueName, long& lIndex) const; | |
167 | #endif //Win32 | |
168 | ||
169 | bool GetFirstKey (wxString& strKeyName , long& lIndex); | |
170 | bool GetNextKey (wxString& strKeyName , long& lIndex) const; | |
171 | ||
172 | private: | |
173 | // no copy ctor/assignment operator | |
174 | wxRegKey(const wxRegKey& key); // not implemented | |
175 | wxRegKey& operator=(const wxRegKey& key); // not implemented | |
176 | ||
177 | HKEY m_hKey, // our handle | |
178 | m_hRootKey; // handle of the top key (i.e. StdKey) | |
179 | wxString m_strKey; // key name (relative to m_hRootKey) | |
180 | ||
181 | MUTABLE long m_dwLastError; // last error (0 if none) | |
182 | }; | |
183 | ||
184 | #endif //_REGISTRY_H |