Improve wxRegKey documentation

Expand the class description.

Fix and improve the code example.

Closes https://github.com/wxWidgets/wxWidgets/pull/1693
This commit is contained in:
PB
2020-01-04 20:32:46 +01:00
committed by Vadim Zeitlin
parent 53df59a14a
commit 1b93041d6e

View File

@@ -9,11 +9,12 @@
@class wxRegKey @class wxRegKey
wxRegKey is a class representing the Windows registry (it is only available wxRegKey is a class representing the Windows registry (it is only available
under Windows). One can create, query and delete registry keys using this under Windows) which can be used to create, query, set and delete registry keys.
class.
The Windows registry is easy to understand. There are five registry keys, The Windows registry contains data stored by Windows and the applications.
namely: The data are stored in a tree structure, where a tree node is called a key.
Each key can contain subkeys as well as values. There are several predefined keys
that are used as main entry points to the registry, the most commonly used being:
@li @c HKEY_CLASSES_ROOT (HKCR) @li @c HKEY_CLASSES_ROOT (HKCR)
@li @c HKEY_CURRENT_USER (HKCU) @li @c HKEY_CURRENT_USER (HKCU)
@@ -21,7 +22,7 @@
@li @c HKEY_CURRENT_CONFIG (HKCC) @li @c HKEY_CURRENT_CONFIG (HKCC)
@li @c HKEY_USERS (HKU) @li @c HKEY_USERS (HKU)
After creating a key, it can hold a value. The values can be: The values can be in these formats:
@li String Value @li String Value
@li Binary Value @li Binary Value
@@ -34,9 +35,9 @@
@b Example: @b Example:
@code @code
// This assume that the key already exists, use HasSubKey() to check // This assumes that the key already exists, use HasSubKey() to check
// for the key existence if necessary. // for the key existence if necessary.
wxRegKey key(wxRegKey::HKLM, "Software\\MyKey"); wxRegKey key(wxRegKey::HKCU, "Software\\MyKey");
// Create a new value "MyValue" and set it to 12. // Create a new value "MyValue" and set it to 12.
key.SetValue("MyValue", 12); key.SetValue("MyValue", 12);
@@ -44,18 +45,17 @@
// Read the value back. // Read the value back.
long value; long value;
key.QueryValue("MyValue", &value); key.QueryValue("MyValue", &value);
wxMessageBox(wxString::Format("%d", value), "Registry Value", wxOK); wxLogMessage("Registry value: %ld", value);
// Get the number of subkeys and enumerate them. // Enumerate the subkeys.
size_t subkeys; wxString keyName;
key.GetKeyInfo(&subkeys, NULL, NULL, NULL); long index = 0;
wxString key_name; for ( bool cont = key.GetFirstKey(keyName, index);
key.GetFirstKey(key_name, 1); cont;
for(int i = 0; i < subkeys; i++) cont = key.GetNextKey(keyName, index) )
{ {
wxMessageBox(key_name, "Subkey Name", wxOK); wxLogMessage("Subkey name: %s", keyName);
key.GetNextKey(key_name, 1);
} }
@endcode @endcode