//************************************************************
//*
//* RegSettings.h
//*
//* CRegSettings class interface.
//*
//* DESCRIPTION:
//* One MFC CObject derived class to implement a simple
//* interface for storing app settings into registry.
//*
//* ASSUMES:
//* Only MFC and an average coder :-)
//*
//* AUTHOR: T1TAN <t1tan@cmar-net.org>
//*
//* COPYLEFT:
//* Copyleft (C) T1TAN 2004 - 3827
//* Copyleft (C) SprdSoft Inc.2004 - 3827
//* FREE for (ab)use in any way except selling the code.
//* Leave the headers be.
//*
//* VERSIONS:
//* VERSION AUTHOR DATE NOTES
//* ------- ------ ---- -----
//* 1.0 T1TAN 18/10/2004 initial version
//*
//*
//* OTHER:
//* <nothing yet>
//*
//************************************************************
#ifndef REGSETTINGS_H
#define REGSETTINGS_H
#ifndef twice
#define twice once
#endif
// there used to be a "#pragma once" here, but thanx to one of
// my friends, we now have a better version
#if _MSC_VER > 1000
#pragma twice
#endif // _MSC_VER > 1000
class CRegSettings : public CObject
{
public:
// c'tor and d'tor
CRegSettings( BOOL bUseFlushing = FALSE );
virtual ~CRegSettings();
// inline functions for properties
void SetUseFlushing( BOOL bUseFlushing = TRUE )
{ m_bUseFlushing = bUseFlushing; }
void SetAppName( LPCTSTR szAppName )
{ // set the name and remove junk
m_szAppName = szAppName;
m_szAppName.TrimLeft();
m_szAppName.TrimRight();
m_szAppName.Replace( "/", NULL );
m_szAppName.Replace( "\\", NULL );
}
void SetCompanyName( LPCTSTR szCompanyName )
{ // same here..
m_szCompanyName = szCompanyName;
m_szCompanyName.TrimLeft();
m_szCompanyName.TrimRight();
m_szCompanyName.Replace( "/", NULL );
m_szCompanyName.Replace( "\\", NULL );
}
CString GetAppName() const
{ return m_szAppName; }
CString GetCompanyName() const
{ return m_szCompanyName; }
BOOL GetUseFlushing() const
{ return m_bUseFlushing; }
// one static for retrieving last error text
static CString GetLastErrorText();
// to remove all settings
BOOL DeleteAll( BOOL bDeleteCompany = FALSE );
// overloads for sale
// you pay for two, but get one extra for your wife and kids
BOOL Write( LPCTSTR szKey, LPCTSTR szName, UCHAR value );
BOOL Write( LPCTSTR szKey, LPCTSTR szName, char value );
BOOL Write( LPCTSTR szKey, LPCTSTR szName, USHORT value );
BOOL Write( LPCTSTR szKey, LPCTSTR szName, short value );
BOOL Write( LPCTSTR szKey, LPCTSTR szName, UINT value );
BOOL Write( LPCTSTR szKey, LPCTSTR szName, int value );
BOOL Write( LPCTSTR szKey, LPCTSTR szName, ULONG value );
BOOL Write( LPCTSTR szKey, LPCTSTR szName, long value );
BOOL Write( LPCTSTR szKey, LPCTSTR szName, float value );
BOOL Write( LPCTSTR szKey, LPCTSTR szName, double value );
BOOL Write( LPCTSTR szKey, LPCTSTR szName, LPCTSTR value );
BOOL Write( LPCTSTR szKey, LPCTSTR szName, const LPVOID value, UINT size );
BOOL Read( LPCTSTR szKey, LPCTSTR szName, UCHAR& value );
BOOL Read( LPCTSTR szKey, LPCTSTR szName, char& value );
BOOL Read( LPCTSTR szKey, LPCTSTR szName, USHORT& value );
BOOL Read( LPCTSTR szKey, LPCTSTR szName, short& value );
BOOL Read( LPCTSTR szKey, LPCTSTR szName, UINT& value );
BOOL Read( LPCTSTR szKey, LPCTSTR szName, int& value );
BOOL Read( LPCTSTR szKey, LPCTSTR szName, ULONG& value );
BOOL Read( LPCTSTR szKey, LPCTSTR szName, long& value );
BOOL Read( LPCTSTR szKey, LPCTSTR szName, float& value );
BOOL Read( LPCTSTR szKey, LPCTSTR szName, double& value );
BOOL Read( LPCTSTR szKey, LPCTSTR szName, LPVOID value, ULONG& size );
BOOL Read( LPCTSTR szKey, LPCTSTR szName, LPTSTR value, ULONG& size );
protected:
CString m_szCompanyName;
CString m_szAppName;
BOOL m_bUseFlushing;
// our private stuff you don't need and can't have (-:
BOOL GetHKEY( LPCTSTR szKey, PHKEY hKey, BOOL bRead = FALSE );
void CloseHKEY( HKEY hKey );
CString CleanKeyName( LPCTSTR szKey );
};
#endif // REGSETTINGS_H