// Прочитать из реестра значение заданного параметра
BOOL RegReadString(IN HKEY hKey, IN LPCTSTR szParameterName, OUT CString &strResult, IN BOOL bIgnoreCase = TRUE) {
BOOL bRes = FALSE;
int i=0;
while (TRUE) {
TCHAR szValueName[1024] = {0};
DWORD dwSizeValueName=1024,
dwType,
dwSizeData=1024;
BYTE pbData[1024] = {0};
long res = RegEnumValue(hKey, i++, szValueName, &dwSizeValueName, NULL, &dwType, pbData, &dwSizeData);
if (res != ERROR_SUCCESS)
break;
if ((dwType == REG_SZ) &&
(bIgnoreCase ?
(lstrcmpi(szParameterName, szValueName) == 0)
:
(lstrcmp (szParameterName, szValueName) == 0)
)
)
{
strResult = (LPCTSTR)pbData;
bRes = TRUE;
break;
}
}
return bRes;
}
// Прочитать из реестра значение заданного параметра
BOOL RegReadDword(IN HKEY hKey, IN LPCTSTR szParameterName, OUT DWORD &dwResult, IN BOOL bIgnoreCase = TRUE) {
BOOL bRes = FALSE;
int i=0;
while (TRUE) {
TCHAR szValueName[1024] = {0};
DWORD dwSizeValueName=1024,
dwType,
dwSizeData=1024;
BYTE pbData[1024] = {0};
long res = RegEnumValue(hKey, i++, szValueName, &dwSizeValueName, NULL, &dwType, pbData, &dwSizeData);
if (res != ERROR_SUCCESS)
break;
if ((dwType == REG_DWORD) &&
(bIgnoreCase ?
(lstrcmpi(szParameterName, szValueName) == 0)
:
(lstrcmp (szParameterName, szValueName) == 0)
)
)
{
dwResult = *((int*)pbData);
bRes = TRUE;
break;
}
}
return bRes;
}
/**
// Прочитать строку из реестра по заданному пути
// Пример вызова:
// CString strParam = GetDWordKey(TEXT("HKEY_CURRENT_USER\\SOFTWARE\\MyProgramm\\StringParam"));
/**/
CString GetStringKey(LPCTSTR szKeyName)
{
CString strResult;
CString strKeyName(szKeyName);
strKeyName.TrimLeft(TEXT('\\'));
HKEY hKey = NULL;
do {
int iPos = strKeyName.Find(TEXT('\\'));
if (iPos != -1) {
CString strKey = strKeyName.Left(iPos);
if (hKey == NULL) {
if (strKey.CompareNoCase(TEXT("HKEY_CLASSES_ROOT" )) == 0) hKey = HKEY_CLASSES_ROOT ; else
if (strKey.CompareNoCase(TEXT("HKEY_CURRENT_USER" )) == 0) hKey = HKEY_CURRENT_USER ; else
if (strKey.CompareNoCase(TEXT("HKEY_LOCAL_MACHINE" )) == 0) hKey = HKEY_LOCAL_MACHINE ; else
if (strKey.CompareNoCase(TEXT("HKEY_USERS" )) == 0) hKey = HKEY_USERS ; else
if (strKey.CompareNoCase(TEXT("HKEY_CURRENT_CONFIG")) == 0) hKey = HKEY_CURRENT_CONFIG; else {
break;
}
} else {
long lRes = RegOpenKeyEx(hKey, strKey, 0, KEY_READ, &hKey);
if (lRes != ERROR_SUCCESS) {
break;
}
}
strKeyName = strKeyName.Mid(iPos+1);
} else {
BOOL bRes = RegReadString(hKey, strKeyName, strResult);
break;
}
} while (TRUE);
return strResult;
}
/**
// Прочитать DWORD из реестра по заданному пути
// Пример вызова:
// long lParam = GetDWordKey(TEXT("HKEY_CURRENT_USER\\SOFTWARE\\MyProgramm\\DwordParam"));
/**/
long GetDWordKey(LPCTSTR szKeyName)
{
DWORD dwResult = 0;
CString strKeyName(szKeyName);
strKeyName.TrimLeft(TEXT('\\'));
HKEY hKey = NULL;
do {
int iPos = strKeyName.Find(TEXT('\\'));
if (iPos != -1) {
CString strKey = strKeyName.Left(iPos);
if (hKey == NULL) {
if (strKey.CompareNoCase(TEXT("HKEY_CLASSES_ROOT" )) == 0) hKey = HKEY_CLASSES_ROOT ; else
if (strKey.CompareNoCase(TEXT("HKEY_CURRENT_USER" )) == 0) hKey = HKEY_CURRENT_USER ; else
if (strKey.CompareNoCase(TEXT("HKEY_LOCAL_MACHINE" )) == 0) hKey = HKEY_LOCAL_MACHINE ; else
if (strKey.CompareNoCase(TEXT("HKEY_USERS" )) == 0) hKey = HKEY_USERS ; else
if (strKey.CompareNoCase(TEXT("HKEY_CURRENT_CONFIG")) == 0) hKey = HKEY_CURRENT_CONFIG; else {
break;
}
} else {
long lRes = RegOpenKeyEx(hKey, strKey, 0, KEY_READ, &hKey);
if (lRes != ERROR_SUCCESS) {
break;
}
}
strKeyName = strKeyName.Mid(iPos+1);
} else {
BOOL bRes = RegReadDword(hKey, strKeyName, dwResult);
break;
}
} while (TRUE);
return dwResult;
}
Как вытащить информацию из реестра?
Как вытащить информацию из реестра?
Цитата:
Originally posted by Kalitkin
Как вытащить информацию из реестра?
Как вытащить информацию из реестра?
Посмотри в MSDN RegQueryValue.
Цитата:
Originally posted by SeregaLBN
Код:
// Прочитать из реестра значение заданного параметра
BOOL RegReadString(IN HKEY hKey, IN LPCTSTR szParameterName, OUT CString &strResult, IN BOOL bIgnoreCase = TRUE) {
BOOL bRes = FALSE;
int i=0;
while (TRUE) {
TCHAR szValueName[1024] = {0};
DWORD dwSizeValueName=1024,
dwType,
dwSizeData=1024;
BYTE pbData[1024] = {0};
long res = RegEnumValue(hKey, i++, szValueName, &dwSizeValueName, NULL, &dwType, pbData, &dwSizeData);
if (res != ERROR_SUCCESS)
break;
if ((dwType == REG_SZ) &&
(bIgnoreCase ?
(lstrcmpi(szParameterName, szValueName) == 0)
:
(lstrcmp (szParameterName, szValueName) == 0)
)
)
{
strResult = (LPCTSTR)pbData;
bRes = TRUE;
break;
}
}
return bRes;
}
// Прочитать из реестра значение заданного параметра
BOOL RegReadDword(IN HKEY hKey, IN LPCTSTR szParameterName, OUT DWORD &dwResult, IN BOOL bIgnoreCase = TRUE) {
BOOL bRes = FALSE;
int i=0;
while (TRUE) {
TCHAR szValueName[1024] = {0};
DWORD dwSizeValueName=1024,
dwType,
dwSizeData=1024;
BYTE pbData[1024] = {0};
long res = RegEnumValue(hKey, i++, szValueName, &dwSizeValueName, NULL, &dwType, pbData, &dwSizeData);
if (res != ERROR_SUCCESS)
break;
if ((dwType == REG_DWORD) &&
(bIgnoreCase ?
(lstrcmpi(szParameterName, szValueName) == 0)
:
(lstrcmp (szParameterName, szValueName) == 0)
)
)
{
dwResult = *((int*)pbData);
bRes = TRUE;
break;
}
}
return bRes;
}
/**
// Прочитать строку из реестра по заданному пути
// Пример вызова:
// CString strParam = GetDWordKey(TEXT("HKEY_CURRENT_USER\\SOFTWARE\\MyProgramm\\StringParam"));
/**/
CString GetStringKey(LPCTSTR szKeyName)
{
CString strResult;
CString strKeyName(szKeyName);
strKeyName.TrimLeft(TEXT('\\'));
HKEY hKey = NULL;
do {
int iPos = strKeyName.Find(TEXT('\\'));
if (iPos != -1) {
CString strKey = strKeyName.Left(iPos);
if (hKey == NULL) {
if (strKey.CompareNoCase(TEXT("HKEY_CLASSES_ROOT" )) == 0) hKey = HKEY_CLASSES_ROOT ; else
if (strKey.CompareNoCase(TEXT("HKEY_CURRENT_USER" )) == 0) hKey = HKEY_CURRENT_USER ; else
if (strKey.CompareNoCase(TEXT("HKEY_LOCAL_MACHINE" )) == 0) hKey = HKEY_LOCAL_MACHINE ; else
if (strKey.CompareNoCase(TEXT("HKEY_USERS" )) == 0) hKey = HKEY_USERS ; else
if (strKey.CompareNoCase(TEXT("HKEY_CURRENT_CONFIG")) == 0) hKey = HKEY_CURRENT_CONFIG; else {
break;
}
} else {
long lRes = RegOpenKeyEx(hKey, strKey, 0, KEY_READ, &hKey);
if (lRes != ERROR_SUCCESS) {
break;
}
}
strKeyName = strKeyName.Mid(iPos+1);
} else {
BOOL bRes = RegReadString(hKey, strKeyName, strResult);
break;
}
} while (TRUE);
return strResult;
}
/**
// Прочитать DWORD из реестра по заданному пути
// Пример вызова:
// long lParam = GetDWordKey(TEXT("HKEY_CURRENT_USER\\SOFTWARE\\MyProgramm\\DwordParam"));
/**/
long GetDWordKey(LPCTSTR szKeyName)
{
DWORD dwResult = 0;
CString strKeyName(szKeyName);
strKeyName.TrimLeft(TEXT('\\'));
HKEY hKey = NULL;
do {
int iPos = strKeyName.Find(TEXT('\\'));
if (iPos != -1) {
CString strKey = strKeyName.Left(iPos);
if (hKey == NULL) {
if (strKey.CompareNoCase(TEXT("HKEY_CLASSES_ROOT" )) == 0) hKey = HKEY_CLASSES_ROOT ; else
if (strKey.CompareNoCase(TEXT("HKEY_CURRENT_USER" )) == 0) hKey = HKEY_CURRENT_USER ; else
if (strKey.CompareNoCase(TEXT("HKEY_LOCAL_MACHINE" )) == 0) hKey = HKEY_LOCAL_MACHINE ; else
if (strKey.CompareNoCase(TEXT("HKEY_USERS" )) == 0) hKey = HKEY_USERS ; else
if (strKey.CompareNoCase(TEXT("HKEY_CURRENT_CONFIG")) == 0) hKey = HKEY_CURRENT_CONFIG; else {
break;
}
} else {
long lRes = RegOpenKeyEx(hKey, strKey, 0, KEY_READ, &hKey);
if (lRes != ERROR_SUCCESS) {
break;
}
}
strKeyName = strKeyName.Mid(iPos+1);
} else {
BOOL bRes = RegReadDword(hKey, strKeyName, dwResult);
break;
}
} while (TRUE);
return dwResult;
}
BOOL RegReadString(IN HKEY hKey, IN LPCTSTR szParameterName, OUT CString &strResult, IN BOOL bIgnoreCase = TRUE) {
BOOL bRes = FALSE;
int i=0;
while (TRUE) {
TCHAR szValueName[1024] = {0};
DWORD dwSizeValueName=1024,
dwType,
dwSizeData=1024;
BYTE pbData[1024] = {0};
long res = RegEnumValue(hKey, i++, szValueName, &dwSizeValueName, NULL, &dwType, pbData, &dwSizeData);
if (res != ERROR_SUCCESS)
break;
if ((dwType == REG_SZ) &&
(bIgnoreCase ?
(lstrcmpi(szParameterName, szValueName) == 0)
:
(lstrcmp (szParameterName, szValueName) == 0)
)
)
{
strResult = (LPCTSTR)pbData;
bRes = TRUE;
break;
}
}
return bRes;
}
// Прочитать из реестра значение заданного параметра
BOOL RegReadDword(IN HKEY hKey, IN LPCTSTR szParameterName, OUT DWORD &dwResult, IN BOOL bIgnoreCase = TRUE) {
BOOL bRes = FALSE;
int i=0;
while (TRUE) {
TCHAR szValueName[1024] = {0};
DWORD dwSizeValueName=1024,
dwType,
dwSizeData=1024;
BYTE pbData[1024] = {0};
long res = RegEnumValue(hKey, i++, szValueName, &dwSizeValueName, NULL, &dwType, pbData, &dwSizeData);
if (res != ERROR_SUCCESS)
break;
if ((dwType == REG_DWORD) &&
(bIgnoreCase ?
(lstrcmpi(szParameterName, szValueName) == 0)
:
(lstrcmp (szParameterName, szValueName) == 0)
)
)
{
dwResult = *((int*)pbData);
bRes = TRUE;
break;
}
}
return bRes;
}
/**
// Прочитать строку из реестра по заданному пути
// Пример вызова:
// CString strParam = GetDWordKey(TEXT("HKEY_CURRENT_USER\\SOFTWARE\\MyProgramm\\StringParam"));
/**/
CString GetStringKey(LPCTSTR szKeyName)
{
CString strResult;
CString strKeyName(szKeyName);
strKeyName.TrimLeft(TEXT('\\'));
HKEY hKey = NULL;
do {
int iPos = strKeyName.Find(TEXT('\\'));
if (iPos != -1) {
CString strKey = strKeyName.Left(iPos);
if (hKey == NULL) {
if (strKey.CompareNoCase(TEXT("HKEY_CLASSES_ROOT" )) == 0) hKey = HKEY_CLASSES_ROOT ; else
if (strKey.CompareNoCase(TEXT("HKEY_CURRENT_USER" )) == 0) hKey = HKEY_CURRENT_USER ; else
if (strKey.CompareNoCase(TEXT("HKEY_LOCAL_MACHINE" )) == 0) hKey = HKEY_LOCAL_MACHINE ; else
if (strKey.CompareNoCase(TEXT("HKEY_USERS" )) == 0) hKey = HKEY_USERS ; else
if (strKey.CompareNoCase(TEXT("HKEY_CURRENT_CONFIG")) == 0) hKey = HKEY_CURRENT_CONFIG; else {
break;
}
} else {
long lRes = RegOpenKeyEx(hKey, strKey, 0, KEY_READ, &hKey);
if (lRes != ERROR_SUCCESS) {
break;
}
}
strKeyName = strKeyName.Mid(iPos+1);
} else {
BOOL bRes = RegReadString(hKey, strKeyName, strResult);
break;
}
} while (TRUE);
return strResult;
}
/**
// Прочитать DWORD из реестра по заданному пути
// Пример вызова:
// long lParam = GetDWordKey(TEXT("HKEY_CURRENT_USER\\SOFTWARE\\MyProgramm\\DwordParam"));
/**/
long GetDWordKey(LPCTSTR szKeyName)
{
DWORD dwResult = 0;
CString strKeyName(szKeyName);
strKeyName.TrimLeft(TEXT('\\'));
HKEY hKey = NULL;
do {
int iPos = strKeyName.Find(TEXT('\\'));
if (iPos != -1) {
CString strKey = strKeyName.Left(iPos);
if (hKey == NULL) {
if (strKey.CompareNoCase(TEXT("HKEY_CLASSES_ROOT" )) == 0) hKey = HKEY_CLASSES_ROOT ; else
if (strKey.CompareNoCase(TEXT("HKEY_CURRENT_USER" )) == 0) hKey = HKEY_CURRENT_USER ; else
if (strKey.CompareNoCase(TEXT("HKEY_LOCAL_MACHINE" )) == 0) hKey = HKEY_LOCAL_MACHINE ; else
if (strKey.CompareNoCase(TEXT("HKEY_USERS" )) == 0) hKey = HKEY_USERS ; else
if (strKey.CompareNoCase(TEXT("HKEY_CURRENT_CONFIG")) == 0) hKey = HKEY_CURRENT_CONFIG; else {
break;
}
} else {
long lRes = RegOpenKeyEx(hKey, strKey, 0, KEY_READ, &hKey);
if (lRes != ERROR_SUCCESS) {
break;
}
}
strKeyName = strKeyName.Mid(iPos+1);
} else {
BOOL bRes = RegReadDword(hKey, strKeyName, dwResult);
break;
}
} while (TRUE);
return dwResult;
}
Пасиба, и еще вопрос, как лучше хранить картинки в программе (их дохрена :))(в отдельном файле или dll или ...)?