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.
The Windows registry is easy to understand. There are five registry keys, namely:
After creating a key, it can hold a value. The values can be:
Derived from
None
Include files
<wx/msw/registry.h>
Example
wxRegKey *pRegKey = new wxRegKey("HKEY_LOCAL_MACHINE\\Software\\MyKey"); //will create the Key if it does not exist if( !pRegKey->Exists() ) pRegKey->Create(); //will create a new value MYVALUE and set it to 12 pRegKey->SetValue("MYVALUE",12); //Query for the Value and Retrieve it long lMyVal; wxString strTemp; pRegKey->QueryValue("MYVALUE",&lMyVal); strTemp.Printf("%d",lMyVal); wxMessageBox(strTemp,"Registry Value",0,this); //Retrive the number of SubKeys and enumerate them size_t nSubKeys; pRegKey->GetKeyInfo(&nSubKeys,NULL,NULL,NULL); pRegKey->GetFirstKey(strTemp,1); for(int i=0;i<nSubKeys;i++) { wxMessageBox(strTemp,"SubKey Name",0,this); pRegKey->GetNextKey(strTemp,1); }Members
wxRegKey::wxRegKey
wxRegKey::Close
wxRegKey::Create
wxRegKey::DeleteSelf
wxRegKey::DeleteKey
wxRegKey::DeleteValue
wxRegKey::Exists
wxRegKey::GetName
wxRegKey::GetFirstKey
wxRegKey::GetFirstValue
wxRegKey::GetKeyInfo
wxRegKey::GetNextKey
wxRegKey::GetNextValue
wxRegKey::HasValue
wxRegKey::HasValues
wxRegKey::HasSubKey
wxRegKey::HasSubKeys
wxRegKey::IsEmpty
wxRegKey::IsOpened
wxRegKey::Open
wxRegKey::QueryValue
wxRegKey::Rename
wxRegKey::RenameValue
wxRegKey::SetValue
wxRegKey()
The Constructor to set to HKCR
wxRegKey(const wxString& strKey)
The constructor to set the full name of the key.
wxRegKey(const wxRegKey& keyParent, const wxString& strKey)
The constructor to set the full name of the key under a previously created parent.
void Close()
Closes the key.
bool Create(bool bOkIfExists = true)
Creates the key. Will fail if the key already exists and bOkIfExists is false.
void DeleteSelf()
Deletes this key and all of its subkeys and values recursively.
void DeleteKey(const wxChar *szKey)
Deletes the subkey with all of its subkeys/values recursively.
void DeleteValue(const wxChar *szKey)
Deletes the named value.
static bool Exists() const
Returns true if the key exists.
wxString GetName(bool bShortPrefix = true) const
Gets the name of the registry key.
bool GetKeyValue(wxString& strKeyName, long& lIndex)
Gets the first key.
bool GetFirstValue(wxString& strValueName, long& lIndex)
Gets the first value of this key.
bool Exists(size_t *pnSubKeys, size_t *pnValues, size_t *pnMaxValueLen) const
Gets information about the key.
Parameters
pnSubKeys
pnMaxKeyLen
pnValues
bool GetNextKey(wxString& strKeyName, long& lIndex) const
Gets the next key.
bool GetNextValue(wxString& strValueName, long& lIndex) const
Gets the next key value for this key.
bool HasValue(const wxChar *szValue) const
Returns true if the value exists.
bool HasValues() const
Returns true if any values exist.
bool HasSubKey(const wxChar *szKey) const
Returns true if given subkey exists.
bool HasSubKeys() const
Returns true if any subkeys exist.
bool IsEmpty() const
Returns true if this key is empty, nothing under this key.
bool IsOpened() const
Returns true if the key is opened.
bool 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.
bool QueryValue(const wxChar *szValue, wxString& strValue) const
Retrieves the string value.
bool QueryValue(const wxChar *szValue, long *plValue) const
Retrieves the numeric value.
bool Rename(const wxChar * szNewName)
Renames the key.
bool RenameValue(const wxChar *szValueOld, const wxChar *szValueNew)
Renames a value.
bool SetValue(const wxChar *szValue, long lValue)
Sets the numeric value.