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 void SetName(const wxString
& strKey
);
104 void SetHkey(HKEY hKey
);
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
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; }
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)
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)
125 // deleting keys/values
126 // deletes this key and all of it's subkeys/values
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
);
133 // access to values and subkeys
135 ValueType
GetValueType(const char *szValue
);
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; }
143 // conversion operators query the default value of the key
144 operator wxString() const;
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;
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;
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;
163 // enumerate values and subkeys
165 bool GetFirstValue(wxString
& strValueName
, long& lIndex
);
166 bool GetNextValue (wxString
& strValueName
, long& lIndex
) const;
169 bool GetFirstKey (wxString
& strKeyName
, long& lIndex
);
170 bool GetNextKey (wxString
& strKeyName
, long& lIndex
) const;
173 // no copy ctor/assignment operator
174 wxRegKey(const wxRegKey
& key
); // not implemented
175 wxRegKey
& operator=(const wxRegKey
& key
); // not implemented
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)
181 MUTABLE
long m_dwLastError
; // last error (0 if none)