liutang:写的不错。
另外,推荐使用MFC的CRegKey
(发表于2003-3-23 18:16:00)
xiaojin:不好意思,我以前没注意到MFC有这个类。但我写的比MFC简单。
(发表于2003-3-24 8:13:00)
chambers:注册信息添加到注册表中后,重新启动,注册信息都没有了!!!!
(发表于2003-9-23 15:18:00)
wyqml:谢谢了,这个类比较好。
我只用到write成员函数时发现不能设置二进制值,不过只要将设置二进制值的write成员函数中的RegSetValueEx的参数REG_DWORD改为REG_BINARY即可写入二进制值。
另外,我还不知道怎么样设置长度为零的二进制值。我如果将nVal赋值为0的话,在注册表中的二进制值是00 00, 并不是我想要的“长度为零的二进制值”。
请教高手。
(发表于2003-12-19 17:38:00)
guanghezhou:注册信息添加到注册表中后,重新启动,注册信息都没有了,但是注消不会丢失是怎么回事
(发表于2005-3-21 16:04:00)
nonocast:注册信息添加到注册表中后,重新启动,注册信息都没有了,但是注消不会丢失是怎么回事!!!
发现同样问题!!!
怎么解决
(发表于2005-7-17 15:19:00)
nonocast:RegCreateKeyEx()
注意第五个参数dwOptions用的是哪个值~~
如果是 REG_OPTION_VOLATILE的话,创建的值只要重起机器就没了~~
要保留的话,要用 REG_OPTION_NON_VOLATILE~~
(发表于2005-7-17 15:25:00)
24431188:I had modify the class.
Registry.h:
/*--------------------------------\
public://add the follow functions.
BOOL EnumKey(CStringList &strList);
BOOL UpLevelKey();
CString GetCurrentKey();
CString GetRegRoot();
protected://add the follow propertys
CString m_strCurrentKey;
CString m_strRegRoot;
\--------------------------------*/
Registry.cpp
/*----------------------------------\
CRegistry::CRegistry(HKEY hKey)
{
m_hKey=hKey;
if( hKey == HKEY_LOCAL_MACHINE)
m_strRegRoot = "HKEY_LOCAL_MACHINE";
//recode current RegRoot in CString.
//if hKey == HKEY_CLASSES_ROOT ....and so on
.........
}
BOOL CRegistry::CreateKey(LPCTSTR lpSubKey)
{
.......
if(lReturn==ERROR_SUCCESS)
{
m_hKey=hKey;
m_strCurrentKey += lpSubKey;
m_strCurrentKey.TrimRight("\\");
m_strCurrentKey += "\\";
return TRUE;
}
......
}
\-----------------------------------*/
(发表于2006-3-28 15:55:00)
24431188:BOOL CRegistry::Open(LPCTSTR lpSubKey)
{
............
if(lReturn==ERROR_SUCCESS)
{
m_hKey=hKey;
m_strCurrentKey += lpSubKey;
m_strCurrentKey.TrimRight("\\");
m_strCurrentKey += "\\";
return TRUE;
}
}
BOOL CRegistry::UpLevelKey()
{
ASSERT(m_hKey);
CString strRoot = m_strRegRoot;
CString strCurrentKey = m_strCurrentKey;
Close();
if( strRoot == "HKEY_LOCAL_MACHINE")
m_hKey = HKEY_LOCAL_MACHINE;
//if strRoot == "HKEY_CLASSES_ROOT"
//m_hKey = HKEY_CLASSES_ROOT; and so on.
strCurrentKey.TrimRight("\\");
CString strUpLevel = strCurrentKey.Left(strCurrentKey.ReverseFind('\\'));
return Open(strUpLevel);
...................
}
(发表于2006-3-28 16:00:00)
24431188:void CRegistry::Close()
{
if(m_hKey)
{
RegCloseKey(m_hKey);
m_hKey=NULL;
m_strCurrentKey.Empty();
m_strRegRoot.Empty();
}
}
BOOL CRegistry::EnumKey(CStringList &strList)
{
ASSERT(m_hKey);
char buf[MAX_PATH] = { 0 };
DWORD dwIndex = 0;
CString strListNote;
long lReturn = RegEnumKey (m_hKey,dwIndex,buf,MAX_PATH);
while (lReturn == ERROR_SUCCESS)
{
strListNote = buf;
strList.AddTail(strListNote);
lReturn = RegEnumKey(m_hKey,++dwIndex,buf,MAX_PATH);
}
return TRUE;
}
// that is all.
(发表于2006-3-28 16:01:00)
ldehai:关于“guanghezhou:注册信息添加到注册表中后,重新启动,注册信息都没有了,但是注消不会丢失是怎么回事?"的解释:
long lReturn=RegCreateKeyEx(m_hKey,lpSubKey,0L,NULL,REG_OPTION_VOLATILE,KEY_ALL_ACCESS,NULL,&hKey,&dw);
这里REG_OPTION_VOLATILE 表示重启后无效
正式用的话要改成REG_OPTION_NON_VOLATILE,表示重启后依然有效。
(发表于2007-6-29 14:49:00)
ldehai:其实这个类完全可以不用继承自CObject,把用到的CString 全部替换为LPCTSTR,能用的地方就多了。
(发表于2007-6-29 14:53:00)
..........................................................................
--------------------next---------------------