2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: msw/registry.h
|
2008-03-10 11:24:38 -04:00
|
|
|
// Purpose: interface of wxRegKey
|
2008-03-08 08:52:38 -05:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxRegKey
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
wxRegKey is a class representing the Windows registry (it is only available
|
|
|
|
under Windows). One can create, query and delete registry keys using this
|
|
|
|
class.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
The Windows registry is easy to understand. There are five registry keys,
|
|
|
|
namely:
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-06-21 01:53:53 -04:00
|
|
|
@li @c HKEY_CLASSES_ROOT (HKCR)
|
|
|
|
@li @c HKEY_CURRENT_USER (HKCU)
|
|
|
|
@li @c HKEY_LOCAL_MACHINE (HKLM)
|
|
|
|
@li @c HKEY_CURRENT_CONFIG (HKCC)
|
|
|
|
@li @c HKEY_USERS (HKU)
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
After creating a key, it can hold a value. The values can be:
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-06-20 22:38:44 -04:00
|
|
|
@li String Value
|
|
|
|
@li Binary Value
|
|
|
|
@li DWORD Value
|
|
|
|
@li Multi String Value
|
|
|
|
@li Expandable String Value
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-27 16:54:47 -04:00
|
|
|
@onlyfor{wxmsw}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-06-20 22:38:44 -04:00
|
|
|
@b Example:
|
|
|
|
|
|
|
|
@code
|
|
|
|
wxRegKey *key = new wxRegKey("HKEY_LOCAL_MACHINE\\Software\\MyKey");
|
|
|
|
|
|
|
|
// Create the key if it does not exist.
|
|
|
|
if( !key->Exists() )
|
|
|
|
key->Create();
|
|
|
|
|
|
|
|
// Create a new value "MYVALUE" and set it to 12.
|
|
|
|
key->SetValue("MYVALUE", 12);
|
|
|
|
|
|
|
|
// Read the value back.
|
|
|
|
long value;
|
|
|
|
key->QueryValue("MYVALUE", &value);
|
|
|
|
wxMessageBox(wxString::Format("%d", value), "Registry Value", wxOK);
|
|
|
|
|
|
|
|
// Get the number of subkeys and enumerate them.
|
|
|
|
size_t subkeys;
|
|
|
|
key->GetKeyInfo(&subkeys, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
wxString key_name;
|
|
|
|
key->GetFirstKey(key_name, 1);
|
|
|
|
for(int i = 0; i < subkeys; i++)
|
|
|
|
{
|
|
|
|
wxMessageBox(key_name, "Subkey Name", wxOK);
|
|
|
|
key->GetNextKey(key_name, 1);
|
|
|
|
}
|
|
|
|
@endcode
|
2009-02-20 06:34:52 -05:00
|
|
|
|
|
|
|
|
|
|
|
@library{wxbase}
|
|
|
|
@category{cfg}
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
class wxRegKey
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2008-06-21 01:53:53 -04:00
|
|
|
Default constructor, initializes to @c HKEY_CLASSES_ROOT.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
wxRegKey();
|
2008-06-20 22:38:44 -04:00
|
|
|
/**
|
|
|
|
The constructor to set the full name of the key.
|
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
wxRegKey(const wxString& strKey);
|
2008-12-17 04:03:50 -05:00
|
|
|
/**
|
2009-02-20 06:34:52 -05:00
|
|
|
The constructor to set the full name of the key using one of the
|
2008-12-17 04:03:50 -05:00
|
|
|
standard keys, that is, HKCR, HKCU, HKLM, HKUSR, HKPD, HKCC or HKDD.
|
|
|
|
*/
|
|
|
|
wxRegKey(StdKey keyParent, const wxString& strKey);
|
2008-06-20 22:38:44 -04:00
|
|
|
/**
|
|
|
|
The constructor to set the full name of the key under a previously created
|
|
|
|
parent.
|
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
wxRegKey(const wxRegKey& keyParent, const wxString& strKey);
|
2008-06-20 22:38:44 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Access modes for wxRegKey.
|
|
|
|
*/
|
|
|
|
enum AccessMode
|
|
|
|
{
|
2008-12-17 04:03:50 -05:00
|
|
|
Read, ///< Read-only
|
|
|
|
Write ///< Read and Write
|
|
|
|
};
|
|
|
|
|
2009-02-20 06:34:52 -05:00
|
|
|
/**
|
2008-12-17 04:03:50 -05:00
|
|
|
The standard registry key enumerator.
|
|
|
|
*/
|
|
|
|
enum StdKey
|
|
|
|
{
|
|
|
|
HKCR, ///< HKEY_CLASSES_ROOT
|
|
|
|
HKCU, ///< HKEY_CURRENT_USER
|
|
|
|
HKLM, ///< HKEY_LOCAL_MACHINE
|
|
|
|
HKUSR, ///< HKEY_USERS
|
|
|
|
HKPD, ///< HKEY_PERFORMANCE_DATA (Windows NT and 2K only)
|
|
|
|
HKCC, ///< HKEY_CURRENT_CONFIG
|
|
|
|
HKDD, ///< HKEY_DYN_DATA (Windows 95 and 98 only)
|
|
|
|
HKMAX
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
The value type enumerator.
|
|
|
|
*/
|
|
|
|
enum ValueType
|
|
|
|
{
|
|
|
|
Type_None, ///< No value type
|
|
|
|
Type_String, ///< Unicode null-terminated string
|
|
|
|
Type_Expand_String, ///< Unicode null-terminated string
|
|
|
|
///< (with environment variable references)
|
|
|
|
Type_Binary, ///< Free form binary
|
|
|
|
Type_Dword, ///< 32-bit number
|
|
|
|
Type_Dword_little_endian, ///< 32-bit number (same as Type_Dword)
|
|
|
|
Type_Dword_big_endian, ///< 32-bit number
|
|
|
|
Type_Link, ///< Symbolic Link (Unicode)
|
|
|
|
Type_Multi_String, ///< Multiple Unicode strings
|
|
|
|
Type_Resource_list, ///< Resource list in the resource map
|
|
|
|
Type_Full_resource_descriptor, ///< Resource list in the hardware description
|
2009-02-20 06:34:52 -05:00
|
|
|
Type_Resource_requirements_list ///<
|
2008-06-20 22:38:44 -04:00
|
|
|
};
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Closes the key.
|
|
|
|
*/
|
|
|
|
void Close();
|
|
|
|
|
2008-12-17 04:03:50 -05:00
|
|
|
/**
|
|
|
|
Copy the entire contents of the key recursively to another location
|
2009-01-21 13:04:37 -05:00
|
|
|
using the name. Returns @true if successful.
|
2008-12-17 04:03:50 -05:00
|
|
|
*/
|
|
|
|
bool Copy(const wxString& szNewName);
|
|
|
|
/**
|
|
|
|
Copy the entire contents of the key recursively to another location
|
2009-01-21 13:04:37 -05:00
|
|
|
using the key. Returns @true if successful.
|
2008-12-17 04:03:50 -05:00
|
|
|
*/
|
|
|
|
bool Copy(wxRegKey& keyDst);
|
2009-02-20 06:34:52 -05:00
|
|
|
|
2008-12-17 04:03:50 -05:00
|
|
|
/**
|
|
|
|
Copy the value to another key, possibly changing its name. By default
|
2009-01-21 13:04:37 -05:00
|
|
|
it will remain the same. Returns @true if successful.
|
2008-12-17 04:03:50 -05:00
|
|
|
*/
|
2009-02-20 06:34:52 -05:00
|
|
|
bool CopyValue(const wxString& szValue, wxRegKey& keyDst,
|
2008-12-17 04:03:50 -05:00
|
|
|
const wxString& szNewName = wxEmptyString);
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2009-01-21 13:04:37 -05:00
|
|
|
Creates the key. Will fail if the key already exists and @a bOkIfExists
|
|
|
|
is @false. Returns @true if successful.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 08:33:59 -04:00
|
|
|
bool Create(bool bOkIfExists = true);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2009-01-21 13:04:37 -05:00
|
|
|
Deletes the subkey with all its subkeys and values recursively.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-11-22 05:41:52 -05:00
|
|
|
void DeleteKey(const wxString& szKey);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2009-01-21 13:04:37 -05:00
|
|
|
Deletes this key and all its subkeys and values recursively.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void DeleteSelf();
|
|
|
|
|
|
|
|
/**
|
2009-02-20 06:34:52 -05:00
|
|
|
Deletes the named value or use an empty string argument to remove the
|
2009-01-21 13:04:37 -05:00
|
|
|
default value of the key.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-11-22 05:41:52 -05:00
|
|
|
void DeleteValue(const wxString& szKey);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the key exists.
|
|
|
|
*/
|
2008-06-20 22:38:44 -04:00
|
|
|
bool Exists() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2008-12-17 04:03:50 -05:00
|
|
|
/**
|
|
|
|
Write the contents of this key and all its subkeys to the given file.
|
|
|
|
(The file will not be overwritten; it's an error if it already exists.)
|
|
|
|
Note that we export the key in REGEDIT4 format, not RegSaveKey() binary
|
2009-01-21 13:04:37 -05:00
|
|
|
format nor the newer REGEDIT5. Returns @true if successful.
|
2008-12-17 04:03:50 -05:00
|
|
|
*/
|
|
|
|
bool Export(const wxString& filename) const;
|
|
|
|
/**
|
|
|
|
Write the contents of this key and all its subkeys to the opened stream.
|
2009-01-21 13:04:37 -05:00
|
|
|
Returns @true if successful.
|
2008-12-17 04:03:50 -05:00
|
|
|
*/
|
|
|
|
bool Export(wxOutputStream& ostr) const;
|
2009-02-20 06:34:52 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2009-01-21 13:04:37 -05:00
|
|
|
Gets the first key. Returns @true if successful.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
bool GetFirstKey(wxString& strKeyName, long& lIndex);
|
|
|
|
|
|
|
|
/**
|
2009-01-21 13:04:37 -05:00
|
|
|
Gets the first value of this key. Returns @true if successful.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
bool GetFirstValue(wxString& strValueName, long& lIndex);
|
|
|
|
|
|
|
|
/**
|
2009-01-21 13:04:37 -05:00
|
|
|
Gets information about the key. Returns @true if successful.
|
2008-03-27 16:54:47 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param pnSubKeys
|
2008-03-09 08:33:59 -04:00
|
|
|
The number of subkeys.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param pnMaxKeyLen
|
2008-03-09 08:33:59 -04:00
|
|
|
The maximum length of the subkey name.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param pnValues
|
2008-03-09 08:33:59 -04:00
|
|
|
The number of values.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param pnMaxValueLen
|
2008-03-09 08:33:59 -04:00
|
|
|
The maximum length of a value.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-06-20 22:38:44 -04:00
|
|
|
bool GetKeyInfo(size_t* pnSubKeys, size_t* pnMaxKeyLen,
|
|
|
|
size_t* pnValues, size_t* pnMaxValueLen) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Gets the name of the registry key.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxString GetName(bool bShortPrefix = true) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2009-01-21 13:04:37 -05:00
|
|
|
Gets the next key. Returns @true if successful.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool GetNextKey(wxString& strKeyName, long& lIndex) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2009-01-21 13:04:37 -05:00
|
|
|
Gets the next key value for this key. Returns @true if successful.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool GetNextValue(wxString& strValueName, long& lIndex) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2008-12-17 04:03:50 -05:00
|
|
|
/**
|
|
|
|
Gets the value type.
|
|
|
|
*/
|
|
|
|
ValueType GetValueType(const wxString& szValue) const;
|
2009-02-20 06:34:52 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
Returns @true if given subkey exists.
|
|
|
|
*/
|
2008-11-22 05:41:52 -05:00
|
|
|
bool HasSubKey(const wxString& szKey) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if any subkeys exist.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool HasSubKeys() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the value exists.
|
|
|
|
*/
|
2008-11-22 05:41:52 -05:00
|
|
|
bool HasValue(const wxString& szValue) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if any values exist.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool HasValues() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if this key is empty, nothing under this key.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool IsEmpty() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2008-12-17 04:03:50 -05:00
|
|
|
/**
|
2009-01-21 13:04:37 -05:00
|
|
|
Returns @true if the value contains a number.
|
2008-12-17 04:03:50 -05:00
|
|
|
*/
|
|
|
|
bool IsNumericValue(const wxString& szValue) const;
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
Returns @true if the key is opened.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool IsOpened() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2009-01-21 13:04:37 -05:00
|
|
|
Explicitly opens the key. This method also allows the key to be opened
|
|
|
|
in read-only mode by passing wxRegKey::Read instead of default
|
|
|
|
wxRegKey::Write parameter. Returns @true if successful.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
bool Open(AccessMode mode = Write);
|
|
|
|
|
2009-01-21 13:04:37 -05:00
|
|
|
/**
|
|
|
|
Assignment operator to set the default value of the key.
|
|
|
|
*/
|
|
|
|
wxRegKey& operator=(const wxString& strValue);
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2008-12-17 04:03:50 -05:00
|
|
|
Return the default value of the key.
|
|
|
|
*/
|
|
|
|
wxString QueryDefaultValue() const;
|
|
|
|
|
|
|
|
/**
|
2009-01-21 13:04:37 -05:00
|
|
|
Retrieves the raw string value. Returns @true if successful.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-12-17 04:03:50 -05:00
|
|
|
bool QueryRawValue(const wxString& szValue, wxString& strValue) const;
|
|
|
|
|
|
|
|
/**
|
2009-01-21 13:04:37 -05:00
|
|
|
Retrieves the raw or expanded string value. Returns @true if successful.
|
2008-12-17 04:03:50 -05:00
|
|
|
*/
|
|
|
|
bool QueryValue(const wxString& szValue, wxString& strValue, bool raw) const;
|
2008-06-20 22:38:44 -04:00
|
|
|
|
|
|
|
/**
|
2009-01-21 13:04:37 -05:00
|
|
|
Retrieves the numeric value. Returns @true if successful.
|
2008-06-20 22:38:44 -04:00
|
|
|
*/
|
2008-12-17 04:03:50 -05:00
|
|
|
bool QueryValue(const wxString& szValue, long* plValue) const;
|
|
|
|
|
|
|
|
/**
|
2009-01-21 13:04:37 -05:00
|
|
|
Retrieves the binary structure. Returns @true if successful.
|
2008-12-17 04:03:50 -05:00
|
|
|
*/
|
|
|
|
bool QueryValue(const wxString& szValue, wxMemoryBuffer& buf) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2009-01-21 13:04:37 -05:00
|
|
|
Renames the key. Returns @true if successful.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-11-22 05:41:52 -05:00
|
|
|
bool Rename(const wxString& szNewName);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2009-01-21 13:04:37 -05:00
|
|
|
Renames a value. Returns @true if successful.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-11-22 05:41:52 -05:00
|
|
|
bool RenameValue(const wxString& szValueOld,
|
|
|
|
const wxString& szValueNew);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2008-12-17 04:03:50 -05:00
|
|
|
/**
|
|
|
|
Preallocate some memory for the name. For wxRegConfig usage only.
|
|
|
|
*/
|
2009-02-20 06:34:52 -05:00
|
|
|
void ReserveMemoryForName(size_t bytes);
|
2008-12-17 04:03:50 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Set or change the HKEY handle.
|
|
|
|
*/
|
|
|
|
void SetHkey(WXHKEY hKey);
|
2009-02-20 06:34:52 -05:00
|
|
|
|
2008-12-17 04:03:50 -05:00
|
|
|
/**
|
|
|
|
Set the full key name. The name is absolute. It should start with
|
|
|
|
HKEY_xxx.
|
|
|
|
*/
|
|
|
|
void SetName(const wxString& strKey);
|
|
|
|
/**
|
|
|
|
Set the name relative to the parent key
|
|
|
|
*/
|
|
|
|
void SetName(StdKey keyParent, const wxString& strKey);
|
|
|
|
/**
|
|
|
|
Set the name relative to the parent key
|
|
|
|
*/
|
|
|
|
void SetName(const wxRegKey& keyParent, const wxString& strKey);
|
2009-02-20 06:34:52 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2009-01-21 13:04:37 -05:00
|
|
|
Sets the given @a szValue which must be numeric. If the value doesn't
|
|
|
|
exist, it is created. Returns @true if successful.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-11-22 05:41:52 -05:00
|
|
|
bool SetValue(const wxString& szValue, long lValue);
|
2008-06-20 22:38:44 -04:00
|
|
|
/**
|
2009-01-21 13:04:37 -05:00
|
|
|
Sets the given @a szValue which must be string. If the value doesn't
|
|
|
|
exist, it is created. Returns @true if successful.
|
2008-06-20 22:38:44 -04:00
|
|
|
*/
|
2008-11-22 05:41:52 -05:00
|
|
|
bool SetValue(const wxString& szValue, const wxString& strValue);
|
2008-06-20 22:38:44 -04:00
|
|
|
/**
|
2009-02-20 06:34:52 -05:00
|
|
|
Sets the given @a szValue which must be binary. If the value doesn't
|
2009-01-21 13:04:37 -05:00
|
|
|
exist, it is created. Returns @true if successful.
|
2008-06-20 22:38:44 -04:00
|
|
|
*/
|
2008-11-22 05:41:52 -05:00
|
|
|
bool SetValue(const wxString& szValue, const wxMemoryBuffer& buf);
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|