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 ///////////////////////////////////////////////////////////////////////////////
15 // ----------------------------------------------------------------------------
16 // mutable hack (see also registry.cpp)
17 // ----------------------------------------------------------------------------
19 #define MUTABLE mutable
24 // ----------------------------------------------------------------------------
25 // forward decl for handle type
26 // ----------------------------------------------------------------------------
29 #define HKEY unsigned long
32 // ----------------------------------------------------------------------------
33 // class wxRegKey encapsulates window HKEY handle
34 // ----------------------------------------------------------------------------
35 class WXDLLEXPORT wxRegKey
38 // NB: do _not_ change the values of elements in these enumerations!
40 // registry value types (with comments from winnt.h)
43 Type_None
, // No value type
44 Type_String
, // Unicode nul terminated string
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
, // ???
60 // predefined registry keys
66 HKLM
, // local machine
68 HKPD
, // performance data (@@ NT only?)
70 HKCC
, // current config
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
);
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
);
91 // root key is set to HKCR (the only root key under Win16)
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
);
102 // change key (closes the previously opened key if any)
103 // the name is absolute, i.e. should start with HKEY_xxx
104 void SetName(const wxString
& strKey
);
105 // the name is relative to the parent key
106 void SetName(StdKey keyParent
, const wxString
& strKey
);
107 // the name is relative to the parent key
108 void SetName(const wxRegKey
& keyParent
, const wxString
& strKey
);
109 // hKey should be opened and will be closed in wxRegKey dtor
110 void SetHkey(HKEY hKey
);
112 // get infomation about the key
113 // get the (full) key name. Abbreviate std root keys if bShortPrefix.
114 wxString
GetName(bool bShortPrefix
= TRUE
) const;
115 // return true if the key exists
117 // return true if the key is opened
118 bool IsOpened() const { return m_hKey
!= 0; }
119 // for "if ( !key ) wxLogError(...)" kind of expressions
120 operator bool() const { return m_dwLastError
== 0; }
122 // operations on the key itself
123 // explicitly open the key (will be automatically done by all functions
124 // which need the key to be opened if the key is not opened yet)
126 // create the key: will fail if the key already exists and bOkIfExists
127 bool Create(bool bOkIfExists
= TRUE
);
128 // close the key (will be automatically done in dtor)
131 // deleting keys/values
132 // deletes this key and all of it's subkeys/values
134 // deletes the subkey with all of it's subkeys/values recursively
135 bool DeleteKey(const char *szKey
);
136 // deletes the named value (may be NULL to remove the default value)
137 bool DeleteValue(const char *szValue
);
139 // access to values and subkeys
141 ValueType
GetValueType(const char *szValue
);
143 // assignment operators set the default value of the key
144 wxRegKey
& operator=(const wxString
& strValue
)
145 { SetValue(NULL
, strValue
); return *this; }
146 wxRegKey
& operator=(long lValue
)
147 { SetValue(NULL
, lValue
); return *this; }
149 // conversion operators query the default value of the key
150 operator wxString() const;
152 // set the string value
153 bool SetValue(const char *szValue
, const wxString
& strValue
);
154 // return the string value
155 bool QueryValue(const char *szValue
, wxString
& strValue
) const;
158 // set the numeric value
159 bool SetValue(const char *szValue
, long lValue
);
160 // return the numeric value
161 bool QueryValue(const char *szValue
, long *plValue
) const;
164 // query existence of a key/value
165 // return true if value exists
166 bool HasValue(const char *szKey
) const;
167 // return true if given subkey exists
168 bool HasSubKey(const char *szKey
) const;
169 // return true if any subkeys exist
170 bool HasSubkeys() const;
172 // enumerate values and subkeys
173 bool GetFirstValue(wxString
& strValueName
, long& lIndex
);
174 bool GetNextValue (wxString
& strValueName
, long& lIndex
) const;
176 bool GetFirstKey (wxString
& strKeyName
, long& lIndex
);
177 bool GetNextKey (wxString
& strKeyName
, long& lIndex
) const;
180 // no copy ctor/assignment operator
181 wxRegKey(const wxRegKey
& key
); // not implemented
182 wxRegKey
& operator=(const wxRegKey
& key
); // not implemented
184 HKEY m_hKey
, // our handle
185 m_hRootKey
; // handle of the top key (i.e. StdKey)
186 wxString m_strKey
; // key name (relative to m_hRootKey)
188 MUTABLE
long m_dwLastError
; // last error (0 if none)