封装了一个简单的注册表操作类

不想写文字了  测试了下 可以使用  想知道详细的用法加我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();
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值