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

王朝other·作者佚名  2006-01-10
窄屏简体版  字體: |||超大  

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

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航