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 getfirstkey(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)

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.