Contents Up Previous Next

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.

The Windows registry is easy to understand. There are five registry keys, namely:

  1. HKEY_CLASSES_ROOT (HKCR)
  2. HKEY_CURRENT_USER (HKCU)
  3. HKEY_LOCAL_MACHINE (HKLM)
  4. HKEY_CURRENT_CONFIG (HKCC)
  5. HKEY_USERS (HKU)

After creating a key, it can hold a value. The values can be:

  1. String Value
  2. Binary Value
  3. DWORD Value
  4. Multi String Value
  5. Expandable String Value

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::wxRegKey

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.


wxRegKey::Close

void Close()

Closes the key.


wxRegKey::Create

bool Create(bool bOkIfExists = true)

Creates the key. Will fail if the key already exists and bOkIfExists is false.


wxRegKey::DeleteSelf

void DeleteSelf()

Deletes this key and all of its subkeys and values recursively.


wxRegKey::DeleteKey

void DeleteKey(const wxChar *szKey)

Deletes the subkey with all of its subkeys/values recursively.


wxRegKey::DeleteValue

void DeleteValue(const wxChar *szKey)

Deletes the named value.


wxRegKey::Exists

static bool Exists() const

Returns true if the key exists.


wxRegKey::GetName

wxString GetName(bool bShortPrefix = true) const

Gets the name of the registry key.


wxRegKey::GetFirstKey

bool GetKeyValue(wxString& strKeyName, long& lIndex)

Gets the first key.


wxRegKey::GetFirstValue

bool GetFirstValue(wxString& strValueName, long& lIndex)

Gets the first value of this key.


wxRegKey::GetKeyInfo

bool Exists(size_t *pnSubKeys, size_t *pnValues, size_t *pnMaxValueLen) const

Gets information about the key.

Parameters

pnSubKeys

pnMaxKeyLen

pnValues


wxRegKey::GetNextKey

bool GetNextKey(wxString& strKeyName, long& lIndex) const

Gets the next key.


wxRegKey::GetNextValue

bool GetNextValue(wxString& strValueName, long& lIndex) const

Gets the next key value for this key.


wxRegKey::HasValue

bool HasValue(const wxChar *szValue) const

Returns true if the value exists.


wxRegKey::HasValues

bool HasValues() const

Returns true if any values exist.


wxRegKey::HasSubKey

bool HasSubKey(const wxChar *szKey) const

Returns true if given subkey exists.


wxRegKey::HasSubKeys

bool HasSubKeys() const

Returns true if any subkeys exist.


wxRegKey::IsEmpty

bool IsEmpty() const

Returns true if this key is empty, nothing under this key.


wxRegKey::IsOpened

bool IsOpened() const

Returns true if the key is opened.


wxRegKey::Open

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.


wxRegKey::QueryValue

bool QueryValue(const wxChar *szValue, wxString& strValue) const

Retrieves the string value.

bool QueryValue(const wxChar *szValue, long *plValue) const

Retrieves the numeric value.


wxRegKey::Rename

bool Rename(const wxChar * szNewName)

Renames the key.


wxRegKey::RenameValue

bool RenameValue(const wxChar *szValueOld, const wxChar *szValueNew)

Renames a value.


wxRegKey::SetValue

bool SetValue(const wxChar *szValue, long lValue)

Sets the numeric value.