#include <wx/msw/registry.h>
The Windows registry is easy to understand. There are five registry keys, namely:
HKEY_CLASSES_ROOT (HKCR) HKEY_CURRENT_USER (HKCU) HKEY_LOCAL_MACHINE (HKLM) HKEY_CURRENT_CONFIG (HKCC) HKEY_USERS (HKU)
Example:
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); }
Public Types | |
| enum | AccessMode { Read, Write } |
Public Member Functions | |
| wxRegKey () | |
| wxRegKey (const wxString &strKey) | |
| wxRegKey (const wxRegKey &keyParent, const wxString &strKey) | |
| void | Close () |
| bool | Create (bool bOkIfExists=true) |
| void | DeleteKey (const wxString &szKey) |
| void | DeleteSelf () |
| void | DeleteValue (const wxString &szKey) |
| bool | Exists () const |
| bool | GetFirstKey (wxString &strKeyName, long &lIndex) |
| bool | GetFirstValue (wxString &strValueName, long &lIndex) |
| bool | GetKeyInfo (size_t *pnSubKeys, size_t *pnMaxKeyLen, size_t *pnValues, size_t *pnMaxValueLen) const |
| wxString | GetName (bool bShortPrefix=true) const |
| bool | GetNextKey (wxString &strKeyName, long &lIndex) const |
| bool | GetNextValue (wxString &strValueName, long &lIndex) const |
| bool | HasSubKey (const wxString &szKey) const |
| bool | HasSubKeys () const |
| bool | HasValue (const wxString &szValue) const |
| bool | HasValues () const |
| bool | IsEmpty () const |
| bool | IsOpened () const |
| bool | Open (AccessMode mode=Write) |
| bool | QueryValue (const wxString &szValue, wxString &strValue) const |
| const bool | QueryValue (const wxString &szValue, long *plValue) const |
| bool | Rename (const wxString &szNewName) |
| bool | RenameValue (const wxString &szValueOld, const wxString &szValueNew) |
| bool | SetValue (const wxString &szValue, long lValue) |
| bool | SetValue (const wxString &szValue, const wxString &strValue) |
| bool | SetValue (const wxString &szValue, const wxMemoryBuffer &buf) |
| enum wxRegKey::AccessMode |
Access modes for wxRegKey.
| wxRegKey::wxRegKey | ( | ) |
Default constructor, initializes to HKEY_CLASSES_ROOT.
| wxRegKey::wxRegKey | ( | const wxString & | strKey | ) |
The constructor to set the full name of the key.
The constructor to set the full name of the key under a previously created parent.
| void wxRegKey::Close | ( | ) |
Closes the key.
| bool wxRegKey::Create | ( | bool | bOkIfExists = true |
) |
Creates the key. Will fail if the key already exists and bOkIfExists is false.
| void wxRegKey::DeleteKey | ( | const wxString & | szKey | ) |
Deletes the subkey with all of its subkeys/values recursively.
| void wxRegKey::DeleteSelf | ( | ) |
Deletes this key and all of its subkeys and values recursively.
| void wxRegKey::DeleteValue | ( | const wxString & | szKey | ) |
Deletes the named value.
| bool wxRegKey::Exists | ( | ) | const |
Returns true if the key exists.
| bool wxRegKey::GetFirstKey | ( | wxString & | strKeyName, | |
| long & | lIndex | |||
| ) |
Gets the first key.
| bool wxRegKey::GetFirstValue | ( | wxString & | strValueName, | |
| long & | lIndex | |||
| ) |
Gets the first value of this key.
| bool wxRegKey::GetKeyInfo | ( | size_t * | pnSubKeys, | |
| size_t * | pnMaxKeyLen, | |||
| size_t * | pnValues, | |||
| size_t * | pnMaxValueLen | |||
| ) | const |
Gets information about the key.
| pnSubKeys | The number of subkeys. | |
| pnMaxKeyLen | The maximum length of the subkey name. | |
| pnValues | The number of values. | |
| pnMaxValueLen | The maximum length of a value. |
| wxString wxRegKey::GetName | ( | bool | bShortPrefix = true |
) | const |
Gets the name of the registry key.
| bool wxRegKey::GetNextKey | ( | wxString & | strKeyName, | |
| long & | lIndex | |||
| ) | const |
Gets the next key.
| bool wxRegKey::GetNextValue | ( | wxString & | strValueName, | |
| long & | lIndex | |||
| ) | const |
Gets the next key value for this key.
| bool wxRegKey::HasSubKey | ( | const wxString & | szKey | ) | const |
Returns true if given subkey exists.
| bool wxRegKey::HasSubKeys | ( | ) | const |
Returns true if any subkeys exist.
| bool wxRegKey::HasValue | ( | const wxString & | szValue | ) | const |
Returns true if the value exists.
| bool wxRegKey::HasValues | ( | ) | const |
Returns true if any values exist.
| bool wxRegKey::IsEmpty | ( | ) | const |
Returns true if this key is empty, nothing under this key.
| bool wxRegKey::IsOpened | ( | ) | const |
Returns true if the key is opened.
| bool wxRegKey::Open | ( | AccessMode | mode = Write |
) |
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.
Retrieves the string value.
| const bool wxRegKey::QueryValue | ( | const wxString & | szValue, | |
| long * | plValue | |||
| ) | const |
Retrieves the numeric value.
| bool wxRegKey::Rename | ( | const wxString & | szNewName | ) |
Renames the key.
Renames a value.
| bool wxRegKey::SetValue | ( | const wxString & | szValue, | |
| long | lValue | |||
| ) |
Sets the given szValue which must be numeric. If the value doesn't exist, it is created.
Sets the given szValue which must be string. If the value doesn't exist, it is created.
| bool wxRegKey::SetValue | ( | const wxString & | szValue, | |
| const wxMemoryBuffer & | buf | |||
| ) |
Sets the given szValue which must be binary. If the value doesn't exist, it is created.
|
[ top ] |