/*================================================================
* 函数名: VerifyValue
* 参数: (LPCTSTR pszValue)
* 功能描述: 判断给定的值是否存在 (请先调用VerifyKey,然后在使用该函数)
* 返回值: BOOL
================================================================*/
BOOL CReg::VerifyValue (LPCTSTR pszValue)
{
LONG lReturn = ::RegQueryValueEx(m_hSubKey, pszValue, NULL,
NULL, NULL, NULL);
if(lReturn == ERROR_SUCCESS)
return TRUE;
return FALSE;
}
/*================================================================
* 函数名: VerifyValue
* 参数: (LPCTSTR pszValue)
* 功能描述: 判断指定的键名是否等于某个值
* 返回值: BOOL
================================================================*/
BOOL CReg::IsEqual(LPCTSTR pszValue,int nn)
{
int nTemp;
this->Read(pszValue,nTemp);
if(nTemp==nn)
return TRUE;
return FALSE;
}
BOOL CReg::IsEqual(LPCTSTR pszValue,DWORD dw)
{
DWORD dwTemp;
this->Read(pszValue,dwTemp);
if(dwTemp==dw)
return TRUE;
return FALSE;
}
BOOL CReg::IsEqual(LPCTSTR pszValue,LPCTSTR lpsz)
{
CString str;
this->Read(pszValue,str);
if(str.CompareNoCase(lpsz)==0)
return TRUE;
return FALSE;
}
/*================================================================
* 函数名: CreateKey
* 参数: (HKEY hRootKey, LPCTSTR pszPath)
* 功能描述: 创建路径
* 返回值: BOOL
================================================================*/
BOOL CReg::CreateKey (LPCTSTR pszPath)
{
DWORD dw;
LONG ReturnValue = ::RegCreateKeyEx (m_hRootKey, pszPath, 0L, NULL,
REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL,
&m_hSubKey, &dw);
if(ReturnValue == ERROR_SUCCESS)
return TRUE;
return FALSE;
}
/*================================================================
* 函数名: Write
* 参数: (LPCTSTR lpszKeyName, int iVal)
* 功能描述: 写入整型值
* 返回值: BOOL
================================================================*/
BOOL CReg::Write (LPCTSTR lpszKeyName, int iVal)
{
DWORD dwValue;
dwValue = (DWORD)iVal;
LONG ReturnValue = ::RegSetValueEx (m_hSubKey, lpszKeyName, 0L, REG_DWORD,
(CONST BYTE*) &dwValue, sizeof(DWORD));
if(ReturnValue == ERROR_SUCCESS)
return TRUE;
return FALSE;
}
/*================================================================
* 函数名: Write
* 参数: (LPCTSTR lpszKeyName, DWORD dwVal)
* 功能描述: 写入DWORD值
* 返回值: BOOL
================================================================*/
BOOL CReg::Write (LPCTSTR lpszKeyName, DWORD dwVal)
{
return ::RegSetValueEx (m_hSubKey, lpszKeyName, 0L, REG_DWORD,
(CONST BYTE*) &dwVal, sizeof(DWORD));
}
/*================================================================
* 函数名: Write
* 参数: (LPCTSTR lpszKeyName, LPCTSTR pszData)
* 功能描述: 写入字符串值
* 返回值: BOOL
================================================================*/
BOOL CReg::Write (LPCTSTR lpszKeyName, LPCTSTR pszData)
{
LONG ReturnValue = ::RegSetValueEx (m_hSubKey, lpszKeyName, 0L, REG_SZ,
(CONST BYTE*) pszData, strlen(pszData) + 1);
if(ReturnValue == ERROR_SUCCESS)
return TRUE;
return FALSE;
}
/*================================================================
* 函数名: Read
* 参数: (LPCTSTR lpszKeyName, int& iVal) 第2个参数通过引用传递,可以在函数中修改实参
* 功能描述: 读取整数
* 返回值: BOOL
================================================================*/
BOOL CReg::Read(LPCTSTR lpszKeyName, int& iVal)
{
DWORD dwType;
DWORD dwSize = sizeof (DWORD);
DWORD dwDest;
LONG lReturn = ::RegQueryValueEx (m_hSubKey, (LPSTR) lpszKeyName, NULL,
&dwType, (BYTE *) &dwDest, &dwSize);
if(lReturn == ERROR_SUCCESS)
{
iVal = (int)dwDest;
return TRUE;
}
return FALSE;
}
/*================================================================
* 函数名: Read
* 参数: (LPCTSTR lpszKeyName, DWORD& dwVal) 第2个参数通过引用传递,可以在函数中修改实参
* 功能描述: 读取DWORD值
* 返回值: BOOL
================================================================*/
BOOL CReg::Read (LPCTSTR lpszKeyName, DWORD& dwVal)
{
DWORD dwType;
DWORD dwSize = sizeof (DWORD);
DWORD dwDest;
LONG lReturn = ::RegQueryValueEx (m_hSubKey, (LPSTR) lpszKeyName, NULL,
&dwType, (BYTE *) &dwDest, &dwSize);
if(lReturn == ERROR_SUCCESS)
{
dwVal = dwDest;
return TRUE;
}
return FALSE;
}
/*================================================================
* 函数名: Read
* 参数: (LPCTSTR lpszKeyName, CString& sVal) 第2个参数通过引用传递,可以在函数中修改实参
* 功能描述: 读取字符串值
* 返回值: BOOL
================================================================*/
BOOL CReg::Read (LPCTSTR lpszKeyName, CString& sVal)
{
DWORD dwType;
DWORD dwSize = 200;
char szString[255];
LONG lReturn = ::RegQueryValueEx (m_hSubKey, (LPSTR) lpszKeyName, NULL,
&dwType, (BYTE *) szString, &dwSize);
if(lReturn == ERROR_SUCCESS)
{
sVal = szString;
return TRUE;
}
return FALSE;
}
/*================================================================
* 函数名: DeleteValue
* 参数: (LPCTSTR pszValue)
* 功能描述: 删除值
* 返回值: BOOL
================================================================*/
BOOL CReg::DeleteValue (LPCTSTR pszValue)
{
if(::RegDeleteValue(m_hSubKey, pszValue)== ERROR_SUCCESS)
return TRUE;
else
return FALSE;
}
/*================================================================
* 函数名: DeleteKey
* 参数: (HKEY hRootKey, LPCTSTR pszPath)
* 功能描述: 删除路径
* 返回值: BOOL
================================================================*/
BOOL CReg::DeleteKey (LPCTSTR pszPath)
{
if(::RegDeleteKey(m_hRootKey, pszPath) == ERROR_SUCCESS)
return TRUE;
else
return FALSE;
}
/*================================================================
* 函数名: Close
* 参数:
* 功能描述: 关闭注册表
* 返回值: void
================================================================*/
void CReg::Close()
{
if (m_hSubKey)
{
::RegCloseKey (m_hSubKey);
m_hSubKey = NULL;
}
}