1.打開鍵
LPCTSTR StrKey(%%1);
HKEY m_hKey=%%2;
if (ERROR_SUCCESS==::RegOpenKeyEx(m_hKey,StrKey,NULL,KEY_ALL_ACCESS,&m_hKey))
{
%%3
}
2.添加鍵
LPCTSTR StrKey(%%1);
HKEY hKey;
DWORD dwDisposition;
if (ERROR_SUCCESS==::RegCreateKeyEx(m_hKey, (LPCTSTR)StrKey,0,NULL,
REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&hKey,&dwDisposition))
{
m_hKey=hKey;
if (dwDisposition==REG_CREATED_NEW_KEY)
{
%%2
}
else if (dwDisposition==REG_OPENED_EXISTING_KEY)
{
%%3
}
}
3.刪除鍵
LPCTSTR StrKey(%%1);
HKEY SrcKey=m_hKey;
char KeyName[256];
int nRes=0;
if (OpenKey(SrcKey,StrKey))
{
nRes=FirstEnumKey(KeyName);
while (nRes)
{
DeleteKey(KeyName);
nRes=NextEnumKey(KeyName);
}
}
if (::RegDeleteKey(SrcKey,StrKey)==ERROR_SUCCESS)
{
%%2
}
4.枚舉第一個鍵
BOOL CRegEdit::FirstEnumKey(char* Value)
{
DWORD dwSize=255;
m_EnumLoop=0;
if (ERROR_SUCCESS==::RegEnumKeyEx(m_hKey,m_EnumLoop,Value,&dwSize,NULL,NULL,NULL,NULL))
{
%%2
}
5.枚舉下一個鍵
BOOL CRegEdit::NextEnumKey(char* Value)
{
DWORD dwSize=255;
m_EnumLoop++;
if (ERROR_SUCCESS==::RegEnumKeyEx(m_hKey,m_EnumLoop,Value,&dwSize,NULL,NULL,NULL,NULL))
{
%%2
}
6.獲取DWORD值
LPCTSTR StrChildKey(%%1);
DWORD %%1;
DWORD dwSize=255,dwType=REG_DWORD;
if (ERROR_SUCCESS==::RegQueryValueEx(m_hKey,StrChildKey,0,&dwType,(BYTE *)(&%%2),&dwSize))
{
%%2
}
7.獲取二進制值
LPCTSTR StrChildKey(%%1);
DWORD %%1;
DWORD dwSize=255,dwType=REG_BINARY;
if (ERROR_SUCCESS==::RegQueryValueEx(m_hKey,StrChildKey,0,&dwType,(BYTE *)(&%%2),&dwSize))
{
%%2
}
8.讀取字符串值
LPCTSTR StrChildKey(%%1);
CString %%2;
DWORD dwSize=255,dwType=REG_SZ;
char String[256];
if (ERROR_SUCCESS==::RegQueryValueEx(m_hKey,StrChildKey,0,&dwType,(BYTE *)String,&dwSize))
%%2=CString(String);
9.寫入字符串值
LPCTSTR StrChildKey(%%1);LPCTSTR Value;CString %%2;
if (ERROR_SUCCESS==::RegSetValueEx( m_hKey,(LPCTSTR)StrChildKey,0,REG_SZ,(BYTE *)(LPCSTR)Value,strlen(Value)+1) )
%%2=CString(Value);
10.寫入二進制值
LPCTSTR StrChildKey(%%1);const char* %%2;
if (ERROR_SUCCESS==::RegSetValueEx( m_hKey,(LPCTSTR)StrChildKey,0,REG_BINARY,(BYTE *)%%2,strlen(Value)) )
{
%%3
}