// XTRegistryManager.h : header file // // This file is a part of the Xtreme Toolkit for MFC. // ©1998-2003 Codejock Software, All Rights Reserved. // // This source code can only be used under the terms and conditions // outlined in the accompanying license agreement. // // support@codejock.com // http://www.codejock.com // ////////////////////////////////////////////////////////////////////// #ifndef __XTREGISTRYMANAGER_H__ #define __XTREGISTRYMANAGER_H__ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 ////////////////////////////////////////////////////////////////////// // Summary: CXTRegistryManager is a stand alone registry management class. You // can use it to read and write values from your system's registry or an // .INI file. Use CXTRegistryManager to read and write string, integer, // and binary data to and from the registry. You can also specify an .INI // file name, and have these values stored there instead. class _XT_EXT_CLASS CXTRegistryManager { public: // Input: hKeyBase - Current key to be used in the registry. // Summary: Constructs a CXTRegistryManager object. CXTRegistryManager(HKEY hKeyBase = HKEY_CURRENT_USER); // Summary: Destroys a CXTRegistryManager object, handles cleanup and de-allocation. virtual ~CXTRegistryManager(); protected: HKEY m_hKeyBase; // Handle to the registry key to use. The default is HKEY_CURRENT_USER. CString m_strINIFileName; // Name of an .INI file for registry settings. CWinApp* m_pWinApp; // Points to an application's CWinApp object. public: // Input: strINIFileName - Full path to the .INI file. // Summary: This member function will set the .INI file name for the registry // manager to use instead of the system registry. void SetINIFileName(CString strINIFileName); // Returns: A CString object. // Summary: This member function will return the file name of the .INI file // used by the registry manager. CString GetINIFileName(); // Input: lpszSection - Points to a null-terminated string that specifies the section // containing the entry. If the section does not exist, it is created. // The name of the section is case independent. The string may be any // combination of uppercase and lowercase letters. // section - Points to a null-terminated string that contains the entry into // which the value is to be written. If the entry does not exist in // the specified section, it is created. // nValue - Contains the value to be written. // Returns: Nonzero if successful, otherwise returns zero. // Summary: Call this member function to write the specified INT value into // the specified section of the application’s registry or .INI file. BOOL WriteProfileInt(LPCTSTR lpszSection,LPCTSTR lpszEntry,int nValue); // Input: lpszSection - Points to a null-terminated string that specifies the section // containing the entry. If the section does not exist, it is created. // The name of the section is case independent. The string may be any // combination of uppercase and lowercase letters. // lpszEntry - Points to a null-terminated string that contains the entry into // which the value is to be written. If the entry does not exist in // the specified section, it is created. // pData - Contains the value to be written. // nBytes - Contains the size of the value to be written. // Returns: Nonzero if successful, otherwise returns zero. // Summary: Call this member function to write the specified binary value into // the specified section of the application’s registry or .INI file. BOOL WriteProfileBinary(LPCTSTR lpszSection,LPCTSTR lpszEntry,LPBYTE pData,UINT nBytes); // Input: lpszSection - Points to a null-terminated string that specifies the section // containing the entry. If the section does not exist, it is created. // The name of the section is case independent. The string may be any // combination of uppercase and lowercase letters. // lpszEntry - Points to a null-terminated string that contains the entry into // which the value is to be written. If the entry does not exist in // the specified section, it is created. // lpszValue - Contains the value to be written. // Returns: Nonzero if successful, otherwise returns zero. // Summary: Call this member function to write the specified string value into // the specified section of the application’s registry or .INI file. BOOL WriteProfileString(LPCTSTR lpszSection,LPCTSTR lpszEntry,LPCTSTR lpszValue); // Input: lpszSection - Points to a null-terminated string that specifies the section // containing the entry. If the section does not exist, it is created. // The name of the section is case independent. The string may be any // combination of uppercase and lowercase letters. // lpszEntry - Points to a null-terminated string that contains the entry into // which the value is to be written. If the entry does not exist in // the specified section, it is created. // pValue - Contains the value to be written. // Returns: Nonzero if successful, otherwise returns zero. // Summary: Call this member function to write the specified CPoint value into // the specified section of the application’s registry or .INI file. BOOL WriteProfilePoint(LPCTSTR lpszSection,LPCTSTR lpszEntry,CPoint * pValue); // Input: lpszSection - Points to a null-terminated string that specifies the section // containing the entry. If the section does not exist, it is created. // The name of the section is case independent. The string may be any // combination of uppercase and lowercase letters. // lpszEntry - Points to a null-terminated string that contains the entry into // which the value is to be written. If the entry does not exist in // the specified section, it is created. // pValue - Contains the value to be written. // Returns: Nonzero if successful, otherwise returns zero. // Summary: Call this member function to write the specified CRect value into // the specified section of the application’s registry or .INI file. BOOL WriteProfileRect(LPCTSTR lpszSection,LPCTSTR lpszEntry,CRect * pValue); // Input: lpszSection - Points to a null-terminated string that specifies the section // containing the entry. If the section does not exist, it is created. // The name of the section is case independent. The string may be any // combination of uppercase and lowercase letters. // lpszEntry - Points to a null-terminated string that contains the entry into // which the value is to be written. If the entry does not exist in // the specified section, it is created. // pValue - Contains the value to be written. // Returns: Nonzero if successful, otherwise returns zero. // Summary: Call this member function to write the specified CSize value into // the specified section of the application’s registry or .INI file. BOOL WriteProfileSize(LPCTSTR lpszSection,LPCTSTR lpszEntry,CSize * pValue); // Input: lpszSection - Points to a null-terminated string that specifies the section // containing the entry. If the section does not exist, it is created. // The name of the section is case independent. The string may be any // combination of uppercase and lowercase letters. // lpszEntry - Points to a null-terminated string that contains the entry into // which the value is to be written. If the entry does not exist in // the specified section, it is created. // pValue - Contains the value to be written. // Returns: Nonzero if successful, otherwise returns zero. // Summary: Call this member function to write the specified double/float value // into the specified section of the application’s registry or .INI file. BOOL WriteProfileDouble(LPCTSTR lpszSection,LPCTSTR ,double * pValue); // Input: lpszSection - Points to a null-terminated string that specifies the section // containing the entry. If the section does not exist, it is created. // The name of the section is case independent. The string may be any // combination of uppercase and lowercase letters. // lpszEntry - Points to a null-terminated string that contains the entry into // which the value is to be written. If the entry does not exist in // the specified section, it is created. // pValue - Contains the value to be written. // Returns: Nonzero if successful, otherwise returns zero. // Summary: Call this member function to write the specified DWORD value into // the specified section of the application’s registry or .INI file. // // Note that as COLORREF is a typedef for a DWORD, WriteProfileColor calls // this function. BOOL WriteProfileDword(LPCTSTR lpszSection,LPCTSTR lpszEntry,DWORD * pValue); // Input: lpszSection - Points to a null-terminated string that specifies the section // containing the entry. If the section does not exist, it is created. // The name of the section is case independent. The string may be any // combination of uppercase and lowercase letters. // lpszEntry - Points to a null-terminated string that contains the entry into // which the value is to be written. If the entry does not exist in // the specified section, it is created. // pValue - Contains the value to be written. // Returns: Nonzero if successful, otherwise returns zero. // Summary: Call this member function to write the specified COLORREF value // into the specified section of the application’s registry or .INI file. // // Note that as COLORREF is a typedef for a DWORD, this function just // calls WriteProfileDword. BOOL WriteProfileColor(LPCTSTR lpszSection,LPCTSTR lpszEntry,COLORREF * pValue); // Input: lpszSection - Points to a null-terminated string that specifies the section // containing the entry. // lpszEntry - Points to a null-terminated string that contains the entry whose // value is to be retrieved. // nDefault - Specifies the default value to return if the framework cannot // find the entry. This value can be an unsigned value in the range 0 // through 65,535 or a signed value in the range –32,768 through 32,767. // Returns: The integer value of the string that follows the // specified entry if the function is successful. The return value is // the value of the 'nDefault' parameter if the function does not find the // entry. The return value is zero if the value that corresponds to the // specified entry is not an integer. // Summary: Call this member function to retrieve the value of an integer from // an entry within a specified section of the application’s registry or // .INI file. // // This member function supports hexadecimal notation for the value // in the .INI file. When you retrieve a signed integer, you should cast // the value into an int. UINT GetProfileInt(LPCTSTR lpszSection,LPCTSTR lpszEntry,int nDefault); // Input: lpszSection - Points to a null-terminated string that specifies the section // containing the entry. // lpszEntry - Points to a null-terminated string that contains the entry whose // value is to be retrieved. // ppData - Address of a LPBYTE data member to receive the value. It is the // caller's responsibility to free the memory allocated for 'ppData'. // An example of this would be: // //
// void CXTDockWindow::LoadBarSize(CString strSection)
// {
// XT_MANAGE_STATE; // Switch to toolkit resources/module state
//
// // restore the previous bar style.
// if(::IsWindow(m_hWnd))
// {
// UINT nSize = 0;
// LPBYTE pbtData = 0;
// CString string;
// string.LoadString(XT_IDS_REG_BARPOS);
//
// CXTRegistryManager regManager;
// if (regManager.GetProfileBinary( strSection,
// string, &pbtData, &nSize))
// {
// XT_BARPLACEMENT* pBP =
// reinterpret_cast(pbtData);
//
// SetBarPlacement(pBP);
// delete [] pbtData;
// }
// }
// }
// pBytes - Address of a UINT to receive the size of 'ppData'.
// Returns: Nonzero if successful, otherwise returns zero.
// Summary: Call this member function to retrieve the binary value from an entry
// within a specified section of the application’s registry or .INI file.
BOOL GetProfileBinary(LPCTSTR lpszSection,LPCTSTR lpszEntry,BYTE** ppData,UINT* pBytes);
// Input: lpszSection - Points to a null-terminated string that specifies the section
// containing the entry.
// lpszEntry - Points to a null-terminated string that contains the entry whose
// value is to be retrieved.
// lpszDefault - Points to the default string value for the given entry if the
// entry cannot be found in the initialization file.
// Returns: The string associated with an entry within the specified section in the
// application’s registry or .INI file. The return value is the string from the
// application’s .INI file or 'lpszDefault' if the string cannot be found.
// Summary: Call this member function to retrieve the string associated with
// an entry within the specified section in the application’s registry
// or .INI file. The return value is the string from the application’s
// .INI file or 'lpszDefault' if the string cannot be found. The maximum
// string length supported by the framework is _MAX_PATH. If 'lpszDefault'
// is NULL, the return value is an empty string.
CString GetProfileString(LPCTSTR lpszSection,LPCTSTR lpszEntry,LPCTSTR lpszDefault);
// Input: lpszSection - Points to a null-terminated string that specifies the section
// containing the entry.
// lpszEntry - Points to a null-terminated string that contains the entry whose
// value is to be retrieved.
// ptResult - Points to the variable to be filled from the registry.
// Returns: TRUE if the function succeeds, and FALSE otherwise.
// Summary: Call this member function to retrieve the value of a CPoint from
// an entry within a specified section of the application’s registry or
// .INI file. Retrieves the CPoint value that follows the specified entry
// if the function is successful.
BOOL GetProfilePoint(LPCTSTR lpszSection,LPCTSTR lpszEntry,CPoint * ptResult);
// Input: lpszSection - Points to a null-terminated string that specifies the section
// containing the entry.
// lpszEntry - Points to a null-terminated string that contains the entry whose
// value is to be retrieved.
// rcResult - Points to the variable to be filled from the registry.
// Returns: TRUE if the function succeeds, and FALSE otherwise.
// Summary: Call this member function to retrieve the value of a CRect from
// an entry within a specified section of the application’s registry or
// .INI file. Retrieves the CRect value that follows the specified entry
// if the function is successful.
BOOL GetProfileRect(LPCTSTR lpszSection,LPCTSTR lpszEntry,CRect * rcResult);
// Input: lpszSection - Points to a null-terminated string that specifies the section
// containing the entry.
// lpszEntry - Points to a null-terminated string that contains the entry whose
// value is to be retrieved.
// rcResult - Points to the variable to be filled from the registry.
// Returns: TRUE if the function succeeds, and FALSE otherwise.
// Summary: Call this member function to retrieve the value of a CSize from
// an entry within a specified section of the application’s registry or
// .INI file. Retrieves the CSize value that follows the specified entry
// if the function is successful.
BOOL GetProfileSize(LPCTSTR lpszSection,LPCTSTR lpszEntry,CSize * rcResult);
// Input: lpszSection - Points to a null-terminated string that specifies the section
// containing the entry.
// lpszEntry - Points to a null-terminated string that contains the entry whose
// value is to be retrieved.
// rcResult - Points to the variable to be filled from the registry.
// Returns: TRUE if the function succeeds, and FALSE otherwise.
// Summary: Call this member function to retrieve the value of a double from
// an entry within a specified section of the application’s registry or
// .INI file. Retrieves the value that follows the specified entry if the
// function is successful.
BOOL GetProfileDouble(LPCTSTR lpszSection,LPCTSTR lpszEntry,double * rcResult);
// Input: lpszSection - Points to a null-terminated string that specifies the section
// containing the entry.
// lpszEntry - Points to a null-terminated string that contains the entry whose
// value is to be retrieved.
// rcResult - Points to the variable to be filled from the registry.
// Returns: TRUE if the function succeeds, and FALSE otherwise.
// Summary: Call this member function to retrieve the value of a DWORD from
// an entry within a specified section of the application’s registry or
// .INI file. Retrieves the value that follows the specified entry if the
// function is successful.
//
// Note that as COLORREF is a typedef for a DWORD, GetProfileColor calls
// this function.
BOOL GetProfileDword(LPCTSTR lpszSection,LPCTSTR lpszEntry,DWORD * rcResult);
// Input: lpszSection - Points to a null-terminated string that specifies the section
// containing the entry.
// lpszEntry - Points to a null-terminated string that contains the entry whose
// value is to be retrieved.
// rcResult - Points to the variable to be filled from the registry.
// Returns: TRUE if the function succeeds, and FALSE otherwise.
// Summary: Call this member function to retrieve the value of a COLORREF from
// an entry within a specified section of the application’s registry or
// .INI file. Retrieves the value that follows the specified entry if the
// function is successful.
//
// Note that as COLORREF is a typedef for a DWORD, this function just
// calls GetProfileDword.
BOOL GetProfileColor(LPCTSTR lpszSection,LPCTSTR lpszEntry,COLORREF * rcResult);
// BULLETED LIST:
// Input: lpszSection - Points to a null-terminated string that specifies the section containing
// the entry.
// mapItems - A reference to a CMap