TCHAR szNewKey[128];
LPCTSTR pszKeyPath;
int iIndex = 1;
- HKEY hRootKey;
- HKEY hKey = NULL;
- HKEY hNewKey = NULL;
+ LONG nResult;
+ HKEY hRootKey = NULL, hKey = NULL, hNewKey = NULL;
BOOL bSuccess = FALSE;
DWORD dwDisposition;
HTREEITEM hNewItem;
- pszKeyPath = GetItemPath(g_pChildWnd->hTreeWnd, hItem, &hRootKey);
- if (RegOpenKey(hRootKey, pszKeyPath, &hKey) != ERROR_SUCCESS)
+ pszKeyPath = GetItemPath(hwndTV, hItem, &hRootKey);
+ if (pszKeyPath[0] == TEXT('\0'))
+ hKey = hRootKey;
+ else if (RegOpenKey(hRootKey, pszKeyPath, &hKey) != ERROR_SUCCESS)
goto done;
if (LoadString(hInst, IDS_NEW_KEY, szNewKeyFormat, sizeof(szNewKeyFormat) / sizeof(szNewKeyFormat[0])) <= 0)
/* Need to create a new key with a unique name */
do
{
- _sntprintf(szNewKey, sizeof(szNewKey) / sizeof(szNewKey[0]), szNewKeyFormat, iIndex++);
- RegCreateKeyEx(hKey, szNewKey, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hNewKey, &dwDisposition);
- if (hNewKey && (dwDisposition == REG_OPENED_EXISTING_KEY))
+ wsprintf(szNewKey, szNewKeyFormat, iIndex++);
+ nResult = RegCreateKeyEx(hKey, szNewKey, 0, NULL, 0, KEY_WRITE, NULL, &hNewKey, &dwDisposition);
+ if (hNewKey && dwDisposition == REG_OPENED_EXISTING_KEY)
{
RegCloseKey(hNewKey);
hNewKey = NULL;
}
+ else if (!hNewKey)
+ {
+ TCHAR sz[256];
+ wsprintf(sz, TEXT("Cannot create new key!\n\nError Code: %d"), nResult);
+ MessageBox(hFrameWnd, sz, NULL, MB_ICONERROR);
+ goto done;
+ }
}
while(!hNewKey);
bSuccess = TRUE;
done:
- if (hKey)
+ if (hKey != hRootKey && hKey)
RegCloseKey(hKey);
if (hNewKey)
RegCloseKey(hNewKey);
TVITEM tvi;
/* Total no-good hack */
- if (!_tcsncmp(keyPath, _T("My Computer\\"), 12))
+ if (!_tcsnicmp(keyPath, _T("My Computer\\"), 12))
keyPath += 12;
hRoot = TreeView_GetRoot(hwndTV);
/* Special case for root to expand root key abbreviations */
if (hItem == hRoot)
{
- if (!_tcscmp(szPathPart, TEXT("HKCR")))
+ if (!_tcsicmp(szPathPart, TEXT("HKCR")))
_tcscpy(szPathPart, TEXT("HKEY_CLASSES_ROOT"));
- else if (!_tcscmp(szPathPart, TEXT("HKCU")))
+ else if (!_tcsicmp(szPathPart, TEXT("HKCU")))
_tcscpy(szPathPart, TEXT("HKEY_CURRENT_USER"));
- else if (!_tcscmp(szPathPart, TEXT("HKLM")))
+ else if (!_tcsicmp(szPathPart, TEXT("HKLM")))
_tcscpy(szPathPart, TEXT("HKEY_LOCAL_MACHINE"));
- else if (!_tcscmp(szPathPart, TEXT("HKU")))
+ else if (!_tcsicmp(szPathPart, TEXT("HKU")))
_tcscpy(szPathPart, TEXT("HKEY_USERS"));
- else if (!_tcscmp(szPathPart, TEXT("HKCC")))
+ else if (!_tcsicmp(szPathPart, TEXT("HKCC")))
_tcscpy(szPathPart, TEXT("HKEY_CURRENT_CONFIG"));
- else if (!_tcscmp(szPathPart, TEXT("HKDD")))
+ else if (!_tcsicmp(szPathPart, TEXT("HKDD")))
_tcscpy(szPathPart, TEXT("HKEY_DYN_DATA"));
}
(void)TreeView_GetItem(hwndTV, &tvi);
- if (!_tcscmp(szBuffer, szPathPart))
+ if (!_tcsicmp(szBuffer, szPathPart))
break;
}