]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/registry.h
Added wxExpr parser/lexer files which had somehow got lost;
[wxWidgets.git] / include / wx / msw / registry.h
CommitLineData
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// ----------------------------------------------------------------------------
35class WXDLLEXPORT wxRegKey
36{
37public:
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
2dc77646 96 wxRegKey(StdKey keyParent, const wxString& strKey);
2bda0e17
KB
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)
2dc77646 103 // the name is absolute, i.e. should start with HKEY_xxx
2bda0e17 104 void SetName(const wxString& strKey);
2dc77646
VZ
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);
2bda0e17
KB
111
112 // get infomation about the key
113 // get the (full) key name. Abbreviate std root keys if bShortPrefix.
cf447356 114 wxString GetName(bool bShortPrefix = TRUE) const;
2dc77646 115 // return true if the key exists
2bda0e17 116 bool Exists() const;
2dc77646 117 // return true if the key is opened
2bda0e17
KB
118 bool IsOpened() const { return m_hKey != 0; }
119 // for "if ( !key ) wxLogError(...)" kind of expressions
120 operator bool() const { return m_dwLastError == 0; }
121
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)
125 bool Open();
126 // create the key: will fail if the key already exists and bOkIfExists
cf447356 127 bool Create(bool bOkIfExists = TRUE);
2bda0e17
KB
128 // close the key (will be automatically done in dtor)
129 bool Close();
130
131 // deleting keys/values
132 // deletes this key and all of it's subkeys/values
133 bool DeleteSelf();
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);
138
139 // access to values and subkeys
140 // get value type
141 ValueType GetValueType(const char *szValue);
142
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; }
148
149 // conversion operators query the default value of the key
150 operator wxString() const;
151
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;
156
157#ifdef __WIN32__
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;
162#endif //Win32
163
2dc77646
VZ
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
2bda0e17 168 bool HasSubKey(const char *szKey) const;
2dc77646 169 // return true if any subkeys exist
2bda0e17
KB
170 bool HasSubkeys() const;
171
172 // enumerate values and subkeys
2bda0e17
KB
173 bool GetFirstValue(wxString& strValueName, long& lIndex);
174 bool GetNextValue (wxString& strValueName, long& lIndex) const;
2bda0e17
KB
175
176 bool GetFirstKey (wxString& strKeyName , long& lIndex);
177 bool GetNextKey (wxString& strKeyName , long& lIndex) const;
178
179private:
180 // no copy ctor/assignment operator
181 wxRegKey(const wxRegKey& key); // not implemented
182 wxRegKey& operator=(const wxRegKey& key); // not implemented
183
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)
187
188 MUTABLE long m_dwLastError; // last error (0 if none)
189};
190
191#endif //_REGISTRY_H
2dc77646 192