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 license
10 ///////////////////////////////////////////////////////////////////////////////
16 #pragma interface "registry.h"
19 // ----------------------------------------------------------------------------
20 // mutable hack (see also registry.cpp)
21 // ----------------------------------------------------------------------------
23 #define MUTABLE mutable
28 // ----------------------------------------------------------------------------
29 // forward decl for handle type
30 // ----------------------------------------------------------------------------
33 #define HKEY unsigned long
36 // ----------------------------------------------------------------------------
37 // class wxRegKey encapsulates window HKEY handle
38 // ----------------------------------------------------------------------------
39 class WXDLLEXPORT wxRegKey
42 // NB: do _not_ change the values of elements in these enumerations!
44 // registry value types (with comments from winnt.h)
47 Type_None
, // No value type
48 Type_String
, // Unicode nul terminated string
50 Type_Expand_String
, // Unicode nul terminated string
51 // (with environment variable references)
52 Type_Binary
, // Free form binary
53 Type_Dword
, // 32-bit number
54 Type_Dword_little_endian
, // 32-bit number (same as Type_DWORD)
55 Type_Dword_big_endian
, // 32-bit number
56 Type_Link
, // Symbolic Link (unicode)
57 Type_Multi_String
, // Multiple Unicode strings
58 Type_Resource_list
, // Resource list in the resource map
59 Type_Full_resource_descriptor
, // Resource list in the hardware description
60 Type_Resource_requirements_list
, // ???
64 // predefined registry keys
70 HKLM
, // local machine
72 HKPD
, // performance data (@@ NT only?)
74 HKCC
, // current config
80 // information about standard (predefined) registry keys
81 // number of standard keys
82 static const size_t nStdKeys
;
83 // get the name of a standard key
84 static const char *GetStdKeyName(uint key
);
85 // get the short name of a standard key
86 static const char *GetStdKeyShortName(uint key
);
87 // get StdKey from root HKEY
88 static StdKey
GetStdKeyFromHkey(HKEY hkey
);
90 // extacts the std key prefix from the string (return value) and
91 // leaves only the part after it (i.e. modifies the string passed!)
92 static StdKey
ExtractKeyName(wxString
& str
);
95 // root key is set to HKCR (the only root key under Win16)
97 // strKey is the full name of the key (i.e. starting with HKEY_xxx...)
98 wxRegKey(const wxString
& strKey
);
99 // strKey is the name of key under (standard key) keyParent
100 wxRegKey(StdKey keyParent
, const wxString
& strKey
);
101 // strKey is the name of key under (previously created) keyParent
102 wxRegKey(const wxRegKey
& keyParent
, const wxString
& strKey
);
106 // change key (closes the previously opened key if any)
107 // the name is absolute, i.e. should start with HKEY_xxx
108 void SetName(const wxString
& strKey
);
109 // the name is relative to the parent key
110 void SetName(StdKey keyParent
, const wxString
& strKey
);
111 // the name is relative to the parent key
112 void SetName(const wxRegKey
& keyParent
, const wxString
& strKey
);
113 // hKey should be opened and will be closed in wxRegKey dtor
114 void SetHkey(HKEY hKey
);
116 // get infomation about the key
117 // get the (full) key name. Abbreviate std root keys if bShortPrefix.
118 wxString
GetName(bool bShortPrefix
= TRUE
) const;
119 // return true if the key exists
121 // return true if the key is opened
122 bool IsOpened() const { return m_hKey
!= 0; }
123 // for "if ( !key ) wxLogError(...)" kind of expressions
124 operator bool() const { return m_dwLastError
== 0; }
126 // operations on the key itself
127 // explicitly open the key (will be automatically done by all functions
128 // which need the key to be opened if the key is not opened yet)
130 // create the key: will fail if the key already exists and bOkIfExists
131 bool Create(bool bOkIfExists
= TRUE
);
132 // close the key (will be automatically done in dtor)
135 // deleting keys/values
136 // deletes this key and all of it's subkeys/values
138 // deletes the subkey with all of it's subkeys/values recursively
139 bool DeleteKey(const char *szKey
);
140 // deletes the named value (may be NULL to remove the default value)
141 bool DeleteValue(const char *szValue
);
143 // access to values and subkeys
145 ValueType
GetValueType(const char *szValue
);
147 // assignment operators set the default value of the key
148 wxRegKey
& operator=(const wxString
& strValue
)
149 { SetValue(NULL
, strValue
); return *this; }
150 wxRegKey
& operator=(long lValue
)
151 { SetValue(NULL
, lValue
); return *this; }
153 // conversion operators query the default value of the key
154 operator wxString() const;
156 // set the string value
157 bool SetValue(const char *szValue
, const wxString
& strValue
);
158 // return the string value
159 bool QueryValue(const char *szValue
, wxString
& strValue
) const;
162 // set the numeric value
163 bool SetValue(const char *szValue
, long lValue
);
164 // return the numeric value
165 bool QueryValue(const char *szValue
, long *plValue
) const;
168 // query existence of a key/value
169 // return true if value exists
170 bool HasValue(const char *szKey
) const;
171 // return true if given subkey exists
172 bool HasSubKey(const char *szKey
) const;
173 // return true if any subkeys exist
174 bool HasSubkeys() const;
176 // enumerate values and subkeys
177 bool GetFirstValue(wxString
& strValueName
, long& lIndex
);
178 bool GetNextValue (wxString
& strValueName
, long& lIndex
) const;
180 bool GetFirstKey (wxString
& strKeyName
, long& lIndex
);
181 bool GetNextKey (wxString
& strKeyName
, long& lIndex
) const;
184 // no copy ctor/assignment operator
185 wxRegKey(const wxRegKey
& key
); // not implemented
186 wxRegKey
& operator=(const wxRegKey
& key
); // not implemented
188 HKEY m_hKey
, // our handle
189 m_hRootKey
; // handle of the top key (i.e. StdKey)
190 wxString m_strKey
; // key name (relative to m_hRootKey)
192 MUTABLE
long m_dwLastError
; // last error (0 if none)