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:
@@ -9,11 +9,12 @@
|
||||
@class wxRegKey
|
||||
|
||||
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.
|
||||
under Windows) which can be used to create, query, set and delete registry keys.
|
||||
|
||||
The Windows registry is easy to understand. There are five registry keys,
|
||||
namely:
|
||||
The Windows registry contains data stored by Windows and the applications.
|
||||
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_CURRENT_USER (HKCU)
|
||||
@@ -21,7 +22,7 @@
|
||||
@li @c HKEY_CURRENT_CONFIG (HKCC)
|
||||
@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 Binary Value
|
||||
@@ -34,9 +35,9 @@
|
||||
@b Example:
|
||||
|
||||
@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.
|
||||
wxRegKey key(wxRegKey::HKLM, "Software\\MyKey");
|
||||
wxRegKey key(wxRegKey::HKCU, "Software\\MyKey");
|
||||
|
||||
// Create a new value "MyValue" and set it to 12.
|
||||
key.SetValue("MyValue", 12);
|
||||
@@ -44,18 +45,17 @@
|
||||
// Read the value back.
|
||||
long 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.
|
||||
size_t subkeys;
|
||||
key.GetKeyInfo(&subkeys, NULL, NULL, NULL);
|
||||
// Enumerate the subkeys.
|
||||
wxString keyName;
|
||||
long index = 0;
|
||||
|
||||
wxString key_name;
|
||||
key.GetFirstKey(key_name, 1);
|
||||
for(int i = 0; i < subkeys; i++)
|
||||
for ( bool cont = key.GetFirstKey(keyName, index);
|
||||
cont;
|
||||
cont = key.GetNextKey(keyName, index) )
|
||||
{
|
||||
wxMessageBox(key_name, "Subkey Name", wxOK);
|
||||
key.GetNextKey(key_name, 1);
|
||||
wxLogMessage("Subkey name: %s", keyName);
|
||||
}
|
||||
@endcode
|
||||
|
||||
|
Reference in New Issue
Block a user