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-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
2008-06-20 22:38:44 -04:00
|
|
|
@category{misc}
|
|
|
|
|
|
|
|
@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
|
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-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
|
|
|
|
{
|
|
|
|
Read, ///< Read-only
|
|
|
|
Write ///< Read and Write
|
|
|
|
};
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Closes the key.
|
|
|
|
*/
|
|
|
|
void Close();
|
|
|
|
|
|
|
|
/**
|
2008-03-09 08:33:59 -04:00
|
|
|
Creates the key. Will fail if the key already exists and @a bOkIfExists is
|
2008-03-08 08:52:38 -05:00
|
|
|
@false.
|
|
|
|
*/
|
2008-03-09 08:33:59 -04:00
|
|
|
bool Create(bool bOkIfExists = true);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Deletes the subkey with all of its subkeys/values recursively.
|
|
|
|
*/
|
2008-03-09 08:33:59 -04:00
|
|
|
void DeleteKey(const wxChar* szKey);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Deletes this key and all of its subkeys and values recursively.
|
|
|
|
*/
|
|
|
|
void DeleteSelf();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Deletes the named value.
|
|
|
|
*/
|
2008-03-09 08:33:59 -04:00
|
|
|
void DeleteValue(const wxChar* 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
|
|
|
|
|
|
|
/**
|
|
|
|
Gets the first key.
|
|
|
|
*/
|
|
|
|
bool GetFirstKey(wxString& strKeyName, long& lIndex);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Gets the first value of this key.
|
|
|
|
*/
|
|
|
|
bool GetFirstValue(wxString& strValueName, long& lIndex);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Gets information about the key.
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
Gets the next key.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool GetNextKey(wxString& strKeyName, long& lIndex) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Gets the next key value for this key.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool GetNextValue(wxString& strValueName, long& lIndex) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if given subkey exists.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool HasSubKey(const wxChar* 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-03-09 12:24:26 -04:00
|
|
|
bool HasValue(const wxChar* 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
|
|
|
|
|
|
|
/**
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
Explicitly opens the key. This method also allows the key to be opened in
|
2008-06-20 22:38:44 -04:00
|
|
|
read-only mode by passing wxRegKey::Read instead of default
|
|
|
|
wxRegKey::Write parameter.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
bool Open(AccessMode mode = Write);
|
|
|
|
|
|
|
|
/**
|
2008-06-20 22:38:44 -04:00
|
|
|
Retrieves the string value.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool QueryValue(const wxChar* szValue, wxString& strValue) const;
|
2008-06-20 22:38:44 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Retrieves the numeric value.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
const bool QueryValue(const wxChar* szValue, long* plValue) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Renames the key.
|
|
|
|
*/
|
2008-03-09 08:33:59 -04:00
|
|
|
bool Rename(const wxChar* szNewName);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Renames a value.
|
|
|
|
*/
|
2008-03-09 08:33:59 -04:00
|
|
|
bool RenameValue(const wxChar* szValueOld,
|
|
|
|
const wxChar* szValueNew);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-06-20 22:38:44 -04:00
|
|
|
Sets the given @a szValue which must be numeric.
|
|
|
|
If the value doesn't exist, it is created.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 08:33:59 -04:00
|
|
|
bool SetValue(const wxChar* szValue, long lValue);
|
2008-06-20 22:38:44 -04:00
|
|
|
/**
|
|
|
|
Sets the given @a szValue which must be string.
|
|
|
|
If the value doesn't exist, it is created.
|
|
|
|
*/
|
|
|
|
bool SetValue(const wxChar* szValue, const wxString& strValue);
|
|
|
|
/**
|
|
|
|
Sets the given @a szValue which must be binary.
|
|
|
|
If the value doesn't exist, it is created.
|
|
|
|
*/
|
|
|
|
bool SetValue(const wxChar* szValue, const wxMemoryBuffer& buf);
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|