Ping.Po
学而不思则罔,思而不学则殆。
posts - 3,  comments - 1,  trackbacks - 0
 1 // 头文件
 2 // PpCRegistry.h: interface for the PpCRegistry class.
 3 //
 4 //////////////////////////////////////////////////////////////////////
 5 #if !defined(AFX_PPCREGISTRY_H__05F5A27D_850A_42C6_A919_22DB976E8978__INCLUDED_)
 6 #define AFX_PPCREGISTRY_H__05F5A27D_850A_42C6_A919_22DB976E8978__INCLUDED_
 7 
 8 #if _MSC_VER > 1000
 9 #pragma once
10 #endif // _MSC_VER > 1000
11 
12 class PpCRegistry  
13 {
14 public:
15     PpCRegistry(HKEY hKey=HKEY_LOCAL_MACHINE); // 默认构造函数
16     virtual ~PpCRegistry();
17 public:
18     BOOL ppCreateRegKey(LPCTSTR lpSubKey,PHKEY phkResult=NULL); //phkResult 参数现在没用到。创建RegKey
19     BOOL ppRegOpenKey(LPCTSTR lpSubKey,PHKEY phkResult=NULL); // phkResult 参数现在没用到。 打开RegKey
20     BOOL ppRegSetValue(LPCTSTR lpValueName,DWORD dwType,LPCTSTR lpValue); // 写入注册表
21     BOOL ppRegQueryValue(LPCTSTR lpValueName,LPCTSTR lpValue,LPDWORD lpcbData,LPDWORD lpType=NULL); // 从注册表中读取数据
22     BOOL ppRegDeleteValue(LPCTSTR lpValueName);  // 删除注册表的某个值
23     BOOL ppRegCloseKey(); // 关闭注册表 
24 private:
25     HKEY m_key; // hkey
26 }
 // PpCRegistry.cpp: implementation of the PpCRegistry class.
  2 //
  3 //////////////////////////////////////////////////////////////////////
  4 
  5 #include "stdafx.h"
  6 #include "RegDemo.h"
  7 #include "PpCRegistry.h"
  8 #include <assert.h>
  9 
 10 #ifdef _DEBUG
 11 #undef THIS_FILE
 12 static char THIS_FILE[]=__FILE__;
 13 #define new DEBUG_NEW
 14 #endif
 15 
 16 PpCRegistry::PpCRegistry(HKEY hKey)
 17 {
 18     //assert(hKey);
 19     m_key =hKey;
 20 }
 21 
 22 PpCRegistry::~PpCRegistry()
 23 {
 24     
 25 }
 26 
 27 BOOL PpCRegistry::ppCreateRegKey(LPCTSTR lpSubKey,PHKEY phkResult) //
 28 {
 29     assert(m_key);
 30     assert(lpSubKey);
 31     HKEY tempkey;
 32     long res=RegCreateKey(m_key,lpSubKey,&tempkey);
 33     if (res!=ERROR_SUCCESS)
 34     {
 35         RegCloseKey(m_key);
 36         return FALSE;
 37     }else
 38     {
 39     //    m_key =tempkey;
 40         return TRUE;
 41     }
 42 }
 43 BOOL PpCRegistry::ppRegOpenKey(LPCTSTR lpSubKey,PHKEY phkResult)
 44 {
 45     assert(m_key);
 46     assert(lpSubKey);
 47     
 48     HKEY tempkey;
 49     long res = RegOpenKey(m_key,lpSubKey,&tempkey);
 50     if (res!=ERROR_SUCCESS)
 51     {
 52         RegCloseKey(m_key);
 53         return FALSE;
 54     }else
 55     {
 56         m_key=tempkey;
 57         TRACE("%0xd\n",m_key);
 58         return TRUE;
 59     }
 60 }
 61 
 62 BOOL PpCRegistry::ppRegSetValue(LPCTSTR lpValueName,DWORD dwType,LPCTSTR lpValue) // 写入注册表 lpvaluename=NULL 则设置注册表默认值
 63 {
 64     
 65     assert(lpValue);
 66     // lpValueName ==NULL 修改默认值 的值
 67     long res=RegSetValueEx(m_key,lpValueName,0,dwType,(const unsigned char *)lpValue,strlen(lpValue)+1);
 68 
 69     if (res!=ERROR_SUCCESS)
 70     {
 71     //    RegCloseKey(m_key);
 72         return FALSE;
 73     }else
 74     {
 75         TRACE("%0xd\n",m_key);
 76         return TRUE;
 77     }
 78 }
 79 
 80 BOOL PpCRegistry::ppRegQueryValue(LPCTSTR lpValueName,LPCTSTR lpValue,LPDWORD lpcbData,LPDWORD lpType) // 从注册表中读取数据
 81 {
 82     assert(lpValueName);
 83     assert(lpValue);
 84 
 85     DWORD type;
 86 
 87     TRACE("%0xd\n",m_key);
 88 
 89     long res = RegQueryValueEx(m_key,lpValueName,0,&type,( unsigned char *)lpValue,lpcbData);
 90     if (res!=ERROR_SUCCESS)
 91     {
 92         return FALSE;
 93     }
 94     else
 95     {
 96         if (lpType!=NULL)
 97         {
 98             *lpType=type;
 99         }
100         TRACE("%0xd\n",m_key);
101         return TRUE;
102     }
103 }
104 
105 BOOL PpCRegistry::ppRegDeleteValue(LPCSTR lpValueName) // 删除注册表的某个值
106 {
107     assert(m_key);
108     assert(lpValueName);
109     long res=RegDeleteValue(m_key,lpValueName);
110     if (res!=ERROR_SUCCESS)
111     {
112     
113         return FALSE;
114     }
115     else
116     {
117         return TRUE;
118     }
119 }
120 
121 
122 BOOL PpCRegistry::ppRegCloseKey() // 关闭注册表 
123 {
124     if (m_key)
125     {
126         RegCloseKey(m_key);
127         m_key=NULL;
128     }
129     return TRUE
130 }
封装得很粗糙。只封装了一些对册表最基本的操作。希望在以后工作学习中一步一步的能把他完善。希望这里朋友多多指导。
posted on 2009-02-05 21:22 PingPo 阅读(539) 评论(0)  编辑 收藏 引用 所属分类: VC++

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理



<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿(1)

随笔分类

随笔档案

文章档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜