1998-05-20 10:12:05 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: msw/registry.h
|
|
|
|
// Purpose: Registry classes and functions
|
|
|
|
// Author: Vadim Zeitlin
|
2000-02-14 19:05:36 -05:00
|
|
|
// Modified by:
|
1998-05-20 10:12:05 -04:00
|
|
|
// Created: 03.04.198
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
|
1998-08-07 19:52:45 -04:00
|
|
|
// Licence: wxWindows licence
|
1998-05-20 10:12:05 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _REGISTRY_H
|
|
|
|
#define _REGISTRY_H
|
|
|
|
|
1998-07-03 12:36:10 -04:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface "registry.h"
|
|
|
|
#endif
|
|
|
|
|
1998-05-20 10:12:05 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
1998-08-02 19:04:55 -04:00
|
|
|
// types used in this module
|
1998-05-20 10:12:05 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
1998-08-24 15:13:34 -04:00
|
|
|
|
|
|
|
/*
|
1998-05-20 10:12:05 -04:00
|
|
|
#ifndef HKEY_DEFINED
|
|
|
|
#define HKEY_DEFINED
|
|
|
|
#define HKEY unsigned long
|
|
|
|
#endif
|
1998-08-24 15:13:34 -04:00
|
|
|
*/
|
1998-05-20 10:12:05 -04:00
|
|
|
|
1998-08-02 19:04:55 -04:00
|
|
|
typedef unsigned long ulong;
|
|
|
|
|
1998-05-20 10:12:05 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// class wxRegKey encapsulates window HKEY handle
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
class WXDLLEXPORT wxRegKey
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// NB: do _not_ change the values of elements in these enumerations!
|
|
|
|
|
|
|
|
// registry value types (with comments from winnt.h)
|
|
|
|
enum ValueType
|
|
|
|
{
|
|
|
|
Type_None, // No value type
|
|
|
|
Type_String, // Unicode nul terminated string
|
|
|
|
#ifdef __WIN32__
|
|
|
|
Type_Expand_String, // Unicode nul terminated string
|
|
|
|
// (with environment variable references)
|
|
|
|
Type_Binary, // Free form binary
|
|
|
|
Type_Dword, // 32-bit number
|
2000-02-14 19:05:36 -05:00
|
|
|
Type_Dword_little_endian // 32-bit number
|
|
|
|
= Type_Dword, // (same as Type_DWORD)
|
1998-05-20 10:12:05 -04:00
|
|
|
Type_Dword_big_endian, // 32-bit number
|
|
|
|
Type_Link, // Symbolic Link (unicode)
|
|
|
|
Type_Multi_String, // Multiple Unicode strings
|
|
|
|
Type_Resource_list, // Resource list in the resource map
|
|
|
|
Type_Full_resource_descriptor, // Resource list in the hardware description
|
1999-01-15 19:13:58 -05:00
|
|
|
Type_Resource_requirements_list // ???
|
1998-05-20 10:12:05 -04:00
|
|
|
#endif //WIN32
|
|
|
|
};
|
|
|
|
|
|
|
|
// predefined registry keys
|
|
|
|
enum StdKey
|
|
|
|
{
|
2000-02-14 19:05:36 -05:00
|
|
|
HKCR // classes root
|
1998-05-20 10:12:05 -04:00
|
|
|
#ifdef __WIN32__
|
2000-02-14 19:05:36 -05:00
|
|
|
,
|
|
|
|
HKCU, // current user
|
|
|
|
HKLM, // local machine
|
|
|
|
HKUSR, // users
|
|
|
|
HKPD // performance data (WinNT/2K only)
|
|
|
|
#if WINVER >= 0x0400
|
|
|
|
,
|
|
|
|
HKCC, // current config (starting from Win95/NT 4.0)
|
|
|
|
HKDD // dynamic data (Win95/98 only)
|
1998-05-20 10:12:05 -04:00
|
|
|
#endif // Winver
|
|
|
|
#endif // Win32/16
|
|
|
|
};
|
|
|
|
|
|
|
|
// information about standard (predefined) registry keys
|
|
|
|
// number of standard keys
|
|
|
|
static const size_t nStdKeys;
|
|
|
|
// get the name of a standard key
|
1999-04-21 17:46:02 -04:00
|
|
|
static const wxChar *GetStdKeyName(size_t key);
|
1998-05-20 10:12:05 -04:00
|
|
|
// get the short name of a standard key
|
1999-04-21 17:46:02 -04:00
|
|
|
static const wxChar *GetStdKeyShortName(size_t key);
|
1998-05-20 10:12:05 -04:00
|
|
|
// get StdKey from root HKEY
|
1998-08-24 15:13:34 -04:00
|
|
|
static StdKey GetStdKeyFromHkey(WXHKEY hkey);
|
1998-05-20 10:12:05 -04:00
|
|
|
|
|
|
|
// extacts the std key prefix from the string (return value) and
|
|
|
|
// leaves only the part after it (i.e. modifies the string passed!)
|
|
|
|
static StdKey ExtractKeyName(wxString& str);
|
|
|
|
|
|
|
|
// ctors
|
|
|
|
// root key is set to HKCR (the only root key under Win16)
|
|
|
|
wxRegKey();
|
|
|
|
// strKey is the full name of the key (i.e. starting with HKEY_xxx...)
|
|
|
|
wxRegKey(const wxString& strKey);
|
|
|
|
// strKey is the name of key under (standard key) keyParent
|
1998-05-27 19:18:16 -04:00
|
|
|
wxRegKey(StdKey keyParent, const wxString& strKey);
|
1998-05-20 10:12:05 -04:00
|
|
|
// strKey is the name of key under (previously created) keyParent
|
|
|
|
wxRegKey(const wxRegKey& keyParent, const wxString& strKey);
|
|
|
|
//
|
|
|
|
~wxRegKey();
|
|
|
|
|
|
|
|
// change key (closes the previously opened key if any)
|
1998-05-27 19:18:16 -04:00
|
|
|
// the name is absolute, i.e. should start with HKEY_xxx
|
1998-05-20 10:12:05 -04:00
|
|
|
void SetName(const wxString& strKey);
|
1998-05-27 19:18:16 -04:00
|
|
|
// the name is relative to the parent key
|
|
|
|
void SetName(StdKey keyParent, const wxString& strKey);
|
|
|
|
// the name is relative to the parent key
|
|
|
|
void SetName(const wxRegKey& keyParent, const wxString& strKey);
|
|
|
|
// hKey should be opened and will be closed in wxRegKey dtor
|
1998-08-24 15:13:34 -04:00
|
|
|
void SetHkey(WXHKEY hKey);
|
1998-05-20 10:12:05 -04:00
|
|
|
|
|
|
|
// get infomation about the key
|
|
|
|
// get the (full) key name. Abbreviate std root keys if bShortPrefix.
|
1998-07-01 13:26:46 -04:00
|
|
|
wxString GetName(bool bShortPrefix = TRUE) const;
|
1998-05-27 19:18:16 -04:00
|
|
|
// return true if the key exists
|
1998-08-02 19:04:55 -04:00
|
|
|
bool Exists() const;
|
|
|
|
// get the info about key (any number of these pointers may be NULL)
|
1998-08-18 16:15:51 -04:00
|
|
|
bool GetKeyInfo(size_t *pnSubKeys, // number of subkeys
|
|
|
|
size_t *pnMaxKeyLen, // max len of subkey name
|
|
|
|
size_t *pnValues, // number of values
|
|
|
|
size_t *pnMaxValueLen) const;
|
1998-05-27 19:18:16 -04:00
|
|
|
// return true if the key is opened
|
1998-08-02 19:04:55 -04:00
|
|
|
bool IsOpened() const { return m_hKey != 0; }
|
1998-05-20 10:12:05 -04:00
|
|
|
// for "if ( !key ) wxLogError(...)" kind of expressions
|
|
|
|
operator bool() const { return m_dwLastError == 0; }
|
|
|
|
|
|
|
|
// operations on the key itself
|
|
|
|
// explicitly open the key (will be automatically done by all functions
|
|
|
|
// which need the key to be opened if the key is not opened yet)
|
|
|
|
bool Open();
|
2000-02-14 19:05:36 -05:00
|
|
|
// create the key: will fail if the key already exists and !bOkIfExists
|
1998-07-01 13:26:46 -04:00
|
|
|
bool Create(bool bOkIfExists = TRUE);
|
2000-02-14 19:05:36 -05:00
|
|
|
// rename a value from old name to new one
|
|
|
|
bool RenameValue(const wxChar *szValueOld, const wxChar *szValueNew);
|
2000-02-24 18:33:15 -05:00
|
|
|
// rename the key
|
|
|
|
bool Rename(const wxChar *szNewName);
|
2000-02-14 19:05:36 -05:00
|
|
|
// copy value to another key possibly changing its name (by default it will
|
|
|
|
// remain the same)
|
|
|
|
bool CopyValue(const wxChar *szValue, wxRegKey& keyDst,
|
|
|
|
const wxChar *szNewName = NULL);
|
|
|
|
// copy the entire contents of the key recursively to another location
|
2000-02-24 18:33:15 -05:00
|
|
|
bool Copy(const wxChar *szNewName);
|
2000-02-14 19:05:36 -05:00
|
|
|
// same as Copy() but using a key and not the name
|
|
|
|
bool Copy(wxRegKey& keyDst);
|
1998-05-20 10:12:05 -04:00
|
|
|
// close the key (will be automatically done in dtor)
|
|
|
|
bool Close();
|
|
|
|
|
|
|
|
// deleting keys/values
|
|
|
|
// deletes this key and all of it's subkeys/values
|
|
|
|
bool DeleteSelf();
|
|
|
|
// deletes the subkey with all of it's subkeys/values recursively
|
1999-04-21 17:46:02 -04:00
|
|
|
bool DeleteKey(const wxChar *szKey);
|
1998-05-20 10:12:05 -04:00
|
|
|
// deletes the named value (may be NULL to remove the default value)
|
1999-04-21 17:46:02 -04:00
|
|
|
bool DeleteValue(const wxChar *szValue);
|
1998-05-20 10:12:05 -04:00
|
|
|
|
|
|
|
// access to values and subkeys
|
|
|
|
// get value type
|
1999-04-21 17:46:02 -04:00
|
|
|
ValueType GetValueType(const wxChar *szValue) const;
|
1999-01-23 18:50:24 -05:00
|
|
|
// returns TRUE if the value contains a number (else it's some string)
|
1999-04-21 17:46:02 -04:00
|
|
|
bool IsNumericValue(const wxChar *szValue) const;
|
1998-05-20 10:12:05 -04:00
|
|
|
|
|
|
|
// assignment operators set the default value of the key
|
|
|
|
wxRegKey& operator=(const wxString& strValue)
|
|
|
|
{ SetValue(NULL, strValue); return *this; }
|
|
|
|
wxRegKey& operator=(long lValue)
|
|
|
|
{ SetValue(NULL, lValue); return *this; }
|
|
|
|
|
2002-01-21 10:52:03 -05:00
|
|
|
// query the default value of the key: implicitly or explicitly
|
|
|
|
wxString QueryDefaultValue() const;
|
|
|
|
operator wxString() const { return QueryDefaultValue(); }
|
|
|
|
|
|
|
|
// named values
|
1998-05-20 10:12:05 -04:00
|
|
|
|
|
|
|
// set the string value
|
1999-04-21 17:46:02 -04:00
|
|
|
bool SetValue(const wxChar *szValue, const wxString& strValue);
|
2000-10-12 19:40:26 -04:00
|
|
|
// retrieve the string value
|
|
|
|
bool QueryValue(const wxChar *szValue, wxString& strValue) const
|
|
|
|
{ return QueryValue(szValue, strValue, FALSE); }
|
|
|
|
// retrieve raw string value
|
|
|
|
bool QueryRawValue(const wxChar *szValue, wxString& strValue) const
|
|
|
|
{ return QueryValue(szValue, strValue, TRUE); }
|
|
|
|
// retrieve either raw or expanded string value
|
|
|
|
bool QueryValue(const wxChar *szValue, wxString& strValue, bool raw) const;
|
1998-05-20 10:12:05 -04:00
|
|
|
|
|
|
|
#ifdef __WIN32__
|
|
|
|
// set the numeric value
|
1999-04-21 17:46:02 -04:00
|
|
|
bool SetValue(const wxChar *szValue, long lValue);
|
1998-05-20 10:12:05 -04:00
|
|
|
// return the numeric value
|
1999-04-21 17:46:02 -04:00
|
|
|
bool QueryValue(const wxChar *szValue, long *plValue) const;
|
1998-05-20 10:12:05 -04:00
|
|
|
#endif //Win32
|
|
|
|
|
1998-05-27 19:18:16 -04:00
|
|
|
// query existence of a key/value
|
|
|
|
// return true if value exists
|
1999-06-26 07:10:50 -04:00
|
|
|
bool HasValue(const wxChar *szKey) const;
|
1998-05-27 19:18:16 -04:00
|
|
|
// return true if given subkey exists
|
1999-06-26 07:10:50 -04:00
|
|
|
bool HasSubKey(const wxChar *szKey) const;
|
1998-05-27 19:18:16 -04:00
|
|
|
// return true if any subkeys exist
|
1999-06-26 07:10:50 -04:00
|
|
|
bool HasSubkeys() const;
|
|
|
|
// return true if any values exist
|
|
|
|
bool HasValues() const;
|
|
|
|
// return true if the key is empty (nothing under this key)
|
|
|
|
bool IsEmpty() const { return !HasSubkeys() && !HasValues(); }
|
1998-05-20 10:12:05 -04:00
|
|
|
|
|
|
|
// enumerate values and subkeys
|
|
|
|
bool GetFirstValue(wxString& strValueName, long& lIndex);
|
|
|
|
bool GetNextValue (wxString& strValueName, long& lIndex) const;
|
|
|
|
|
|
|
|
bool GetFirstKey (wxString& strKeyName , long& lIndex);
|
|
|
|
bool GetNextKey (wxString& strKeyName , long& lIndex) const;
|
|
|
|
|
2001-04-20 21:46:19 -04:00
|
|
|
// for wxRegConfig usage only: preallocate some memory for the name
|
|
|
|
void ReserveMemoryForName(size_t bytes) { m_strKey.reserve(bytes); }
|
|
|
|
|
1998-05-20 10:12:05 -04:00
|
|
|
private:
|
2001-04-20 21:46:19 -04:00
|
|
|
// common part of all ctors
|
|
|
|
void Init()
|
|
|
|
{
|
|
|
|
m_hKey = (WXHKEY) NULL;
|
|
|
|
m_dwLastError = 0;
|
|
|
|
}
|
|
|
|
|
1998-05-20 10:12:05 -04:00
|
|
|
// no copy ctor/assignment operator
|
|
|
|
wxRegKey(const wxRegKey& key); // not implemented
|
|
|
|
wxRegKey& operator=(const wxRegKey& key); // not implemented
|
|
|
|
|
1998-10-14 19:53:24 -04:00
|
|
|
WXHKEY m_hKey, // our handle
|
1998-05-20 10:12:05 -04:00
|
|
|
m_hRootKey; // handle of the top key (i.e. StdKey)
|
|
|
|
wxString m_strKey; // key name (relative to m_hRootKey)
|
|
|
|
|
2001-04-20 21:46:19 -04:00
|
|
|
long m_dwLastError; // last error (0 if none)
|
1998-05-20 10:12:05 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif //_REGISTRY_H
|
1998-05-27 19:18:16 -04:00
|
|
|
|