]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/registry.h
applied patch 410892 (wxCopyFile uses ::CopyFile under Win32, has overwrite parameter)
[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
23f681ec 5// Modified by:
2bda0e17
KB
6// Created: 03.04.198
7// RCS-ID: $Id$
8// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
bbcdf8bc 9// Licence: wxWindows licence
2bda0e17
KB
10///////////////////////////////////////////////////////////////////////////////
11
12#ifndef _REGISTRY_H
13#define _REGISTRY_H
14
0d3820b3
JS
15#ifdef __GNUG__
16#pragma interface "registry.h"
17#endif
18
2bda0e17
KB
19// ----------------------------------------------------------------------------
20// mutable hack (see also registry.cpp)
21// ----------------------------------------------------------------------------
47d67540 22#if wxUSE_MUTABLE
2bda0e17
KB
23 #define MUTABLE mutable
24#else
25 #define MUTABLE
26#endif
27
28// ----------------------------------------------------------------------------
8f494e5d 29// types used in this module
2bda0e17 30// ----------------------------------------------------------------------------
0d8d91a9
JS
31
32/*
2bda0e17
KB
33#ifndef HKEY_DEFINED
34 #define HKEY_DEFINED
35 #define HKEY unsigned long
36#endif
0d8d91a9 37*/
2bda0e17 38
8f494e5d
VZ
39typedef unsigned long ulong;
40
2bda0e17
KB
41// ----------------------------------------------------------------------------
42// class wxRegKey encapsulates window HKEY handle
43// ----------------------------------------------------------------------------
44class WXDLLEXPORT wxRegKey
45{
46public:
47 // NB: do _not_ change the values of elements in these enumerations!
48
49 // registry value types (with comments from winnt.h)
50 enum ValueType
51 {
52 Type_None, // No value type
53 Type_String, // Unicode nul terminated string
54#ifdef __WIN32__
55 Type_Expand_String, // Unicode nul terminated string
56 // (with environment variable references)
57 Type_Binary, // Free form binary
58 Type_Dword, // 32-bit number
23f681ec
VZ
59 Type_Dword_little_endian // 32-bit number
60 = Type_Dword, // (same as Type_DWORD)
2bda0e17
KB
61 Type_Dword_big_endian, // 32-bit number
62 Type_Link, // Symbolic Link (unicode)
63 Type_Multi_String, // Multiple Unicode strings
64 Type_Resource_list, // Resource list in the resource map
65 Type_Full_resource_descriptor, // Resource list in the hardware description
a3ef5bf5 66 Type_Resource_requirements_list // ???
2bda0e17
KB
67#endif //WIN32
68 };
69
70 // predefined registry keys
71 enum StdKey
72 {
23f681ec 73 HKCR // classes root
2bda0e17 74#ifdef __WIN32__
23f681ec
VZ
75 ,
76 HKCU, // current user
77 HKLM, // local machine
78 HKUSR, // users
79 HKPD // performance data (WinNT/2K only)
80#if WINVER >= 0x0400
81 ,
82 HKCC, // current config (starting from Win95/NT 4.0)
83 HKDD // dynamic data (Win95/98 only)
2bda0e17
KB
84#endif // Winver
85#endif // Win32/16
86 };
87
88 // information about standard (predefined) registry keys
89 // number of standard keys
90 static const size_t nStdKeys;
91 // get the name of a standard key
4de6207a 92 static const wxChar *GetStdKeyName(size_t key);
2bda0e17 93 // get the short name of a standard key
4de6207a 94 static const wxChar *GetStdKeyShortName(size_t key);
2bda0e17 95 // get StdKey from root HKEY
0d8d91a9 96 static StdKey GetStdKeyFromHkey(WXHKEY hkey);
2bda0e17
KB
97
98 // extacts the std key prefix from the string (return value) and
99 // leaves only the part after it (i.e. modifies the string passed!)
100 static StdKey ExtractKeyName(wxString& str);
101
102 // ctors
103 // root key is set to HKCR (the only root key under Win16)
104 wxRegKey();
105 // strKey is the full name of the key (i.e. starting with HKEY_xxx...)
106 wxRegKey(const wxString& strKey);
107 // strKey is the name of key under (standard key) keyParent
2dc77646 108 wxRegKey(StdKey keyParent, const wxString& strKey);
2bda0e17
KB
109 // strKey is the name of key under (previously created) keyParent
110 wxRegKey(const wxRegKey& keyParent, const wxString& strKey);
111 //
112 ~wxRegKey();
113
114 // change key (closes the previously opened key if any)
2dc77646 115 // the name is absolute, i.e. should start with HKEY_xxx
2bda0e17 116 void SetName(const wxString& strKey);
2dc77646
VZ
117 // the name is relative to the parent key
118 void SetName(StdKey keyParent, const wxString& strKey);
119 // the name is relative to the parent key
120 void SetName(const wxRegKey& keyParent, const wxString& strKey);
121 // hKey should be opened and will be closed in wxRegKey dtor
0d8d91a9 122 void SetHkey(WXHKEY hKey);
2bda0e17
KB
123
124 // get infomation about the key
125 // get the (full) key name. Abbreviate std root keys if bShortPrefix.
cf447356 126 wxString GetName(bool bShortPrefix = TRUE) const;
2dc77646 127 // return true if the key exists
8f494e5d
VZ
128 bool Exists() const;
129 // get the info about key (any number of these pointers may be NULL)
3cda6353
VZ
130 bool GetKeyInfo(size_t *pnSubKeys, // number of subkeys
131 size_t *pnMaxKeyLen, // max len of subkey name
132 size_t *pnValues, // number of values
133 size_t *pnMaxValueLen) const;
2dc77646 134 // return true if the key is opened
8f494e5d 135 bool IsOpened() const { return m_hKey != 0; }
2bda0e17
KB
136 // for "if ( !key ) wxLogError(...)" kind of expressions
137 operator bool() const { return m_dwLastError == 0; }
138
139 // operations on the key itself
140 // explicitly open the key (will be automatically done by all functions
141 // which need the key to be opened if the key is not opened yet)
142 bool Open();
23f681ec 143 // create the key: will fail if the key already exists and !bOkIfExists
cf447356 144 bool Create(bool bOkIfExists = TRUE);
23f681ec
VZ
145 // rename a value from old name to new one
146 bool RenameValue(const wxChar *szValueOld, const wxChar *szValueNew);
225fe9d6
VZ
147 // rename the key
148 bool Rename(const wxChar *szNewName);
23f681ec
VZ
149 // copy value to another key possibly changing its name (by default it will
150 // remain the same)
151 bool CopyValue(const wxChar *szValue, wxRegKey& keyDst,
152 const wxChar *szNewName = NULL);
153 // copy the entire contents of the key recursively to another location
225fe9d6 154 bool Copy(const wxChar *szNewName);
23f681ec
VZ
155 // same as Copy() but using a key and not the name
156 bool Copy(wxRegKey& keyDst);
2bda0e17
KB
157 // close the key (will be automatically done in dtor)
158 bool Close();
159
160 // deleting keys/values
161 // deletes this key and all of it's subkeys/values
162 bool DeleteSelf();
163 // deletes the subkey with all of it's subkeys/values recursively
4de6207a 164 bool DeleteKey(const wxChar *szKey);
2bda0e17 165 // deletes the named value (may be NULL to remove the default value)
4de6207a 166 bool DeleteValue(const wxChar *szValue);
2bda0e17
KB
167
168 // access to values and subkeys
169 // get value type
4de6207a 170 ValueType GetValueType(const wxChar *szValue) const;
90186e52 171 // returns TRUE if the value contains a number (else it's some string)
4de6207a 172 bool IsNumericValue(const wxChar *szValue) const;
2bda0e17
KB
173
174 // assignment operators set the default value of the key
175 wxRegKey& operator=(const wxString& strValue)
176 { SetValue(NULL, strValue); return *this; }
177 wxRegKey& operator=(long lValue)
178 { SetValue(NULL, lValue); return *this; }
179
180 // conversion operators query the default value of the key
181 operator wxString() const;
182
183 // set the string value
4de6207a 184 bool SetValue(const wxChar *szValue, const wxString& strValue);
6dfec4b8
VZ
185 // retrieve the string value
186 bool QueryValue(const wxChar *szValue, wxString& strValue) const
187 { return QueryValue(szValue, strValue, FALSE); }
188 // retrieve raw string value
189 bool QueryRawValue(const wxChar *szValue, wxString& strValue) const
190 { return QueryValue(szValue, strValue, TRUE); }
191 // retrieve either raw or expanded string value
192 bool QueryValue(const wxChar *szValue, wxString& strValue, bool raw) const;
2bda0e17
KB
193
194#ifdef __WIN32__
195 // set the numeric value
4de6207a 196 bool SetValue(const wxChar *szValue, long lValue);
2bda0e17 197 // return the numeric value
4de6207a 198 bool QueryValue(const wxChar *szValue, long *plValue) const;
2bda0e17
KB
199#endif //Win32
200
2dc77646
VZ
201 // query existence of a key/value
202 // return true if value exists
92049cd4 203 bool HasValue(const wxChar *szKey) const;
2dc77646 204 // return true if given subkey exists
92049cd4 205 bool HasSubKey(const wxChar *szKey) const;
2dc77646 206 // return true if any subkeys exist
92049cd4
VZ
207 bool HasSubkeys() const;
208 // return true if any values exist
209 bool HasValues() const;
210 // return true if the key is empty (nothing under this key)
211 bool IsEmpty() const { return !HasSubkeys() && !HasValues(); }
2bda0e17
KB
212
213 // enumerate values and subkeys
2bda0e17
KB
214 bool GetFirstValue(wxString& strValueName, long& lIndex);
215 bool GetNextValue (wxString& strValueName, long& lIndex) const;
2bda0e17
KB
216
217 bool GetFirstKey (wxString& strKeyName , long& lIndex);
218 bool GetNextKey (wxString& strKeyName , long& lIndex) const;
219
220private:
221 // no copy ctor/assignment operator
222 wxRegKey(const wxRegKey& key); // not implemented
223 wxRegKey& operator=(const wxRegKey& key); // not implemented
224
c085e333 225 WXHKEY m_hKey, // our handle
2bda0e17
KB
226 m_hRootKey; // handle of the top key (i.e. StdKey)
227 wxString m_strKey; // key name (relative to m_hRootKey)
228
229 MUTABLE long m_dwLastError; // last error (0 if none)
230};
231
232#endif //_REGISTRY_H
2dc77646 233