wxRegKey Class Reference
[Miscellaneous]

#include <wx/msw/registry.h>

List of all members.


Detailed Description

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:

Availability:  only available for the wxMSW port.

Library:  wxBase

Category:  Miscellaneous

Example:

    wxRegKey *key = new wxRegKey("HKEY_LOCAL_MACHINE\\Software\\MyKey");

    // Create the key if it does not exist.
    if( !key->Exists() )
        key->Create();

    // Create a new value "MYVALUE" and set it to 12.
    key->SetValue("MYVALUE", 12);

    // Read the value back.
    long value;
    key->QueryValue("MYVALUE", &value);
    wxMessageBox(wxString::Format("%d", value), "Registry Value", wxOK);

    // Get the number of subkeys and enumerate them.
    size_t subkeys;
    key->GetKeyInfo(&subkeys, NULL, NULL, NULL);

    wxString key_name;
    key->GetFirstKey(key_name, 1);
    for(int i = 0; i < subkeys; i++)
    {
        wxMessageBox(key_name, "Subkey Name", wxOK);
        key->GetNextKey(key_name, 1);
    }

Public Types

enum  AccessMode {
  Read,
  Write
}

Public Member Functions

 wxRegKey ()
 wxRegKey (const wxString &strKey)
 wxRegKey (const wxRegKey &keyParent, const wxString &strKey)
void Close ()
bool Create (bool bOkIfExists=true)
void DeleteKey (const wxString &szKey)
void DeleteSelf ()
void DeleteValue (const wxString &szKey)
bool Exists () const
bool GetFirstKey (wxString &strKeyName, long &lIndex)
bool GetFirstValue (wxString &strValueName, long &lIndex)
bool GetKeyInfo (size_t *pnSubKeys, size_t *pnMaxKeyLen, size_t *pnValues, size_t *pnMaxValueLen) const
wxString GetName (bool bShortPrefix=true) const
bool GetNextKey (wxString &strKeyName, long &lIndex) const
bool GetNextValue (wxString &strValueName, long &lIndex) const
bool HasSubKey (const wxString &szKey) const
bool HasSubKeys () const
bool HasValue (const wxString &szValue) const
bool HasValues () const
bool IsEmpty () const
bool IsOpened () const
bool Open (AccessMode mode=Write)
bool QueryValue (const wxString &szValue, wxString &strValue) const
const bool QueryValue (const wxString &szValue, long *plValue) const
bool Rename (const wxString &szNewName)
bool RenameValue (const wxString &szValueOld, const wxString &szValueNew)
bool SetValue (const wxString &szValue, long lValue)
bool SetValue (const wxString &szValue, const wxString &strValue)
bool SetValue (const wxString &szValue, const wxMemoryBuffer &buf)

Member Enumeration Documentation

Access modes for wxRegKey.

Enumerator:
Read  Read-only.
Write  Read and Write.


Constructor & Destructor Documentation

wxRegKey::wxRegKey (  ) 

Default constructor, initializes to HKEY_CLASSES_ROOT.

wxRegKey::wxRegKey ( const wxString strKey  ) 

The constructor to set the full name of the key.

wxRegKey::wxRegKey ( const wxRegKey keyParent,
const wxString strKey 
)

The constructor to set the full name of the key under a previously created parent.


Member Function Documentation

void wxRegKey::Close (  ) 

Closes the key.

bool wxRegKey::Create ( bool  bOkIfExists = true  ) 

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

void wxRegKey::DeleteKey ( const wxString szKey  ) 

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

void wxRegKey::DeleteSelf (  ) 

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

void wxRegKey::DeleteValue ( const wxString szKey  ) 

Deletes the named value.

bool wxRegKey::Exists (  )  const

Returns true if the key exists.

bool wxRegKey::GetFirstKey ( wxString strKeyName,
long &  lIndex 
)

Gets the first key.

bool wxRegKey::GetFirstValue ( wxString strValueName,
long &  lIndex 
)

Gets the first value of this key.

bool wxRegKey::GetKeyInfo ( size_t *  pnSubKeys,
size_t *  pnMaxKeyLen,
size_t *  pnValues,
size_t *  pnMaxValueLen 
) const

Gets information about the key.

Parameters:
pnSubKeys The number of subkeys.
pnMaxKeyLen The maximum length of the subkey name.
pnValues The number of values.
pnMaxValueLen The maximum length of a value.

wxString wxRegKey::GetName ( bool  bShortPrefix = true  )  const

Gets the name of the registry key.

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

Gets the next key.

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

Gets the next key value for this key.

bool wxRegKey::HasSubKey ( const wxString szKey  )  const

Returns true if given subkey exists.

bool wxRegKey::HasSubKeys (  )  const

Returns true if any subkeys exist.

bool wxRegKey::HasValue ( const wxString szValue  )  const

Returns true if the value exists.

bool wxRegKey::HasValues (  )  const

Returns true if any values exist.

bool wxRegKey::IsEmpty (  )  const

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

bool wxRegKey::IsOpened (  )  const

Returns true if the key is opened.

bool wxRegKey::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 wxRegKey::QueryValue ( const wxString szValue,
wxString strValue 
) const

Retrieves the string value.

const bool wxRegKey::QueryValue ( const wxString szValue,
long *  plValue 
) const

Retrieves the numeric value.

bool wxRegKey::Rename ( const wxString szNewName  ) 

Renames the key.

bool wxRegKey::RenameValue ( const wxString szValueOld,
const wxString szValueNew 
)

Renames a value.

bool wxRegKey::SetValue ( const wxString szValue,
long  lValue 
)

Sets the given szValue which must be numeric. If the value doesn't exist, it is created.

bool wxRegKey::SetValue ( const wxString szValue,
const wxString strValue 
)

Sets the given szValue which must be string. If the value doesn't exist, it is created.

bool wxRegKey::SetValue ( const wxString szValue,
const wxMemoryBuffer buf 
)

Sets the given szValue which must be binary. If the value doesn't exist, it is created.



wxWidgets logo

[ top ]