]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/registry.h
Misc small changes, some for VC++ 1.5
[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);
147 // copy value to another key possibly changing its name (by default it will
148 // remain the same)
149 bool CopyValue(const wxChar *szValue, wxRegKey& keyDst,
150 const wxChar *szNewName = NULL);
151 // copy the entire contents of the key recursively to another location
152 bool Copy(const wxString& strNewName);
153 // same as Copy() but using a key and not the name
154 bool Copy(wxRegKey& keyDst);
2bda0e17
KB
155 // close the key (will be automatically done in dtor)
156 bool Close();
157
158 // deleting keys/values
159 // deletes this key and all of it's subkeys/values
160 bool DeleteSelf();
161 // deletes the subkey with all of it's subkeys/values recursively
4de6207a 162 bool DeleteKey(const wxChar *szKey);
2bda0e17 163 // deletes the named value (may be NULL to remove the default value)
4de6207a 164 bool DeleteValue(const wxChar *szValue);
2bda0e17
KB
165
166 // access to values and subkeys
167 // get value type
4de6207a 168 ValueType GetValueType(const wxChar *szValue) const;
90186e52 169 // returns TRUE if the value contains a number (else it's some string)
4de6207a 170 bool IsNumericValue(const wxChar *szValue) const;
2bda0e17
KB
171
172 // assignment operators set the default value of the key
173 wxRegKey& operator=(const wxString& strValue)
174 { SetValue(NULL, strValue); return *this; }
175 wxRegKey& operator=(long lValue)
176 { SetValue(NULL, lValue); return *this; }
177
178 // conversion operators query the default value of the key
179 operator wxString() const;
180
181 // set the string value
4de6207a 182 bool SetValue(const wxChar *szValue, const wxString& strValue);
2bda0e17 183 // return the string value
4de6207a 184 bool QueryValue(const wxChar *szValue, wxString& strValue) const;
2bda0e17
KB
185
186#ifdef __WIN32__
187 // set the numeric value
4de6207a 188 bool SetValue(const wxChar *szValue, long lValue);
2bda0e17 189 // return the numeric value
4de6207a 190 bool QueryValue(const wxChar *szValue, long *plValue) const;
2bda0e17
KB
191#endif //Win32
192
2dc77646
VZ
193 // query existence of a key/value
194 // return true if value exists
92049cd4 195 bool HasValue(const wxChar *szKey) const;
2dc77646 196 // return true if given subkey exists
92049cd4 197 bool HasSubKey(const wxChar *szKey) const;
2dc77646 198 // return true if any subkeys exist
92049cd4
VZ
199 bool HasSubkeys() const;
200 // return true if any values exist
201 bool HasValues() const;
202 // return true if the key is empty (nothing under this key)
203 bool IsEmpty() const { return !HasSubkeys() && !HasValues(); }
2bda0e17
KB
204
205 // enumerate values and subkeys
2bda0e17
KB
206 bool GetFirstValue(wxString& strValueName, long& lIndex);
207 bool GetNextValue (wxString& strValueName, long& lIndex) const;
2bda0e17
KB
208
209 bool GetFirstKey (wxString& strKeyName , long& lIndex);
210 bool GetNextKey (wxString& strKeyName , long& lIndex) const;
211
212private:
213 // no copy ctor/assignment operator
214 wxRegKey(const wxRegKey& key); // not implemented
215 wxRegKey& operator=(const wxRegKey& key); // not implemented
216
c085e333 217 WXHKEY m_hKey, // our handle
2bda0e17
KB
218 m_hRootKey; // handle of the top key (i.e. StdKey)
219 wxString m_strKey; // key name (relative to m_hRootKey)
220
221 MUTABLE long m_dwLastError; // last error (0 if none)
222};
223
224#endif //_REGISTRY_H
2dc77646 225