1998-05-20 10:12:05 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: msw/registry.h
|
|
|
|
// Purpose: Registry classes and functions
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Modified by:
|
|
|
|
// 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
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// mutable hack (see also registry.cpp)
|
|
|
|
// ----------------------------------------------------------------------------
|
1998-09-25 09:28:52 -04:00
|
|
|
#if wxUSE_MUTABLE
|
1998-05-20 10:12:05 -04:00
|
|
|
#define MUTABLE mutable
|
|
|
|
#else
|
|
|
|
#define MUTABLE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
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
|
|
|
|
Type_Dword_little_endian, // 32-bit number (same as Type_DWORD)
|
|
|
|
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
|
|
|
|
{
|
1999-01-15 19:13:58 -05:00
|
|
|
HKCR // classes root
|
1998-05-20 10:12:05 -04:00
|
|
|
#ifdef __WIN32__
|
1999-01-15 19:13:58 -05:00
|
|
|
, HKCU, // current user
|
1998-05-20 10:12:05 -04:00
|
|
|
HKLM, // local machine
|
|
|
|
HKUSR, // users
|
1999-01-15 19:13:58 -05:00
|
|
|
HKPD // performance data (@@ NT only?)
|
1998-05-20 10:12:05 -04:00
|
|
|
#if WINVER >= 0x0400
|
1999-01-15 19:13:58 -05:00
|
|
|
, HKCC, // current config
|
|
|
|
HKDD // dynamic data
|
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-13 06:19:16 -04:00
|
|
|
|
|
|
|
#ifdef __GNUWIN32__
|
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-08-13 06:19:16 -04:00
|
|
|
#else
|
1998-08-02 19:04:55 -04:00
|
|
|
bool GetKeyInfo(ulong *pnSubKeys, // number of subkeys
|
|
|
|
ulong *pnMaxKeyLen, // max len of subkey name
|
|
|
|
ulong *pnValues, // number of values
|
|
|
|
ulong *pnMaxValueLen) const;
|
1998-08-13 06:19:16 -04:00
|
|
|
#endif
|
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();
|
|
|
|
// 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);
|
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; }
|
|
|
|
|
|
|
|
// conversion operators query the default value of the key
|
|
|
|
operator wxString() const;
|
|
|
|
|
|
|
|
// set the string value
|
1999-04-21 17:46:02 -04:00
|
|
|
bool SetValue(const wxChar *szValue, const wxString& strValue);
|
1998-05-20 10:12:05 -04:00
|
|
|
// return the string value
|
1999-04-21 17:46:02 -04:00
|
|
|
bool QueryValue(const wxChar *szValue, wxString& strValue) 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-04-21 17:46:02 -04:00
|
|
|
bool HasValue(const wxChar *szKey) const;
|
1998-05-27 19:18:16 -04:00
|
|
|
// return true if given subkey exists
|
1999-04-21 17:46:02 -04:00
|
|
|
bool HasSubKey(const wxChar *szKey) const;
|
1998-05-27 19:18:16 -04:00
|
|
|
// return true if any subkeys exist
|
1998-05-20 10:12:05 -04:00
|
|
|
bool HasSubkeys() const;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// 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)
|
|
|
|
|
|
|
|
MUTABLE long m_dwLastError; // last error (0 if none)
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif //_REGISTRY_H
|
1998-05-27 19:18:16 -04:00
|
|
|
|