wxRegKeywxRegKey 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::wxRegKeywxRegKey() 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.
wxRegKey::Closevoid Close() Closes the key.
wxRegKey::Createbool Create(bool bOkIfExists = true) Creates the key. Will fail if the key already exists and bOkIfExists is false.
wxRegKey::DeleteSelfvoid DeleteSelf() Deletes this key and all of its subkeys and values recursively.
wxRegKey::DeleteKeyvoid DeleteKey(const wxChar *szKey) Deletes the subkey with all of its subkeys/values recursively.
wxRegKey::DeleteValuevoid DeleteValue(const wxChar *szKey) Deletes the named value.
wxRegKey::Existsstatic bool Exists() const Returns true if the key exists.
wxRegKey::GetNamewxString GetName(bool bShortPrefix = true) const Gets the name of the registry key.
wxRegKey::GetFirstKeybool GetFirstKey(wxString& strKeyName, long& lIndex) Gets the first key.
wxRegKey::GetFirstValuebool GetFirstValue(wxString& strValueName, long& lIndex) Gets the first value of this key.
wxRegKey::GetKeyInfobool Exists(size_t *pnSubKeys, size_t *pnValues, size_t *pnMaxValueLen) const Gets information about the key. Parameters pnSubKeys
pnMaxKeyLen
pnValues
wxRegKey::GetNextKeybool GetNextKey(wxString& strKeyName, long& lIndex) const Gets the next key.
wxRegKey::GetNextValuebool GetNextValue(wxString& strValueName, long& lIndex) const Gets the next key value for this key.
wxRegKey::HasValuebool HasValue(const wxChar *szValue) const Returns true if the value exists.
wxRegKey::HasValuesbool HasValues() const Returns true if any values exist.
wxRegKey::HasSubKeybool HasSubKey(const wxChar *szKey) const Returns true if given subkey exists.
wxRegKey::HasSubKeysbool HasSubKeys() const Returns true if any subkeys exist.
wxRegKey::IsEmptybool IsEmpty() const Returns true if this key is empty, nothing under this key.
wxRegKey::IsOpenedbool IsOpened() const Returns true if the key is opened.
wxRegKey::Openbool 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.
wxRegKey::QueryValuebool QueryValue(const wxChar *szValue, wxString& strValue) const Retrieves the string value. bool QueryValue(const wxChar *szValue, long *plValue) const Retrieves the numeric value.
wxRegKey::Renamebool Rename(const wxChar * szNewName) Renames the key.
wxRegKey::RenameValuebool RenameValue(const wxChar *szValueOld, const wxChar *szValueNew) Renames a value.
wxRegKey::SetValuebool SetValue(const wxChar *szValue, long lValue) bool SetValue(const wxChar *szValue, const wxString& strValue) bool SetValue(const wxChar *szValue, const wxMemoryBuffer& buf) Sets the given szValue which must be numeric, string or binary depending on the overload used. If the value doesn't exist, it is created.
|