封装了一个简单的注册表操作类
2005-08-12 15:19
671 查看
不想写文字了 测试了下 可以使用 想知道详细的用法加我QQ吧 76359121
MSN :navyblue1982@hotmail.com
#if !defined(AFX_REGISTRY_H__E0610A5D_7166_4D02_9D7E_11AF7CF8E229__INCLUDED_)
#define AFX_REGISTRY_H__E0610A5D_7166_4D02_9D7E_11AF7CF8E229__INCLUDED_
//创建新键的返回值
#include <winreg.h>
const UINT nReturnNewKeySuccess=1;
const UINT nReturnNewKeyFail=0;
class RegToToolBar
{
public: //Software/Microsoft/Internet Explorer/Extensions
RegToToolBar(HKEY hKey=HKEY_LOCAL_MACHINE,CString szIeKey="Software//Microsoft//Internet Explorer//Extensions",CString szNewKey="//{06DD38D3-D187-11CF-A80D-00C04FD74AD8}");//主键
//UINT OpenKey(CString );
UINT NewAKey();//新字键的名称
UINT AddStrToKey(LPCTSTR,LPCTSTR);//第一个是要添加新新项的名称,第二个是数值
void CloseHkey();//关闭主键
~RegToToolBar();
private:
//主键
HKEY m_hKey;
//要新建的目录
CString m_szIeKey;
//要新建键
CString m_szNewKey;
//要打开的目录
CString m_szOpenItem;
};
#endif//AFX_REGISTRY_H__E0610A5D_7166_4D02_9D7E_11AF7CF8E229__INCLUDED_
////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "RegToToolBar.h"
RegToToolBar::RegToToolBar(HKEY hKey,CString szIeKey,CString szNewKey)
{
m_szIeKey=szIeKey;
m_szNewKey=szNewKey;
m_hKey=hKey;
m_szOpenItem=m_szIeKey+m_szNewKey;//新建的目录
}
UINT RegToToolBar::NewAKey()
{
ASSERT(m_hKey);
ASSERT(m_szOpenItem);
HKEY hKey;
DWORD dw;
long lReturn=::RegCreateKeyEx(m_hKey,m_szOpenItem,0L,NULL,REG_OPTION_VOLATILE,KEY_ALL_ACCESS,NULL,&hKey,&dw);
if(ERROR_SUCCESS==lReturn)
{
m_hKey=hKey;
return nReturnNewKeySuccess;
}
return nReturnNewKeyFail;
}
UINT RegToToolBar::AddStrToKey(LPCTSTR szNewItem,LPCTSTR szNewValue)
{
ASSERT(m_hKey);
ASSERT(szNewItem);
ASSERT(szNewValue);
long lReturn=RegSetValueEx(m_hKey,szNewItem,0L,REG_SZ,(const BYTE*)szNewValue,strlen(szNewValue));
if(lReturn==ERROR_SUCCESS)
return nReturnNewKeySuccess;
return nReturnNewKeyFail;
}
void RegToToolBar::CloseHkey()
{
if(m_hKey)
{
RegCloseKey(m_hKey);
m_hKey=NULL;
}
}
RegToToolBar::~RegToToolBar()
{
CloseHkey();
}
MSN :navyblue1982@hotmail.com
#if !defined(AFX_REGISTRY_H__E0610A5D_7166_4D02_9D7E_11AF7CF8E229__INCLUDED_)
#define AFX_REGISTRY_H__E0610A5D_7166_4D02_9D7E_11AF7CF8E229__INCLUDED_
//创建新键的返回值
#include <winreg.h>
const UINT nReturnNewKeySuccess=1;
const UINT nReturnNewKeyFail=0;
class RegToToolBar
{
public: //Software/Microsoft/Internet Explorer/Extensions
RegToToolBar(HKEY hKey=HKEY_LOCAL_MACHINE,CString szIeKey="Software//Microsoft//Internet Explorer//Extensions",CString szNewKey="//{06DD38D3-D187-11CF-A80D-00C04FD74AD8}");//主键
//UINT OpenKey(CString );
UINT NewAKey();//新字键的名称
UINT AddStrToKey(LPCTSTR,LPCTSTR);//第一个是要添加新新项的名称,第二个是数值
void CloseHkey();//关闭主键
~RegToToolBar();
private:
//主键
HKEY m_hKey;
//要新建的目录
CString m_szIeKey;
//要新建键
CString m_szNewKey;
//要打开的目录
CString m_szOpenItem;
};
#endif//AFX_REGISTRY_H__E0610A5D_7166_4D02_9D7E_11AF7CF8E229__INCLUDED_
////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "RegToToolBar.h"
RegToToolBar::RegToToolBar(HKEY hKey,CString szIeKey,CString szNewKey)
{
m_szIeKey=szIeKey;
m_szNewKey=szNewKey;
m_hKey=hKey;
m_szOpenItem=m_szIeKey+m_szNewKey;//新建的目录
}
UINT RegToToolBar::NewAKey()
{
ASSERT(m_hKey);
ASSERT(m_szOpenItem);
HKEY hKey;
DWORD dw;
long lReturn=::RegCreateKeyEx(m_hKey,m_szOpenItem,0L,NULL,REG_OPTION_VOLATILE,KEY_ALL_ACCESS,NULL,&hKey,&dw);
if(ERROR_SUCCESS==lReturn)
{
m_hKey=hKey;
return nReturnNewKeySuccess;
}
return nReturnNewKeyFail;
}
UINT RegToToolBar::AddStrToKey(LPCTSTR szNewItem,LPCTSTR szNewValue)
{
ASSERT(m_hKey);
ASSERT(szNewItem);
ASSERT(szNewValue);
long lReturn=RegSetValueEx(m_hKey,szNewItem,0L,REG_SZ,(const BYTE*)szNewValue,strlen(szNewValue));
if(lReturn==ERROR_SUCCESS)
return nReturnNewKeySuccess;
return nReturnNewKeyFail;
}
void RegToToolBar::CloseHkey()
{
if(m_hKey)
{
RegCloseKey(m_hKey);
m_hKey=NULL;
}
}
RegToToolBar::~RegToToolBar()
{
CloseHkey();
}
相关文章推荐
- php封装一个简单的数据库操作类
- 一个简单的数据库操作类、封装了一些简单的操作
- 使用redisTemplete简单封装的一个通用操作类
- 一个C#通过iTextSharp封装的PDF文件操作类代码
- 一个简单的数据操作类
- 第14讲 小结 封装一个mysql数据库操作类
- 自己封装的一个简单的倒计时功能实例
- 一个封装的不错的串口操作类
- C#封装的一个串口操作类(可用于Win CE)
- 对JMagick的一个简单封装
- 自己封装一个简单的自定义检索
- 简单封装一个组件:购买数量,带减少增加按钮AmountView
- 关于轻量级数据库SQLite一个简单的SQLiteHelper访问数据库封装类
- 一个简单的XML操作类
- 一个简单的基于 DirectShow 的播放器 1(封装类)
- 基于highcharts封装的一个简单易用的报表统计
- 一个简单封装好的item
- 一个简单封装好的item
- 一个简单的数据库操作类
- 一个简单的读写注册表实例